Skip to content

Commit 08749d8

Browse files
authored
server: skip password policies check on empty password (#8370)
This PR changes the password.policy.regex default value to empty. With an empty value for the configuration, it is skipped during the password policy check, only when the configuration is set to something different than a blank string, the regex will get checked. This way, when creating a user on org.apache.cloudstack.ldap.LdapAuthenticator#authenticate() we won't get an error by default, as an empty value for the password is passed.
1 parent d83d994 commit 08749d8

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)