**
SpringSecurity中遇到的坑
**
1.控制台警告:There is no PasswordEncoder mapped for the id “null”
解决方法:
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
2.控制台警告:Encoded password does not look like BCrypt,输入正确密码也报错
百思不得解,将加密方式改为:
public PasswordEncoder passwordEncoder() {
return NoOpPasswordEncoder.getInstance();
}
这我也不知道为什么,这样就可以。看视频学习,照着敲别人可以我却不行。
还有一种解决方案就是将加密方式改回 1中的,然后对jwt的解密 密钥加密
secret(passwordEncoder.encode(“SECRET”))
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients
.inMemory()
.withClient("clientapp")
.authorizedGrantTypes("password","refresh_token")
.authorities("USER")
.scopes("read", "write")
.resourceIds(RESOURCE_ID)
.secret(passwordEncoder.encode("SECRET"));
}
可以参考这篇文章:链接: https://stackoverflow.com/questions/49582971/encoded-password-does-not-look-like-bcrypt