@Bean
public PasswordEncoder passwordEncoder() {
/**
* 采坑
* spring-boot2 之后废弃了MD5,使用BCryptPasswordEncoder()加密;
*
*/
return new BCryptPasswordEncoder();
}
注意在security的配置内中,要使用BCryptPasswordEncoder 加密,不能使用自己实现的md5加密.(springboot2以上版本)
同时在Auth的配置内中配置secret也要加密BCryptPasswordEncoder
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient(clientOauthDataConfiguration.getClientId())
.secret(passwordEncoder.encode(clientOauthDataConfiguration.getSecret())) //客服端安全码
.authorizedGrantTypes(clientOauthDataConfiguration.getGrantTypes()) //授权类型
.accessTokenValiditySeconds(clientOauthDataConfiguration.getTokenValidityTime()) //token有效期
.refreshTokenValiditySeconds(clientOauthDataConfiguration.getRefreshTokenValidityTime()) //刷新token有效期
.scopes(clientOauthDataConfiguration.getScopes()); //客户端范围
}
最后注意,保存在数据库中的用户密码也要用BCryptPasswordEncoder这个加密