问题描述

今天在使用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. mysql中information_schema.columns字段说明

    1. 获取所有列信息(COLUMNS) SELECT  *  FROM information_schema.COLUMNS WHERE  TABLE_SCHEMA='数据库名';  COLUMNS表 ...

  2. java中把某个字符串中的单引号替换成双引号

    String regexp = "\'";String str = "'good'";System.out.println("替换前:" + ...

  3. Zeus,一个可以快速使用微服务组件

    去年(上周)一直准备着做一个分布式微服务的组件,可以让使用者用最简单的方式引入,只需要使用简单的注解就能够使用. 用一点一点的空闲时间终于堆出来一个暂时可用的zeus-1.0版本. Zeus,意为宙斯 ...

  4. 三句话说清楚ssh端口转发

    看了下自己以前的笔记发现也没有完全搞清楚, 网上好多文章都是抄来抄去,远程端口转发全都是拿127.0.0.1举例 总结了下,三句话就可以讲清楚了   1 ssh本地端口转发是 把ssh服务器可以访问到 ...

  5. 日志管理-log4j与slf4j的使用

    一.概述 1.log4j: Log4j是Apache的一个开源项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件,甚至是套接口服务器.NT的事件记录器.UNIX Sy ...

  6. 20191107-4 beta week 2/2 Scrum立会报告+燃尽图 03

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2019fall/homework/9956 小组名称:“组长”组 组长:杨天宇 组员:魏新,罗杨美慧,王歆瑶, ...

  7. Python 线性回归(Linear Regression) - 到底什么是 regression?

    背景 学习 Linear Regression in Python – Real Python,对 regression 一词比较疑惑. 这个 linear Regression 中的 Regress ...

  8. 1050 螺旋矩阵 (25 分)C语言

    本题要求将给定的 N 个正整数按非递增的顺序,填入"螺旋矩阵".所谓"螺旋矩阵",是指从左上角第 1 个格子开始,按顺时针螺旋方向填充.要求矩阵的规模为 m 行 ...

  9. 使用Rancher Server部署本地多节点K8S集群

    当我第一次开始我的Kubernetes之旅时,我一直在寻找一种设置本地部署环境的方式.很多人常常会使用minikube或microk8s,这两者非常适合新手在单节点集群环境下进行操作.但当我已经了解了 ...

  10. [MariaDB]MHA高可用部署-实验

    目录 一.简介 1.1MHA角色 二.MHA的工具 三.MHA部署过程 3.1.1 配置 3.1.2 环境规划 3.1.3 配置一主多从 3.2 MHA配置 3.2.1 master权限授予 3.2. ...