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 ...
随机推荐
- ThinkPHP中_after_update、_before_update等的用法
https://blog.csdn.net/aslackers/article/details/50339163 TP系统\Think\Model类里隐藏了几个有用的方法: _before_inser ...
- 大数据技术之Flume
第1章 概述 1.1 Flume定义 Flume是Cloudera提供的一个高可用的,高可靠的,分布式的海量日志采集.聚合和传输的系统.Flume基于流式架构,灵活简单. 1.2 Flume组成架构 ...
- RocksDB 之Write Ahead Log(WAL)
Overview RocksDB 中有三个基本的数据结构概念:memtable, sstfile 和 logfile memtable 是个内存数据结构,新写入会插入memtable 切回选择性地写入 ...
- python 类的创建
- SDUT-3363_驴友计划
数据结构实验之图论七:驴友计划 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 做为一个资深驴友,小新有一张珍藏的自驾游 ...
- Leetcode784.Letter Case Permutation字母大小写全排列
给定一个字符串S,通过将字符串S中的每个字母转变大小写,我们可以获得一个新的字符串.返回所有可能得到的字符串集合. 示例: 输入: S = "a1b2" 输出: ["a1 ...
- SpringCloud Zuul 路由映射规则配置
阅读目录 前言 快速入门 路由详解 Cookie与头信息 本地跳转 Hystrix和Ribbon支持 过滤器解释 动态加载 后记 回到目录 前言 本文起笔于2018-06-26周二,接了一个这周要完成 ...
- 【UTR #1】ydc的大树
[UTR #1]ydc的大树 全网唯一一篇题解我看不懂 所以说一下我的O(nlogn)做法: 以1号点为根节点 一个黑点如果有多个相邻的节点出去都能找到最远的黑点,那么这个黑点就是无敌的 所以考虑每个 ...
- 突破!阿里云CDN实现毫秒级全网刷新
通常在某网站使用了CDN节点来实现内容分发加速后,当源站内容更新的时候,CDN刷新系统会通过提交刷新请求将CDN节点上的指定缓存内容强制过期.当用户访问的时候,CDN节点将回源获取最新内容返回给用户, ...
- python元组和range
1.元组 1)元组介绍 元组: 俗称不可变的列表.⼜被成为只读列表, 元组也是python的基本数据类型之⼀, ⽤⼩括号括起来, ⾥⾯可以放任何数据类型的数据, 查询可以. 循环也可以. 切片也可以. ...