码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2020-02-14 10:31:36      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:word   map   div   config   ring   on()   author   内存   cte   

问题描述:

使用springboot,权限管理使用spring security,使用内存用户验证,但无响应报错:

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

解决方式

①:

创建MyPasswordEncoder类实现PasswordEncoder,加注解  @Component

@Component
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());
    }
}

 

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        //如果程序报错There is no PasswordEncoder mapped for the id "null",就将该段注释添加下边代码
        //或者在MyPasswordEncoder类上加一个@Component注解,使它成为一个Bean
        auth.inMemoryAuthentication().withUser("admin").password("123456").authorities("ADMIN_ADD","ADMIN_FIND");//自定义登录用户用户名和密码并赋予一些权限
    }

②:

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

        //这个是使用了匿名内部类
        auth.inMemoryAuthentication().passwordEncoder(new MyPasswordEncoder()).withUser("lxy").password("lxy").authorities("ADMIN_ADD","ADMIN_FIND");
    }

 

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

标签:word   map   div   config   ring   on()   author   内存   cte   

原文地址:https://www.cnblogs.com/think-world/p/12306217.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!