There is no PasswordEncoder mapped for the id "null"

springboot集成 spring-security认证报错-->  There is no PasswordEncoder mapped for the id "null"

 

 

 

在网上看到说是 springboot 2.1.x之前可以直接使用,之后认证就会

There is no PasswordEncoder mapped for the id "null"

 

解决方案:

  

//认证 springboot 2.1.x 可以直接使用~
    //密码编译,passwordEncoder
    //在spring security 5.0+ 新增了很多的加密方式~ 如果没有密码,会不让你使用,明文密码会遭受到反编译,不安全
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {

        //这些数据正常应该是从数据库中读取
        auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder())
                .withUser("aaa")password(new BCryptPasswordEncoder().encode("123456")).roles("vip2","vip3")
          .and()
          .withUser(
"root").password("123456").roles("vip1","vip2","vip3")
          .and()
          .withUser(
"guest").password("123456").roles("vip1") ; }

 

  

posted @ 2021-02-19 16:22  大大大怪兽  阅读(139)  评论(0编辑  收藏  举报