转载请注明http://www.cnblogs.com/majianming/p/7923604.html
最近在学习spring security,但是在设置客户端密码时 一直出现了一下错误,原来没有问题的
向下我做了什么 我把spring security 升级到了5.0.0,应该是这里的问题,不过总不能让我降回去吧

查找资料 发现了一下两篇资料,其实是一样的意思
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 defaultPasswordEncoderis nowDelegatingPasswordEncoderwhich 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 mappedforthe 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类中
)
那么它就抛出异常。
以上。
转载请注明http://www.cnblogs.com/majianming/p/7923604.html
使用版本:<br />spring security 5.0.0.RELEASE