Spring Security怎樣不讓默認的ProviderManager清除密碼等信息

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

...spa

</authentication-manager>code

erase-credentials默認爲true,會在blog

 public Authentication authenticate(Authentication authentication) throws AuthenticationException get

返回前調用 ((CredentialsContainer)result).eraseCredentials(); 清除credentials等信息,因此咱們使用it

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

password老是爲null。io

將erase-credentials設置爲false後,不會清除這些保密信息,可是建議在使用完以後本身調用eraseCredentials()清楚這些信息。class

相關文章
相關標籤/搜索