Spring Boot身份验证和授权事件未触发

时间:2020-06-10 14:17:48

标签: spring spring-boot

我的应用程序中有身份验证审核支持,我遵循以下文章来实现它。 https://www.baeldung.com/spring-boot-authentication-audit

上次使用时,我具有以下版本

        <spring.version>5.1.9.RELEASE</spring.version>
        <spring.boot.version>2.1.7.RELEASE</spring.boot.version>

然后在某些时候,我们将升级弹簧和弹簧靴

        <spring.version>5.2.0.RELEASE</spring.version>
        <spring.boot.version>2.2.0.RELEASE</spring.boot.version>

现在用户登录应用程序时,auditEventHappened方法不再中断

@Component
public class LoginAttemptsLogger {

    @EventListener
    public void auditEventHappened(
      AuditApplicationEvent auditApplicationEvent) {

        AuditEvent auditEvent = auditApplicationEvent.getAuditEvent();
        System.out.println("Principal " + auditEvent.getPrincipal() 
          + " - " + auditEvent.getType());

        WebAuthenticationDetails details = 
          (WebAuthenticationDetails) auditEvent.getData().get("details");
        System.out.println("Remote IP address: "
          + details.getRemoteAddress());
        System.out.println("  Session Id: " + details.getSessionId());
    }
}

希望有人也有同样的问题并且能够解决..降级库,这不是解决问题的方法..

1 个答案:

答案 0 :(得分:1)

如果您像我一样被困住,我就能使它起作用:

这是我期望的棘手部分,生成将返回新的AuditEventRepository(),但是没有AuditEventRepository是接口,您需要实现自定义行为。因此,如果您对默认实现感到满意,请使用InMemoryAuditEventRepository

@Bean
public InMemoryAuditEventRepository auditEventRepository() throws Exception {
  return new InMemoryAuditEventRepository();
}

您将需要在application.property文件中打开审核

management.auditevents.enabled = true