Spring security 无法检测到SpringSecurity3.0 AuthenticationSuccessEvent
我想在用户登录系统后准备一些数据。在使用google之后,我实现了一个ApplicationListener来侦听AuthenticationSuccessEvent:Spring security 无法检测到SpringSecurity3.0 AuthenticationSuccessEvent,spring-security,Spring Security,我想在用户登录系统后准备一些数据。在使用google之后,我实现了一个ApplicationListener来侦听AuthenticationSuccessEvent: import org.springframework.context.ApplicationListener; import org.springframework.security.authentication.event.AuthenticationSuccessEvent; import org.springframewo
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
@Component
public class MyApplicationListener implements
ApplicationListener<AuthenticationSuccessEvent> {
@Override
public void onApplicationEvent(AuthenticationSuccessEvent event) {
UserDetails userDetails = (UserDetails) event.getAuthentication()
.getPrincipal();
System.out.println("Successed login:" + userDetails.getUsername());
}
}
import org.springframework.context.ApplicationListener;
导入org.springframework.security.authentication.event.AuthenticationSuccessEvent;
导入org.springframework.security.core.userdetails.userdetails;
导入org.springframework.stereotype.Component;
@组成部分
公共类MyApplicationListener实现
应用程序侦听器{
@凌驾
ApplicationEvent上的公共无效(AuthenticationSuccessEvent事件){
UserDetails UserDetails=(UserDetails)事件。getAuthentication()
.getPrincipal();
System.out.println(“成功登录:+userDetails.getUsername());
}
}
我更新了Spring3.0版本和SpringSecurity 3.0.0.RC2。但我永远不会被调用AuthenticationSuccessEvent:((我尝试了其他事件,例如AuthenticationFailureBadCredentialsEvent,成功了)
我使用自己的身份验证管理器,不对事件执行任何操作:
我需要自己播客吗
谢谢。我使用的是Spring Security 2.0.4,但我认为基本相同。 从我看到的情况来看,ProviderManager是在成功验证的情况下发布事件的 以下几个问题可能会有所帮助:
Shay我使用的是SpringSecurity2.0.4,但我认为基本相同。 从我看到的情况来看,ProviderManager是在成功验证的情况下发布事件的 以下几个问题可能会有所帮助:
Shay您没有指定配置的详细信息。您声明您使用自己的身份验证管理器-这是否意味着您正在使用Spring Bean配置显式地配置
ProviderManager
如果是这样,您需要在ProviderManager
上配置AuthenticationEventPublisher
,因为默认实现是空实现,它不发布事件
默认实现的bean声明如下所示:
<bean id="defaultAuthEventPublisher" class="org.springframework.security.authentication.DefaultAuthenticationEventPublisher"/>
然后需要将此bean映射到ProviderManager
上的相应属性:
如果您没有声明自己的
ProviderManager
,很遗憾,使用安全命名空间样式的配置无法启用此功能。希望这能回答您的问题!您没有指定配置的详细信息。您声明您使用自己的身份验证管理器-这是否意味着您是否使用Springbean配置显式配置ProviderManager
如果是这样,您需要在ProviderManager
上配置AuthenticationEventPublisher
,因为默认实现是空实现,它不发布事件
默认实现的bean声明如下所示:
<bean id="defaultAuthEventPublisher" class="org.springframework.security.authentication.DefaultAuthenticationEventPublisher"/>
然后需要将此bean映射到ProviderManager
上的相应属性:
如果您没有声明自己的
ProviderManager
,很遗憾,使用安全命名空间样式的配置无法启用此功能。希望这能回答您的问题!也许您想侦听InteractiveAuthenticationSuccessEvent。例如,OpenID仅发出该事件。另请参阅。 可能您想侦听InteractiveAuthenticationSuccessEvent。例如,OpenID仅发出该事件。另请参见。我也有同样的问题,我发现了一些可能有用的方法
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
org.springframework.security.web.session.HttpSessionEventPublisher
我也有同样的问题,我发现了一些可能有用的东西
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
org.springframework.security.web.session.HttpSessionEventPublisher