erase-credentials配置


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

 

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

 

erase-credentials默認為true,會在ProviderManager(默認的AuthenticationManager實現)的方法

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()清楚這些信息。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM