转载请注明出处 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 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.

我简单理解了一下,意思就是为了更加安全,所以就需要添加这个类型(id)

如果没有加密的时候(也即是明文保存),需要改为这样,假设明文密码是password

password -> {noop}password // noop是no operate的意思,也就是说明保存的密码没有做加密操作

总的来说就是在spring security 4的密码格式上添加了密码类型的标记,并将这个标记使用花括号包裹放在密码密文的前面,形成spring security 5 的密码格式

加密类型支持(为了方便书写,这里假设各类加密方式加密后的密码密文是password)

加密方式 原来security 4的密码格式 现在security 5的密码格式
bcrypt password {bcrypt}password
ldap password {ldap}password
MD4 password {MD4}password
MD5 password {MD5}password
noop password {noop}password
pbkdf2 password {pbkdf2}password
scrypt password {scrypt}password
SHA-1 password {SHA-1}password
SHA-256 password {SHA-256}password
sha256 password {sha256}password

接下来介绍一下分析。如果我们不添加这个类型会怎么样,我们查看 org.springframework.security.crypto.password.DelegatingPasswordEncoder 这个类,在里面一个内部类UnmappedIdPasswordEncoder的matches方法抛出了一个异常信息There is no PasswordEncoder mapped for the id \"" + id + "\"",这不就是我们抛出的异常吗?

继续看看代码,在DelegatingPasswordEncoder初始化成员变量时候 ,有这样的定义

private PasswordEncoder defaultPasswordEncoderForMatches = new UnmappedIdPasswordEncoder();

也就是说这里将UnmappedIdPasswordEncoder()设置为了默认,在matches函数中

String id = extractId(prefixEncodedPassword);
PasswordEncoder delegate = this.idToPasswordEncoder.get(id);
if(delegate == null) {
return this.defaultPasswordEncoderForMatches
.matches(rawPassword, prefixEncodedPassword);
}

这里,调用了默认的matches函数,也就是UnmappedIdPasswordEncoder的matches,如果设置在数据库密码没有带{}这样的标记,或者标记里的encode id 没有在声明的id 集合内(id集合是什么?也就是上面表格中所支持的加密格式,在运行时候DelegatingPasswordEncoder的构造函数打个断点就知道了,其实就是idToPasswordEncoder这个变量的值,这个值定义PasswordEncoderFactories类中),那么它就抛出异常。

String prefixEncodedPassword) {
String id = extractId(prefixEncodedPassword);
throw new IllegalArgumentException("There is no PasswordEncoder mapped for the id \"" + id + "\"");

转载请注明出处 http://www.cnblogs.com/majianming/p/7923604.html


使用版本:
spring security 5.0.0.RELEASE

spring security 5 There is no PasswordEncoder mapped for the id "null" 错误的更多相关文章

  1. Spring Security 报There is no PasswordEncoder mapped for the id "null"

    查了下发现是spring security 版本在5.0后就要加个PasswordEncoder了 解决办法 在securityConfig类下加入NoOpPasswordEncoder,不过官方已经 ...

  2. java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"

    问题描述 今天在使用SpringBoot整合spring security,使用内存用户验证,但无响应报错:java.lang.IllegalArgumentException: There is n ...

  3. Spring Security 无法登陆,报错:There is no PasswordEncoder mapped for the id “null”

    编写好继承了WebSecurityConfigurerAdapter类的WebSecurityConfig类后,我们需要在configure(AuthenticationManagerBuilder ...

  4. java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"报错

    出现问题的原因: 内存用户验证时,Spring boot 2.0.1引用的security 依赖是 spring security 5.X版本,此版本需要提供一个PasswordEncorder的实例 ...

  5. 005-SpringBoot2.x整合Security5(解决 There is no PasswordEncoder mapped for the id "null")

    问题描述 SpringBoot升级到了2.0之后的版本,Security也由原来的版本4升级到了5 使用WebSecurityConfigurerAdapter继承重置方法 protected voi ...

  6. There is no PasswordEncoder mapped for the id "null"的解决办法

    今日在SpringBoot项目中使用 Spring Security ,登录时发现报500错,报错信息如下: There is no PasswordEncoder mapped for the id ...

  7. There is no PasswordEncoder mapped for the id "null"

    There is no PasswordEncoder mapped for the id "null" 学习了:https://blog.csdn.net/dream_an/ar ...

  8. SpringBoot + Spring Security 学习笔记(一)自定义基本使用及个性化登录配置

    官方文档参考,5.1.2 中文参考文档,4.1 中文参考文档,4.1 官方文档中文翻译与源码解读 SpringSecurity 核心功能: 认证(你是谁) 授权(你能干什么) 攻击防护(防止伪造身份) ...

  9. springboot+maven整合spring security

    springboot+maven整合spring security已经做了两次了,然而还是不太熟悉,这里针对后台简单记录一下需要做哪些事情,具体的步骤怎么操作网上都有,不再赘述.1.pom.xml中添 ...

随机推荐

  1. linux应用之vi编辑器的安装、配置及用法

    vi(vim是其高级版本)是linux系统上用于文本编辑的一个应用.它的功能十分强大,在日常的系统管理活动或编程中用得都很多.所以用好vi是很有必要的. 学习vi主要学的知识点有:1.vi的配置.2. ...

  2. 从Inception v1,v2,v3,v4,RexNeXt到Xception再到MobileNets,ShuffleNet,MobileNetV2

    from:https://blog.csdn.net/qq_14845119/article/details/73648100 Inception v1的网络,主要提出了Inceptionmodule ...

  3. css绘制三角形

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. 给YUI Compressor添加右键命令,完成快捷压缩

    YUI Compressor默认不带右键安装功能 YUI Compressor非常好用,特别是JS的混淆是众多JS Coding的最爱.可惜官网提供的版本都不具备右键功能,每次压缩都要cmd输入一些命 ...

  5. PHP 单引号与双引号的区别 SQL中的使用

    php单引号与双引号用法:引号嵌套方法 1.双引号内不能直接就再嵌套双引号 2.双引号与单引号互相嵌套使用 如: 双引号内直接嵌套单引号 echo "<script language= ...

  6. 电商:html样式集合

    1. <span class="big"  style="text-decoration:line-through;">原价:¥{zlcms:art ...

  7. flex 在父窗口监听弹出窗口里的某个按钮被点击

    flex 在父窗口监听弹出窗口里的某个按钮被点击 这样可以从子窗口拿回数据在父窗口处理数据,不必再子窗口中处理.在某些情形下省去了不少麻烦. /** * 右键菜单项单击事件 * changed by ...

  8. JAVA基础--JAVA 集合框架(泛型、file类)16

    一.集合总结 集合:Collection体系.Map体系. Collection体系:单列集合的共性操作规则. List:列表,可以重复,有下标,拥有特有的迭代器ListIterator. Array ...

  9. C++ STL map使用

    Map是c++的一个标准容器,它提供了很好一对一的关系,在一些程序中建立一个map可以起到事半功倍的效果,总结了一些map基本简单实用的操作!1. map构造函数:map<string , in ...

  10. lightoj 1076 【二分找满足条件的最左】

    #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned long long ...