问题描述

今天在使用SpringBoot整合spring security,使用内存用户验证,但无响应报错:java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"

错误原因

这是因为Spring boot 2.0.3引用的security 依赖是 spring security 5.X版本,此版本需要提供一个PasswordEncorder的实例,否则后台汇报错误。

解决方式

创建一个类MyPasswordEncoder 实现PasswordEncoder接口

package com.wang.security.config;

import org.springframework.security.crypto.password.PasswordEncoder;

public class MyPasswordEncoder implements PasswordEncoder {
@Override
public String encode(CharSequence charSequence) {
return charSequence.toString();
} @Override
public boolean matches(CharSequence charSequence, String s) {
return s.equals(charSequence.toString());
}
}

在使用认证的时候用MyPasswordEncoder去校验密码

@Configuration
@EnableWebSecurity
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter { @Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//可以设置内存指定的登录的账号密码,指定角色
//不加.passwordEncoder(new MyPasswordEncoder())
//就不是以明文的方式进行匹配,会报错
auth.inMemoryAuthentication().withUser("wang").password("123456").roles("ADMIN");
//.passwordEncoder(new MyPasswordEncoder())。
//这样,页面提交时候,密码以明文的方式进行匹配。
auth.inMemoryAuthentication().passwordEncoder(new MyPasswordEncoder()).withUser("wang").password("123456").roles("ADMIN");
} @Override
protected void configure(HttpSecurity http) throws Exception {
//设置登录,注销,表单登录不用拦截,其他请求要拦截
http.authorizeRequests().antMatchers("/").permitAll()
.anyRequest().authenticated()
.and()
.logout().permitAll()
.and()
.formLogin();
//关闭默认的csrf认证
http.csrf().disable(); }

java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"的更多相关文章

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

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

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

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

  3. [Android] View.setTag(key,Object) (java.lang.IllegalArgumentException: The key must be an application-specific resource id.)

    转自: http://blog.csdn.net/brokge/article/details/8536906 setTag是android的view类中很有用的一个方法,可以用它来给空间附加一些信息 ...

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

    转载请注明出处 http://www.cnblogs.com/majianming/p/7923604.html 最近在学习spring security,但是在设置客户端密码时,一直出现了一下错误提 ...

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

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

  6. 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 ...

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

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

  8. java.lang.IllegalArgumentException: findUserById is ambiguous in Mapped Statements collection

    这是由于mybatis的mapper  xml文件中的id 名字和mybatis内置的方法可能有冲突导致的,  更改xml 的id  名字就可以了!

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

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

随机推荐

  1. Python网络编程笔记二

    使用select模块实现IO多路复用服务端 import socket import select #windows上只支持select.select,不支持poll epoll HOST = &qu ...

  2. Java中的选择结构

    1.if选择结构 if选择结构是根据条件判断之后再做处理的一种语法结构 语法: if(条件){ 代码块 //条件成立之后要执行的代码,可以是一条语句,也可以是一组语句 } if后小括号里的条件是一个表 ...

  3. 「CH2601」 电路维修 解题报告

    CH2601 电路维修 描述 Ha'nyu是来自异世界的魔女,她在漫无目的地四处漂流的时候,遇到了善良的少女Rika,从而被收留在地球上.Rika的家里有一辆飞行车.有一天飞行车的电路板突然出现了故障 ...

  4. 谁再问elasticsearch集群Red怎么办?把这篇笔记给他

    前言 可能你经历过这些Red. ...等等 那ES的Red是神么意思? 这里说的red,是指es集群的状态,一共有三种,green.red.yellow.具体含义: 冷静分析 从上图可知,集群red是 ...

  5. IPython的介绍与使用

    1.IPython简介 ipython是一个python的交互式shell,比默认的python shell好用得多,支持变量自动补全,自动缩进,支持bash shell命令,内置了许多很有用的功能和 ...

  6. 2020 年了,Java 日志框架到底哪个性能好?——技术选型篇

    大家好,之前写(shui)了两篇其他类型的文章,感觉大家反响不是很好,于是我乖乖的回来更新硬核技术文了. 经过本系列前两篇文章我们了解到日志框架大战随着 SLF4j 的一统天下而落下帷幕,但 SLF4 ...

  7. laravel配置加解密

    基于安全考虑,我们php项目配置文件中密码应该是加密的,laravel中也提供了OpenSSL 的 AES-256-CBC 来进行加密 但是如果我们项目配置的是其他加密方式,且希望以最少的改动实现读取 ...

  8. L1-006 连续因子 (20分)

    题意分析 题目中已经将意思说的很清楚了,就是输出一个数的最长连续因子的个数,并且输出是哪几个因子相乘.可以将题目从这两个角度进行分析: N为素数时,最长连续因子的个数为1,即它自己. N不为素数时,即 ...

  9. cogs 728. [网络流24题] 最小路径覆盖问题 匈牙利算法

    728. [网络流24题] 最小路径覆盖问题 ★★★☆   输入文件:path3.in   输出文件:path3.out   评测插件时间限制:1 s   内存限制:128 MB 算法实现题8-3 最 ...

  10. 修理牛棚 贪心 USACO

    今天开始终于可以刷USACO的题啦 准备每一道都发一个题解 1010: 1.3.2 Barn Repair 修理牛棚 时间限制: 1 Sec  内存限制: 128 MB提交: 9  解决: 7[提交] ...