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

出现问题的原因:

  内存用户验证时,Spring boot 2.0.1引用的security 依赖是 spring security 5.X版本,此版本需要提供一个PasswordEncorder的实例,否则后台汇报错误:
java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"
并且页面毫无响应。

解决方法:

创建PasswordEncorder的实现类MyPasswordEncoder。

代码一:

 1 package com.mmall.demo;
 2
 3 import org.springframework.security.crypto.password.PasswordEncoder;
 4
 5 public class MyPasswordEncoder implements PasswordEncoder {
 6     @Override
 7     public String encode(CharSequence rawPassword) {
 8         return rawPassword.toString();
 9     }
10
11     @Override
12     public boolean matches(CharSequence rawPassword, String encodedPassword) {
13         return encodedPassword.equals(rawPassword);
14     }
15 }

代码二:

 1 package com.mmall.demo;
 2
 3 import org.springframework.context.annotation.Configuration;
 4 import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
 5 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
 6 import org.springframework.security.config.annotation.web.builders.WebSecurity;
 7 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
 8 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
 9
10 @Configuration
11 @EnableWebSecurity
12 public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
13
14     @Override
15     protected void configure(AuthenticationManagerBuilder auth) throws Exception {
16         auth.inMemoryAuthentication().
17                 passwordEncoder(new MyPasswordEncoder()).
18                 withUser("admin").password("123456").roles("ADMIN");
19     }
20
21     @Override
22     protected void configure(HttpSecurity http) throws Exception {
23        http.authorizeRequests()
24                .antMatchers("/").permitAll()
25                .anyRequest().authenticated()
26                .and()
27                .logout().permitAll()
28                .and()
29                .formLogin();
30        http.csrf().disable();
31     }
32
33     @Override
34     public void configure(WebSecurity web) throws Exception {
35         web.ignoring().antMatchers("/js/**","/css/**","/image/**");
36     }
37
38
39 }

原文地址:https://www.cnblogs.com/chenyanlong/p/10688662.html

时间: 2024-11-06 22:39:30

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

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

今天在配置spring-security.xml配置文件时出错 错误如下: 严重: Servlet.service() for servlet [security] in context with path [] threw exception java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null" at org.springframework.security.c

java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null”

在spring security中设置默认的登录人的信息,遇到的异常信息: java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null” 有些版本不要求这样子做,所以就不会有该问题的发生, 我现在用的是5.0版本,强制要求提供一个,所以我们就给一个PasswordEncoder给他. 我们也可以使用Spring自带的PasswordEncoder.为了方便起见,我们以明文形式存密码

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

问题描述: 使用springboot,权限管理使用spring security,使用内存用户验证,但无响应报错: java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null" 解决方式 ①: 创建MyPasswordEncoder类实现PasswordEncoder,加注解  @Component @Component public class MyPasswordEn

java.lang.IllegalArgumentException: XXX is ambiguous in Mapped Statements collection

问题的出现: 在后台添加一个新栏目的时候,照着程序已有原来的代码添加新的功能时,文件没有错误.点击新的栏目的时候报了java.lang.IllegalArgumentException: selectPageByExample is ambiguous in Mapped Statements collection (try using the full name including the namespace, or rename one of the entries). 解决: 在网上查找了

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类中很有用的一个方法,可以用它来给空间附加一些信息,在很多场合下都得到妙用. setTag(Object tag)方法比较简单,这里主要谈一谈带两个参数的setTag方法. 官方的api文档中提到:" The specified key should be an id declared in the resources of the applica

There is no PasswordEncoder mapped for the id "null"

因为Spring-Security从4+升级到5+,导致There is no PasswordEncoder mapped for the id “null”错误. 解决方案: 1.可在密码验证类中添加 @Bean public static NoOpPasswordEncoder passwordEncoder() { return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance(); } 2.或者在xml配置文件中添加 <b:be

Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for &hellip;

编译通过并且运行web成功后,访问的页面不需要连接数据库,不牵扯到反射调用实体类就不会报错, 报错内容如下: [WARNING] org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exce

搭建Mybatis 出现 Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mapper.BatchCustomer.findBatchCustomerOneToOne

Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mapper.BatchCustomer.findBatchCustomerOneToOne### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does

Hive报错 Failed with exception java.io.IOException:java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: ${system:user.name%7D

报错信息如下 Failed with exception java.io.IOException:java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: ${system:user.name%7D 解决方法: 编辑 hive-site.xml 文件,添加下边的属性 <property> <name>system:java.io.tmpdir<