|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2022 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
19 | 19 | import java.util.HashMap;
|
20 | 20 | import java.util.Map;
|
21 | 21 |
|
| 22 | +import org.springframework.util.StringUtils; |
| 23 | + |
22 | 24 | /**
|
23 | 25 | * A password encoder that delegates to another PasswordEncoder based upon a prefixed
|
24 | 26 | * identifier.
|
@@ -129,6 +131,10 @@ public class DelegatingPasswordEncoder implements PasswordEncoder {
|
129 | 131 |
|
130 | 132 | private static final String DEFAULT_ID_SUFFIX = "}";
|
131 | 133 |
|
| 134 | + public static final String NO_PASSWORD_ENCODER_MAPPED = "There is no PasswordEncoder mapped for the id \"%s\""; |
| 135 | + |
| 136 | + public static final String NO_PASSWORD_ENCODER_PREFIX = "You have entered a password with no PasswordEncoder. If that is your intent, it should be prefixed with `{noop}`."; |
| 137 | + |
132 | 138 | private final String idPrefix;
|
133 | 139 |
|
134 | 140 | private final String idSuffix;
|
@@ -286,15 +292,10 @@ public String encode(CharSequence rawPassword) {
|
286 | 292 | @Override
|
287 | 293 | public boolean matches(CharSequence rawPassword, String prefixEncodedPassword) {
|
288 | 294 | String id = extractId(prefixEncodedPassword);
|
289 |
| - checkIfStringIsEmptyOrNull(id); |
290 |
| - throw new IllegalArgumentException("There is no PasswordEncoder mapped for the id \"" + id + "\""); |
291 |
| - } |
292 |
| - |
293 |
| - private void checkIfStringIsEmptyOrNull(String string) { |
294 |
| - if (string == null || string.isEmpty()) { |
295 |
| - throw new IllegalArgumentException( |
296 |
| - "You have entered a password with no PasswordEncoder. If that is your intent, it should be prefixed with `{noop}`."); |
| 295 | + if (StringUtils.hasText(id)) { |
| 296 | + throw new IllegalArgumentException(String.format(NO_PASSWORD_ENCODER_MAPPED, id)); |
297 | 297 | }
|
| 298 | + throw new IllegalArgumentException(NO_PASSWORD_ENCODER_PREFIX); |
298 | 299 | }
|
299 | 300 |
|
300 | 301 | }
|
|
0 commit comments