Spring security 如何在Spring Security中访问已注销的用户名?
我们使用SpringSecurity4.0.x,我需要找到访问已注销用户名的方法。 我已配置Spring security 如何在Spring Security中访问已注销的用户名?,spring-security,spring-security4,Spring Security,Spring Security4,我们使用SpringSecurity4.0.x,我需要找到访问已注销用户名的方法。 我已配置LogoutSuccessHandler: 我在方法签名中看到身份验证对象: onLogoutSuccess(HttpServletRequest请求、HttpServletResponse响应、身份验证) 不幸的是,身份验证对象是空的。 我看到LogoutHandler(SecurityContextLogoutHandler)在logoutSuccessHandler之前清除了身份验证,但我找不
LogoutSuccessHandler
:
我在方法签名中看到身份验证对象:
onLogoutSuccess(HttpServletRequest请求、HttpServletResponse响应、身份验证)
不幸的是,身份验证
对象是空的。
我看到LogoutHandler
(SecurityContextLogoutHandler
)在logoutSuccessHandler
之前清除了身份验证,但我找不到如何通过
如您所见,筛选器已获得身份验证
,因此即使SecurityContextLogoutHandler
也会清除SecurityContextHolder
中的身份验证
,而身份验证
仍保留身份验证
,在LogoutFilter
之前,您是否有任何其他代码清除了Authentication
?我已经调试了LogoutFilter
,但我看到身份验证已为null
。调用SecurityContextHolder#clearContext
的唯一代码是SecurityContextPersistenceFilter
和FilterChainProxy
。怎么了?您是否找到任何关于SecurityContextHolder.getContext().setAuthentication(null或null对象)
的代码?我找到了在spring security之前清除会话的代码。谢谢你的帮助!
if (requiresLogout(request, response)) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (logger.isDebugEnabled()) {
logger.debug("Logging out user '" + auth
+ "' and transferring to logout destination");
}
this.handler.logout(request, response, auth);
logoutSuccessHandler.onLogoutSuccess(request, response, auth);
return;
}