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

转载于:https://www.cnblogs.com/wbb2109/p/4077076.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值