Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce maxPasswordAllowedLength config. #6182

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2022-2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -22,6 +22,7 @@
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.identity.input.validation.mgt.exceptions.InputValidationMgtClientException;
import org.wso2.carbon.identity.input.validation.mgt.model.Property;
import org.wso2.carbon.identity.input.validation.mgt.model.ValidationContext;
Expand All @@ -33,7 +34,9 @@
import java.util.stream.Collectors;

import static org.wso2.carbon.identity.input.validation.mgt.utils.Constants.Configs.MAX_LENGTH;
import static org.wso2.carbon.identity.input.validation.mgt.utils.Constants.Configs.MAX_PASSWORD_ALLOWED_LENGTH;
import static org.wso2.carbon.identity.input.validation.mgt.utils.Constants.Configs.MIN_LENGTH;
import static org.wso2.carbon.identity.input.validation.mgt.utils.Constants.Configs.PASSWORD;
import static org.wso2.carbon.identity.input.validation.mgt.utils.Constants.ErrorMessages.ERROR_DEFAULT_MIN_MAX_MISMATCH;
import static org.wso2.carbon.identity.input.validation.mgt.utils.Constants.ErrorMessages.ERROR_INVALID_VALIDATOR_PROPERTY_VALUE;
import static org.wso2.carbon.identity.input.validation.mgt.utils.Constants.ErrorMessages.ERROR_PROPERTY_NOT_SUPPORTED;
Expand Down Expand Up @@ -93,6 +96,21 @@ public boolean validateProps(ValidationContext context) throws InputValidationMg
String.format(ERROR_DEFAULT_MIN_MAX_MISMATCH.getDescription(), this.getClass().getSimpleName(),
properties.get(MIN_LENGTH), properties.get(MAX_LENGTH)));
}

// Validate the max length for the password field.
if (PASSWORD.equals(context.getField())) {
int maxPasswordValue = Integer.parseInt(IdentityUtil.getProperty(MAX_PASSWORD_ALLOWED_LENGTH));
if (properties.get(MAX_LENGTH) != null &&
Integer.parseInt(properties.get(MAX_LENGTH)) > maxPasswordValue) {
if (log.isDebugEnabled()) {
log.error(String.format("The property %s should be less than or equal to %s for the tenant %s.",
kayathiri4 marked this conversation as resolved.
Show resolved Hide resolved
MAX_LENGTH, maxPasswordValue, context.getTenantDomain()));
}
throw new InputValidationMgtClientException(ERROR_PROPERTY_TYPE_MISMATCH.getCode(),
kayathiri4 marked this conversation as resolved.
Show resolved Hide resolved
String.format(ERROR_PROPERTY_TYPE_MISMATCH.getDescription(), MAX_LENGTH, maxPasswordValue,
context.getTenantDomain()));
}
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2022-2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down Expand Up @@ -69,6 +69,7 @@ public static class Configs {
public static final String MAX_CONSECUTIVE_CHR = "max.consecutive.character";
public static final String ENABLE_VALIDATOR = "enable.validator";
public static final String ENABLE_SPECIAL_CHARACTERS = "enable.special.characters";
public static final String MAX_PASSWORD_ALLOWED_LENGTH = "PasswordPolicy.MaxPasswordAllowedLength";

// Keys for password regEx validation.
public static final String JS_REGEX = "regex";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,10 @@
<!--<EnableErrorCodeForPasswordPolicyViolation>{{scim2.enable_error_code_for_password_policy_violations}}</EnableErrorCodeForPasswordPolicyViolation>-->
</SCIM2>

<PasswordPolicy>
<MaxPasswordAllowedLength>64</MaxPasswordAllowedLength>
pavinduLakshan marked this conversation as resolved.
Show resolved Hide resolved
</PasswordPolicy>

<!--Recovery>
<EnableV1API>false</EnableV1API>
<ReCaptcha>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,8 @@
</SCIM2>

<PasswordPolicy>
<PasswordPolicyValidationHandler>
<MaxPasswordAllowedLength>{{identity_mgt.password_policy.max_password_allowed_length}}</MaxPasswordAllowedLength>
<PasswordPolicyValidationHandler>
<Enable>{{identity_mgt.password_policy.password_policy_validation_handler.enable}}</Enable>
</PasswordPolicyValidationHandler>
</PasswordPolicy>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@
"scim2.consider_server_wide_user_endpoint_max_limit": true,

"identity_mgt.password_policy.password_policy_validation_handler.enable": true,
"identity_mgt.password_policy.max_password_allowed_length": 64,
"identity_mgt.recovery.enable_v1_api": false,
"identity_mgt.recovery.notification.manage_internally": true,
"identity_mgt.recovery.callback_url": "${carbon.protocol}:\\/\\/${carbon.host}:${carbon.management.port}\\/.*",
Expand Down
Loading