There is no PasswordEncoder mapped for the id "null"'错误的解决方式


解决方式:自定义加密方式,实现PasswordEncoder接口

 

修改前:

 @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser("yrc").password("111").roles("USER")
                .and()
                .withUser("tx").password("222").roles("USER");
    }
   

 

修改后:此处使用明文,其实就是不加密

  (1)加密类

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

  (2)

 @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .passwordEncoder(new MyPasswordEncoder())
                .withUser("yrc").password("111").roles("USER")
                .and()
                .withUser("tx").password("222").roles("USER");
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM