Skip to content

Commit a97ce24

Browse files
committed
Merge remote-tracking branch 'apache/4.18'
2 parents ab80899 + 08749d8 commit a97ce24

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

server/src/main/java/com/cloud/user/PasswordPolicyImpl.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ public class PasswordPolicyImpl implements PasswordPolicy, Configurable {
2727
private Logger logger = Logger.getLogger(PasswordPolicyImpl.class);
2828

2929
public void verifyIfPasswordCompliesWithPasswordPolicies(String password, String username, Long domainId) {
30+
if (StringUtils.isEmpty(password)) {
31+
logger.warn(String.format("User [%s] has an empty password, skipping password policy checks. " +
32+
"If this is not a LDAP user, there is something wrong.", username));
33+
return;
34+
}
35+
3036
int numberOfSpecialCharactersInPassword = 0;
3137
int numberOfUppercaseLettersInPassword = 0;
3238
int numberOfLowercaseLettersInPassword = 0;
@@ -188,12 +194,12 @@ protected void validateIfPasswordMatchesRegex(String password, String username,
188194
logger.trace(String.format("Validating if the new password for user [%s] matches regex [%s] defined in the configuration [%s].",
189195
username, passwordPolicyRegex, PasswordPolicyRegex.key()));
190196

191-
if (passwordPolicyRegex == null){
192-
logger.trace(String.format("Regex is null; therefore, we will not validate if the new password matches with regex for user [%s].", username));
197+
if (StringUtils.isEmpty(passwordPolicyRegex)) {
198+
logger.trace(String.format("Regex is empty; therefore, we will not validate if the new password matches with regex for user [%s].", username));
193199
return;
194200
}
195201

196-
if (!password.matches(passwordPolicyRegex)){
202+
if (!password.matches(passwordPolicyRegex)) {
197203
logger.error(String.format("User [%s] informed a new password that does not match with regex [%s]. Refusing the user's new password.", username, passwordPolicyRegex));
198204
throw new InvalidParameterValueException("User password does not match with password policy regex.");
199205
}

0 commit comments

Comments
 (0)