美文网首页springboot
Spring Security 报There is no Pas

Spring Security 报There is no Pas

作者: yyq唯心不易 | 来源:发表于2018-03-30 18:18 被阅读1213次

    查了下发现是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
        }
    

    相关文章

      网友评论

      • Bury丶冬天:加上了也没什么卵用啊 还是报这个错
      • IT人故事会:经常看别人的分享.感谢别人的分享,感谢!关注了

      本文标题:Spring Security 报There is no Pas

      本文链接:https://www.haomeiwen.com/subject/fwnicftx.html