There is no PasswordEncoder mapped for the id "null"的解决办法
今日在SpringBoot项目中使用 Spring Security ,登录时发现报500错,报错信息如下:
There is no PasswordEncoder mapped for the id "null"
我接着查找了前端页面上,发现密码框的name属性确实指定的是 password ,并没有出错。这是怎么回事呢?
于是就上网百度,发现这是由于Spring security5中新增加了加密方式,并把原有的spring security的密码存储格式改了。
去官网查找得知,修改后的密码存储格式为:
{id}encodedPassword
于是大概就明白了程序出错的原因: 前端传过来密码后,程序会查找被 花括号"{}"包括起来的id ,以此来确定后面的密码怎么进行加密,而我们在前面并没有按该格式进行处理,这就导致找不到id,就报错了。
明白了报错的原因,就好解决了, 我们只需要对前端传过来的密码进行某种方式加密,就可以了,而官方推荐的是使用bcrypt的加密方式。解决办法如下:
在Securty配置类SecurtyConfig(继承 WebSecurityConfigurerAdapter)中修改 配置即可。
-
@EnableWebSecurity
-
public class SecurtyConfig extends WebSecurityConfigurerAdapter {
-
/**
-
* 自定义配置
-
*
-
* @param http
-
* @throws Exception
-
*/
-
@Override
-
protected void configure(HttpSecurity http) throws Exception {
-
http.authorizeRequests()
-
.antMatchers("/css/**", "/js/**", "/fonts/**", "/index").permitAll() //都可以访问
-
.antMatchers("/users/**").hasRole("ADMIN") //需要相应的角色才能访问
-
.and()
-
.formLogin() //基于Form表单登录验证
-
.loginPage("/login").failureUrl("/login-error"); //自定义登录界面
-
}
-
-
/**
-
* 认证信息管理
-
* spring5中摒弃了原有的密码存储格式,官方把spring security的密码存储格式改了
-
*
-
* @param auth
-
* @throws Exception
-
*/
-
@Autowired
-
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
-
auth.inMemoryAuthentication() //认证信息存储到内存中
-
.passwordEncoder(passwordEncoder())
-
.withUser("user").password(passwordEncoder().encode("123456")).roles("ADMIN");
-
}
-
-
private PasswordEncoder passwordEncoder() {
-
return new BCryptPasswordEncoder();
-
}
-
}
主要是需要对 密码进行加密操作,定义的 passwordEncoder() 方法返回一个 BCryptPasswordEncoder对象,对上面的密码进行加密。这样就解决了该问题。
另外 还有一个也可以解决.
-
@Bean
-
public static PasswordEncoder passwordEncoder(){
-
return NoOpPasswordEncoder.getInstance();
-
}
该方法已经过时,不建议使用。
原文地址:https://blog.csdn.net/m0_37564404/article/details/83378630
There is no PasswordEncoder mapped for the id "null"的解决办法的更多相关文章
- java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"报错
出现问题的原因: 内存用户验证时,Spring boot 2.0.1引用的security 依赖是 spring security 5.X版本,此版本需要提供一个PasswordEncorder的实例 ...
- Spring Security 无法登陆,报错:There is no PasswordEncoder mapped for the id “null”
编写好继承了WebSecurityConfigurerAdapter类的WebSecurityConfig类后,我们需要在configure(AuthenticationManagerBuilder ...
- 005-SpringBoot2.x整合Security5(解决 There is no PasswordEncoder mapped for the id "null")
问题描述 SpringBoot升级到了2.0之后的版本,Security也由原来的版本4升级到了5 使用WebSecurityConfigurerAdapter继承重置方法 protected voi ...
- 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 ...
- java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"
问题描述 今天在使用SpringBoot整合spring security,使用内存用户验证,但无响应报错:java.lang.IllegalArgumentException: There is n ...
- spring security 5 There is no PasswordEncoder mapped for the id "null" 错误
转载请注明出处 http://www.cnblogs.com/majianming/p/7923604.html 最近在学习spring security,但是在设置客户端密码时,一直出现了一下错误提 ...
- Spring Security 报There is no PasswordEncoder mapped for the id "null"
查了下发现是spring security 版本在5.0后就要加个PasswordEncoder了 解决办法 在securityConfig类下加入NoOpPasswordEncoder,不过官方已经 ...
- 单页面网站关于id冲突的解决办法
最近做了一个单页面的网站,所有的页面加载都是通过局部刷新的方式,并且不用iframe,并且我们引入了动态tab页签: 所有的页签里的内容都只是一个元素,都在同一个html页面上,没有任何iframe分 ...
- Linux安装rpm包时报错Header V3 DSA/SHA1 Signature, key ID 1d1e034b: NOKEY解决办法
这是因为yum安装了旧版本的GPG key造成的,解决办法: rpm --import /etc/pki/rpm-gpg/RPM* Header V3 DSA/SHA1 Signature, key ...
随机推荐
- PLAY2.6-SCALA(十一) 模板常用场景
1.布局 声明一个views/main.scala.html模板作为主布局模板 @(title: String)(content: Html) <!DOCTYPE html> <ht ...
- DTcms设置 IIS6.0设置url重写导致editor上传全部失效
1.修改iis的重写规则为htm 2.修改后台后缀为htm 解决
- java中URLEncode和URLDecode
URLEncode和URLDecode用于完成普通字符串和 application/x-www-from-urlencoded MIME字符串之间的相互转化 如果传递的字符串中包含非西欧字符的字符串, ...
- KiCad EDA 镜像目录说明
KiCad EDA 镜像目录说明 stable/ -- 稳定版安装包. testing/ -- 测试安装包. nightly/ -- 每日编译安装包. 5.1 版本的每日编译包,这个文件夹是重点,如果 ...
- Linus 本尊也来了!为什么 KubeCon 越来越火了?
2015年11月,第一届 KubeCon 在美国旧金山开始的时候,还只是个200人的小会议,2019年的7月,KubeCon 第二次在中国举办,就有 3500 多位云原生和开源领域工程师齐聚一堂. 连 ...
- MUI - 实现关闭除指定页面外的其他所有页面的功能
实现关闭除指定页面外的其他所有页面的功能 比如在实现注销登录功能时,要保证旧有的webweiw或缓存不影响新用户的操作,就需要在跳转到登陆页面前关闭其他页面. http://www.cnblogs.c ...
- HDU 5572 An Easy Physics Problem【计算几何】
计算几何的题做的真是少之又少. 之前wa以为是精度问题,后来发现是情况没有考虑全... 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5572 题意: ...
- 关于Spring+mybatis+PageHelper分页插件PageHelper的使用策略
把插件jar包导入项目(具体上篇有介绍http://blog.csdn.net/qq_33624284/article/details/72821811) spring-mybatis.xml文件中配 ...
- 『创造 Cloud Toolkit』贡献排行榜——如何参与定义一款 IDE 插件?
自从我们团队在去年12月发布 Cloud Toolkit(一款让开发部署效率提速 8 倍的 IDE 插件)以来,已帮助数以万计的开发者们提高了云上的部署效率,期间,开发者们不仅积极地向 Cloud T ...
- POLARDB 2.0 重磅升级,分别支持Oracle与PostgreSQL
点击订阅新品发布会! 新产品.新版本.新技术.新功能.价格调整,评论在下方,下期更新!关注更多内容,了解更多 最新发布 POLARDB 2.0 重磅升级 2019年6月19日15时,阿里云 POLAR ...