如何使用Spring特性记录SavedRequestAwareAuthenticationSuccessHandler.onAuthenticationSuccess?

如何使用Spring特性记录SavedRequestAwareAuthenticationSuccessHandler.onAuthenticationSuccess?,spring,spring-security,spring-aop,Spring,Spring Security,Spring Aop,当用户使用Spring Security成功登录时,我尝试登录。我使用日志方面: @Aspect @Component public class LoggingAspect { static Logger log = Logger.getLogger(LoggingAspect.class); @Before("execution(* com.jle.athleges.web.controller.MemberController.*(..))") public void logBefore(

当用户使用Spring Security成功登录时,我尝试登录。我使用日志方面:

@Aspect
@Component
public class LoggingAspect {
static Logger log = Logger.getLogger(LoggingAspect.class);

@Before("execution(* com.jle.athleges.web.controller.MemberController.*(..))")
public void logBefore(JoinPoint joinPoint) {
    log.info("INFO - logBefore() is running!");
    log.info(joinPoint.getSignature().getName());
}

@AfterReturning(pointcut = "execution(* org.springframework.security.authentication.AuthenticationManager.authenticate(..))", returning = "result")
public void after(JoinPoint joinPoint, Object result) throws Throwable {
    log.info(">>> user: " + ((Authentication) result).getName());
}

@Around("execution(* org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler.onAuthenticationSuccess(..))")
public void onAuthenticationSuccess(){
    log.info(">>> user " + (SecurityContextHolder.getContext().getAuthentication().getName()) + " is now connected");
}
}
之后的方法运行正常,但记录了两次。我尝试使用onAuthenticationSuccess,但控制台中没有写入任何内容

我使用中解释的示例,但它不起作用

有什么想法吗

谢谢

我找到了解决方案

我创建了一个新的SuccessHandler bean:

public class SecurityAuthenticationSuccessHandler extends
    SimpleUrlAuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
    Authentication authentication) throws IOException, ServletException {

    super.onAuthenticationSuccess(request, response, authentication);
}
}

第二点是将其作为bean添加到配置中,并在formLogin中进行设置:

    @Bean
public SecurityAuthenticationSuccessHandler getSuccessHandler(){
    return new SecurityAuthenticationSuccessHandler();
}

http.authorizeRequests().antMatchers("/*").permitAll().and()
            .formLogin()
            .successHandler(successHandler)
            .permitAll().and().logout().permitAll();