mirror of
https://github.com/spring-projects/spring-security.git
synced 2026-02-08 14:34:34 +00:00
Merge branch '7.0.x'
Closes gh-18595
This commit is contained in:
commit
ea8bd1a01d
@ -52,20 +52,14 @@ public final class HaveIBeenPwnedRestApiPasswordChecker implements CompromisedPa
|
||||
|
||||
private final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private final MessageDigest sha1Digest;
|
||||
|
||||
private RestClient restClient = RestClient.builder().baseUrl(API_URL).build();
|
||||
|
||||
public HaveIBeenPwnedRestApiPasswordChecker() {
|
||||
this.sha1Digest = getSha1Digest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompromisedPasswordDecision check(@Nullable String password) {
|
||||
if (password == null) {
|
||||
return new CompromisedPasswordDecision(false);
|
||||
}
|
||||
byte[] hash = this.sha1Digest.digest(password.getBytes(StandardCharsets.UTF_8));
|
||||
byte[] hash = getSha1Digest().digest(password.getBytes(StandardCharsets.UTF_8));
|
||||
String encoded = new String(Hex.encode(hash)).toUpperCase(Locale.ROOT);
|
||||
String prefix = encoded.substring(0, PREFIX_LENGTH);
|
||||
String suffix = encoded.substring(PREFIX_LENGTH);
|
||||
|
||||
@ -55,12 +55,6 @@ public class HaveIBeenPwnedRestApiReactivePasswordChecker implements ReactiveCom
|
||||
|
||||
private WebClient webClient = WebClient.builder().baseUrl(API_URL).build();
|
||||
|
||||
private final MessageDigest sha1Digest;
|
||||
|
||||
public HaveIBeenPwnedRestApiReactivePasswordChecker() {
|
||||
this.sha1Digest = getSha1Digest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<CompromisedPasswordDecision> check(@Nullable String password) {
|
||||
return getHash(password).map((hash) -> new String(Hex.encode(hash)))
|
||||
@ -98,7 +92,7 @@ public class HaveIBeenPwnedRestApiReactivePasswordChecker implements ReactiveCom
|
||||
|
||||
private Mono<byte[]> getHash(@Nullable String rawPassword) {
|
||||
return Mono.justOrEmpty(rawPassword)
|
||||
.map((password) -> this.sha1Digest.digest(password.getBytes(StandardCharsets.UTF_8)))
|
||||
.map((password) -> getSha1Digest().digest(password.getBytes(StandardCharsets.UTF_8)))
|
||||
.subscribeOn(Schedulers.boundedElastic())
|
||||
.publishOn(Schedulers.parallel());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user