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.为了方便起见,我们以明文形式存密码在后台,故使用自定义PasswordEncoder

自定义passwordEncoder

public class MyPasswordEncoder implements PasswordEncoder {

    @Override
    public String encode(CharSequence arg0) {
        return arg0.toString();
    }

    @Override
    public boolean matches(CharSequence arg0, String arg1) {
        return arg1.equals(arg0.toString());
    }

}

应用自定义编码器

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {

        auth
          .inMemoryAuthentication()
          .passwordEncoder(new MyPasswordEncoder())//在此处应用自定义PasswordEncoder
          .withUser("user")
          .password("password")
          .roles("USER");
    }
}

自带编码器

@Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

别忘了在注册用户的地方添加编码器加密

增加一个passwordEncoder就可以解决这种异常

原文地址:https://www.cnblogs.com/qingmuchuanqi48/p/12219470.html

时间: 2024-07-30 01:56:51

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 boot 2.0.1引用的security 依赖是 spring security 5.X版本,此版本需要提供一个PasswordEncorder的实例,否则后台汇报错误: java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null" 并且页面毫无响应. 解决方法: 创建PasswordEncorder的实现类MyPassw

解决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<