小编Ser*_*hez的帖子

未触发AuthenticationSuccessEvent或InteractiveAuthenticationSuccessEvent的@EventListener

我在Spring的上下文中有这个监听器:

package listeners;

import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.security.authentication.event.AbstractAuthenticationEvent;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.security.authentication.event.InteractiveAuthenticationSuccessEvent;
import org.springframework.stereotype.Component;
import services.UserService;
import services.security.CustomUserDetails;

/**
 *
 * @author sergio
 */
@Component
public class AuthenticationSuccessEventHandler{

    private static Logger logger = LoggerFactory.getLogger(AuthenticationSuccessEventHandler.class);

    @Autowired
    private UserService userService;

    @EventListener({AuthenticationSuccessEvent.class, InteractiveAuthenticationSuccessEvent.class})
    public void processAuthenticationSuccessEvent(AbstractAuthenticationEvent  e) {
        logger.info("Autenticación realizada ....");
        // Actualizamos la útltima fecha de acceso
        String username = ((CustomUserDetails) e.getAuthentication().getPrincipal()).getUsername();
        logger.info("Actualizando último acceso para user: " + username);
        userService.updateLastLoginAccess(username, new Date());
    }   
} …
Run Code Online (Sandbox Code Playgroud)

spring spring-mvc spring-security

9
推荐指数
1
解决办法
3820
查看次数

获取Spring SpEL表达式的java注释属性值

我需要在多个控制器上实现授权表达式.为此,我决定创建一个便于其使用的个性化注释.问题是授权表达式需要一个参数(一个id),可以在每个控制器中以不同的方式获得.然后

我把注释:

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@PreAuthorize("@authorizationService.hasAdminRole() || ( @authorizationService.hasParentRole() && @authorizationService.isYourSon(#son) )")
public @interface OnlyAccessForAdminOrParentOfTheSon {
    String son() default "";
}
Run Code Online (Sandbox Code Playgroud)

问题是我不知道如何获取要在SPEL授权表达式中使用的注释的"son"属性的值.

我使用的符号如下:

@OnlyAccessForAdminOrParentOfTheSon(son = "#id")
@OnlyAccessForAdminOrParentOfTheSon(son = "#socialMedia.son")
Run Code Online (Sandbox Code Playgroud)

有人知道如何解决这个问题.提前致谢.

spring annotations spring-mvc spring-security spring-el

8
推荐指数
1
解决办法
719
查看次数

Jackson 自定义解串器未调用

我在改造中有以下端点:

@GET("user/detail")
Observable<JacksonResponse<User>> getUserDetail();
Run Code Online (Sandbox Code Playgroud)

该端点返回以下结果:

{
  "code":1012,
  "status":"sucess",
  "message":"Datos Del Usuario",
  "time":"28-10-2015 10:42:04",
  "data":{
    "id_hash":977417640,
    "user_name":"Daniel",
    "user_surname":"Hdz Iglesias",
    "birthdate":"1990-02-07",
    "height":190,
    "weight":80,
    "sex":2,
    "photo_path":" https:\/\/graph.facebook.com
    \/422\/picture?width=100&height=100"
  }
}
Run Code Online (Sandbox Code Playgroud)

这是该类的定义:

public class JacksonResponse<T> {

    private Integer code;
    private String status;
    private String message;
    private String time;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private T data;

    public JacksonResponse(){}

    @JsonCreator
    public JacksonResponse(
            @JsonProperty("code") Integer code,
            @JsonProperty("status") String status,
            @JsonProperty("message") String message,
            @JsonProperty("time") String time,
            @JsonProperty("data") T data) {
        this.code = code;
        this.status = status;
        this.message = message;
        this.time = …
Run Code Online (Sandbox Code Playgroud)

java json jackson deserialization retrofit2

6
推荐指数
1
解决办法
9562
查看次数

如何将Params传递给Thymeleaf Ajax Fragment

我有一个Spring MVC控制器,它返回一个百万美元片段的名称来查看解析器bean.问题是这个片段需要一个url作为参数.在这里我把片段:

     <!-- A fragment with wrapper form for basic personal information fragment -->
 <th:block th:fragment="form-basic(url)">
    <form role="form" th:action="${url}" method="post" th:object="${user}">
         <th:block th:replace="admin/fragments/alerts::form-errors"></th:block>
         <th:block th:include="this::basic" th:remove="tag"/>
         <div class="margiv-top-10">
              <input type="submit"  class="btn green-haze" value="Save" th:value="#{admin.user.form.save}" />
              <input type="reset"  class="btn default" value="Reset" th:value="#{admin.user.form.reset}" />
        </div>
  </form>
</th:block>
Run Code Online (Sandbox Code Playgroud)

我无法获得传递该参数的方法而不会出现错误.控制器如下:

@RequestMapping(method = RequestMethod.GET)
public String show(@CurrentUser User user, Model model) {
   logger.info(user.toString());
   if(!model.containsAttribute(BINDING_RESULT_NAME)) {
       model.addAttribute(ATTRIBUTE_NAME, user);
   }
   model.addAttribute("url", "/admin/users/self/profile");
   return "admin/fragments/user/personal::form-basic({url})";
}
Run Code Online (Sandbox Code Playgroud)

对于上面的示例,我收到以下错误:

06-Jan-2017 11:36:40.264 GRAVE [http-nio-8080-exec-9] org.apache.catalina.core.StandardWrapperValve.invoke El Servlet.service() para el servlet [dispatcher] …
Run Code Online (Sandbox Code Playgroud)

ajax spring spring-mvc thymeleaf

3
推荐指数
1
解决办法
2681
查看次数