【问题标题】:Spring security ApplicationListener doesn't get called for AuthenticationSuccessEvent没有为 AuthenticationSuccessEvent 调用 Spring 安全 ApplicationListener
【发布时间】:2018-09-23 15:52:55
【问题描述】:

在我的安全应用程序中,不会为 AuthenticationSuccessEvent 调用 Spring security ApplicationListener

@Component
public class LoginListener implements ApplicationListener<InteractiveAuthenticationSuccessEvent> {

    @Override
    public void onApplicationEvent(InteractiveAuthenticationSuccessEvent event)
    {
        log.info("Login success");
    }
}

我该怎么办?

【问题讨论】:

  • 您是否在 XML 配置或代码中将此类配置为 authentication-success-handler
  • 没有。据我所知,这门课只是一个听众。 authentication-success-handlerr 类是另一回事。是否应该是 authentication-success-handler 才能按预期工作?
  • 您仍然需要将其注册为 bean。所以这应该添加explicitly 或者应该在component-scan 路径中。这是在component-scan 路径中吗?
  • 是的,在component-scan

标签: java spring-security spring-security-oauth2


【解决方案1】:

我正在使用基于 xml 的 mvc 配置,我正在初始化我的 security,如下所示:

public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer {
    public SecurityWebApplicationInitializer() {
        super(SecurityConfig.class);
    }
}

我通过以下方式解决了上述问题: 移除基于 java 的初始化,并通过在web.xml 中添加过滤器springSecurityFilterChain 对其进行初始化。

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

此外,每当我尝试 @Autowire 我的 SecurityConfig 类中的任何 bean 时,我都会遇到 bean 接线异常。这个问题也解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-05
    • 2021-01-10
    • 2011-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-18
    • 2014-06-14
    相关资源
    最近更新 更多