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

    查了下发现是spring security 版本在5.0后就要加个PasswordEncoder了

    解决办法
    1. 在securityConfig类下加入NoOpPasswordEncoder,不过官方已经不推荐了
        @Bean
        public static NoOpPasswordEncoder passwordEncoder() {
            return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance();
        }
    
    1. 在securityConfig类下加入密码加密,在数据库中存的密码也是要经过这个加密的才能匹配上
        @Autowired
        private UserDetailsService customUserService;
    
        @Override
        public void configure(AuthenticationManagerBuilder auth) throws Exception {
            auth.userDetailsService(customUserService).passwordEncoder(new BCryptPasswordEncoder());
        }
    

    补充:加密操作

        public static void main(String[] args) {
            BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
            //加密"0"
            String encode = bCryptPasswordEncoder.encode("0");
            System.out.println(encode);
            //结果:$2a$10$/eEV4X7hXPzYGzOLXfCizu6h7iRisp7I116wPA3P9uRcHAKJyY4TK
        }


    作者:yyq唯心不易
    链接:https://www.jianshu.com/p/9e7792d767b2
    来源:简书
    简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
  • 相关阅读:
    pipeline流水线语法格式
    nexus私服配置npm、nuget、pypi
    正则表达式-grep
    awk 经典案例
    nginx安装,配置,及高可用
    git remote add origin错误
    [转]Git 撤销操作
    [转]git命令之git remote的用法
    [转]git学习------>git-rev-parse命令初识
    转 gerrit
  • 原文地址:https://www.cnblogs.com/telwanggs/p/10802499.html
Copyright © 2011-2022 走看看