你的位置:首页 > 软件开发 > Java > spring security 5 There is no PasswordEncoder mapped for the id null 错误

spring security 5 There is no PasswordEncoder mapped for the id null 错误

发布时间:2017-11-29 09:00:17
转载请注 security,但是在设置客户端密码时 一直出现了一下错误,原来没有问题的向下我做了什么 我把 spring security 升级到了5.0.0,应该是这里的问题,不过总不能让我降回去吧查找资料 发现了一下两篇资料,其实是一样的意思https://spring. ...

spring security 5 There is no PasswordEncoder mapped for the id null 错误

 转载请注 security,但是在设置客户端密码时 一直出现了一下错误,原来没有问题的

向下我做了什么 我把 spring security 升级到了5.0.0,应该是这里的问题,不过总不能让我降回去吧

spring security 5 There is no PasswordEncoder mapped for the id null 错误

查找资料 发现了一下两篇资料,其实是一样的意思

https://spring.io/blog/2017/11/01/spring-security-5-0-0-rc1-released#password-storage-updated

https://docs.spring.io/spring-security/site/docs/5.0.0.RELEASE/reference/htmlsingle/#ns-password-encoder

Password storage has undergone a major overhaul to provide more secure defaults and the ability to migrate how passwords are stored. The default PasswordEncoder is now DelegatingPasswordEncoder which is a non-passive change. This change ensures that passwords are now encoded using BCrypt by default, allows for validating passwords in old formats, and allows for upgrading the password storage in the future.

大概意思就是为了更加安全,所以就需要添加这个类型,

password -》 {noop}password

但是它{noop}没写也可以启动吖,那么如果我们不添加呢

看 org.springframework.security.crypto.password.DelegatingPasswordEncoder 这个类,在里面一个内部类UnmappedIdPasswordEncoder的matches函数抛出了一个异常 There is no PasswordEncoder mapped for the id \"" + id + "\""

这不就是我们抛出的异常吗

返回去看代码

在初始化成员变量时候  private PasswordEncoder defaultPasswordEncoderForMatches = new UnmappedIdPasswordEncoder(); 

将UnmappedIdPasswordEncoder()设置为默认,在matches函数中 

String id = extractId(prefixEncodedPassword);PasswordEncoder delegate = this.idToPasswordEncoder.get(id);

如果设置的密码没有带{}这样的标记,或者标记里的encode id 没有在声明的id 集合内(id集合是什么?构造函数idToPasswordEncoder打个断点就好了,其实在PasswordEncoderFactories类中

 那么它就抛出异常。

以上。

 转载请注 security 5.0.0.RELEASE


 

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:spring security 5 There is no PasswordEncoder mapped for the id null 错误

关键词:Spring

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录