zoukankan      html  css  js  c++  java
  • Spring Security 报There is no PasswordEncoder mapped for the id "null"

    原代码为:

    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
            auth.inMemoryAuthentication()
                .withUser("rg2")
                .password("123456")
                .roles("ADMIN");
    }

    记过发现报错Spring Security 报There is no PasswordEncoder mapped for the id "null"

    原因是Spring Security 升级到5版本后密码支持多种加密格式;

    添加一个新的类

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

    然后再原代码中改为

        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
            auth.inMemoryAuthentication().passwordEncoder(new MyPasswordEncoder())
                .withUser("rg2")
                .password("123456")
                .roles("ADMIN");
        }
  • 相关阅读:
    [转] linux 信号量之SIGNAL
    [转] 查看CPU使用率 top命令详解
    shell 脚本编程
    ToggleButton
    MultiAutoCompleteTextView
    AutoCompleteTextView
    IO流总结
    JavaWeb 案例——访问权限控制
    IO流之字符流
    File类
  • 原文地址:https://www.cnblogs.com/zhengyuanyuan/p/9163650.html
Copyright © 2011-2022 走看看