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