在 Spring Boot 2.1.9 版本中寻找匹配的密码编码器 [英] Looking for matched password encoder in Spring Boot 2.1.9 release
问题描述
我正在将我的项目从 spring-boot 1.5.12.release 升级到 2.1.9.release.我在最新版本中找不到 org.springframework.security.authentication.encoding.ShaPasswordEncoder
的匹配编码器.以下是我在代码中的代码片段.
I am upgrading my project from spring-boot 1.5.12.release to 2.1.9.release. I am unable to find matching encoder for org.springframework.security.authentication.encoding.ShaPasswordEncoder
in latest version. The following is the code snippet I had it in my code.
@Autowired
private ShaPasswordEncoder encoder;
[...]
String passwordHash = encoder.encode((String)auth.getCredentials());
if (cachedAuth!=null && encoder.isPasswordValid((String) cachedAuth.getCredentials(), password, salt)){
return cachedAuth;
}
我在 Spring Boot 2.1.9 版本中发现了这个类 org.springframework.security.crypto.password.PasswordEncoder
但我没有这个方法 isPasswordValid()
这里.你能帮我解决这个问题吗.
I found this class org.springframework.security.crypto.password.PasswordEncoder
in Spring Boot 2.1.9 release but I don't have this method isPasswordValid()
here. Can you please help me to fix this.
推荐答案
@Bean
@SuppressWarnings("deprecation")
public PasswordEncoder delegatingPasswordEncoder() {
PasswordEncoder defaultEncoder = new StandardPasswordEncoder();
Map<String, PasswordEncoder> encoders = new HashMap<>();
encoders.put("SHA-256", new
org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-256"));
DelegatingPasswordEncoder passworEncoder = new DelegatingPasswordEncoder(
"bcrypt", encoders);
passworEncoder.setDefaultPasswordEncoderForMatches(defaultEncoder);
return passworEncoder;
}
这篇关于在 Spring Boot 2.1.9 版本中寻找匹配的密码编码器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!