Spring Security怎样不让默认的ProviderManager清除密码等信息

<authentication-manager erase-credentials="false">

...

</authentication-manager>

erase-credentials默认为true,会在

 public Authentication authenticate(Authentication authentication) throws AuthenticationException 

返回前调用 ((CredentialsContainer)result).eraseCredentials(); 清除credentials等信息,所以我们使用

SecurityContextImpl securityContextImpl = (SecurityContextImpl) request
.getSession().getAttribute("SPRING_SECURITY_CONTEXT");
Authentication authentication = securityContextImpl.getAuthentication();
// 登录密码,未加密的
String password = (String)(authentication.getCredentials());

password总是为null。

将erase-credentials设置为false后,不会清除这些保密信息,但是建议在使用完之后自己调用eraseCredentials()清楚这些信息。

posted @ 2014-11-05 18:35  hellomsg  阅读(2660)  评论(0编辑  收藏  举报