我已经开发了一个带有Security的注册和登录模块。我现在关心的是如何拦截自动存储的登录以将信息保存在数据库中。我的意思是,当用户标记“记住我”时,如果进入我的应用程序,自动进入登录主页,但我想在数据库中注册访问权限。
现在,当用户显式地浏览登录页面时,很容易做到这一点,但在上述情况下则不然。
致以敬意,
更新:我放了一些额外的信息:
发布于 2013-01-16 09:03:02
你可以做这样的事
@Component
public class AppListener implements ApplicationListener {
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof InteractiveAuthenticationSuccessEvent) {
handleLoginEvent();
} else if (event instanceof HttpSessionDestroyedEvent)
handleLogoutEvent((HttpSessionDestroyedEvent) event);
}
private void handleLoginEvent() {
// handle login event
}
private synchronized void handleLogoutEvent(HttpSessionDestroyedEvent event) {
// handle logout event
}
}致以敬意,
EDIT
将此添加到web.xml中
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>发布于 2013-01-16 09:05:42
您在这里有多个选项:
AuthenticationSuccessHandler将同样适用于两种情况下的,(正常登录并记住我):
public class CustomAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws ServletException, IOException {
// log authentication success here for both cases
super.onAuthenticationSuccess(request, response, authentication);
}
}在你的security.xml里
<bean id="customAuthenticationSuccessHandler" class="com.domain.security.CustomAuthenticationSuccessHandler"/>
<security:http ... >
...
<security:form-login login-page='/login.html' authentication-success-handler-ref="customAuthenticationSuccessHandler" />
<security:remember-me authentication-success-handler-ref="customAuthenticationSuccessHandler" />
</security:http>https://stackoverflow.com/questions/14354034
复制相似问题