From 3779031d504be0652c1a4d3658bb2642a4e0e5e6 Mon Sep 17 00:00:00 2001 From: Malith-19 Date: Fri, 6 Dec 2024 11:41:22 +0530 Subject: [PATCH 1/8] Add maxPasswordAllowedLength config. --- .../resources/identity.xml | 4 ++++ .../resources/identity.xml.j2 | 3 ++- .../org.wso2.carbon.identity.core.server.feature.default.json | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/identity.xml b/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/identity.xml index 1eafa77d3c41..77a2b6890561 100644 --- a/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/identity.xml +++ b/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/identity.xml @@ -1032,6 +1032,10 @@ + + 64 + + + From e58da0b864bb4f189b914265dfe4e5ad532f676a Mon Sep 17 00:00:00 2001 From: Malith-19 Date: Tue, 10 Dec 2024 12:15:30 +0530 Subject: [PATCH 5/8] Address the comments. --- .../model/validators/AbstractRulesValidator.java | 9 +++++---- .../validators/AbstractRulesValidatorTest.java | 15 +++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/src/main/java/org/wso2/carbon/identity/input/validation/mgt/model/validators/AbstractRulesValidator.java b/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/src/main/java/org/wso2/carbon/identity/input/validation/mgt/model/validators/AbstractRulesValidator.java index 07df11246b28..afef429ee06f 100644 --- a/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/src/main/java/org/wso2/carbon/identity/input/validation/mgt/model/validators/AbstractRulesValidator.java +++ b/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/src/main/java/org/wso2/carbon/identity/input/validation/mgt/model/validators/AbstractRulesValidator.java @@ -41,6 +41,7 @@ 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; import static org.wso2.carbon.identity.input.validation.mgt.utils.Constants.ErrorMessages.ERROR_PROPERTY_TYPE_MISMATCH; +import static org.wso2.carbon.identity.input.validation.mgt.utils.Constants.ErrorMessages.ERROR_VALIDATION_MAX_LENGTH_MISMATCH; import static org.wso2.carbon.identity.input.validation.mgt.utils.Constants.SUPPORTED_PARAMS; /** @@ -103,12 +104,12 @@ public boolean validateProps(ValidationContext context) throws InputValidationMg 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.", + log.debug(String.format("The property %s should be less than or equal to %s for the tenant %s.", MAX_LENGTH, maxPasswordValue, context.getTenantDomain())); } - throw new InputValidationMgtClientException(ERROR_PROPERTY_TYPE_MISMATCH.getCode(), - String.format(ERROR_PROPERTY_TYPE_MISMATCH.getDescription(), MAX_LENGTH, maxPasswordValue, - context.getTenantDomain())); + throw new InputValidationMgtClientException(ERROR_VALIDATION_MAX_LENGTH_MISMATCH.getCode(), + String.format(ERROR_VALIDATION_MAX_LENGTH_MISMATCH.getDescription(), + MAX_LENGTH, maxPasswordValue, context.getTenantDomain())); } } return true; diff --git a/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/src/test/java/org/wso2/carbon/identity/input/validation/mgt/test/model/validators/AbstractRulesValidatorTest.java b/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/src/test/java/org/wso2/carbon/identity/input/validation/mgt/test/model/validators/AbstractRulesValidatorTest.java index a2221c17c4e3..c76349cf85d6 100644 --- a/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/src/test/java/org/wso2/carbon/identity/input/validation/mgt/test/model/validators/AbstractRulesValidatorTest.java +++ b/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/src/test/java/org/wso2/carbon/identity/input/validation/mgt/test/model/validators/AbstractRulesValidatorTest.java @@ -42,29 +42,33 @@ 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; +/** + * Testing the AbstractRulesValidator class + */ public class AbstractRulesValidatorTest { + // Test constants. + private static final String TENANT_DOMAIN = "carbon.super"; @Mock private ValidationContext mockContext; - private MockedStatic identityUtil; - // Test constants. - private static final String TENANT_DOMAIN = "carbon.super"; - @BeforeMethod public void setup() { + MockitoAnnotations.openMocks(this); identityUtil = mockStatic(IdentityUtil.class); } @AfterMethod public void tearDown() { + identityUtil.close(); } @DataProvider(name = "validationScenarios") public Object[][] validationScenarios() { + Map validProperties = new HashMap<>(); validProperties.put(MIN_LENGTH, "5"); validProperties.put(MAX_LENGTH, "10"); @@ -109,8 +113,7 @@ public Object[][] validationScenarios() { {validPasswordProperties, PASSWORD, TENANT_DOMAIN, true, null}, // Password properties without MAX_LENGTH. - {passwordPropertiesWithoutMax, PASSWORD, TENANT_DOMAIN, true, null} - }; + {passwordPropertiesWithoutMax, PASSWORD, TENANT_DOMAIN, true, null}}; } @Test(dataProvider = "validationScenarios") From a78135f56716da11e9c08e4e268b5e6d2687ee3a Mon Sep 17 00:00:00 2001 From: Malith-19 Date: Tue, 10 Dec 2024 12:24:17 +0530 Subject: [PATCH 6/8] Update the property name in the error message. --- .../mgt/model/validators/AbstractRulesValidator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/src/main/java/org/wso2/carbon/identity/input/validation/mgt/model/validators/AbstractRulesValidator.java b/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/src/main/java/org/wso2/carbon/identity/input/validation/mgt/model/validators/AbstractRulesValidator.java index afef429ee06f..00ee1868d36e 100644 --- a/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/src/main/java/org/wso2/carbon/identity/input/validation/mgt/model/validators/AbstractRulesValidator.java +++ b/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/src/main/java/org/wso2/carbon/identity/input/validation/mgt/model/validators/AbstractRulesValidator.java @@ -108,8 +108,8 @@ public boolean validateProps(ValidationContext context) throws InputValidationMg MAX_LENGTH, maxPasswordValue, context.getTenantDomain())); } throw new InputValidationMgtClientException(ERROR_VALIDATION_MAX_LENGTH_MISMATCH.getCode(), - String.format(ERROR_VALIDATION_MAX_LENGTH_MISMATCH.getDescription(), - MAX_LENGTH, maxPasswordValue, context.getTenantDomain())); + String.format(ERROR_VALIDATION_MAX_LENGTH_MISMATCH.getDescription(), PASSWORD, maxPasswordValue, + context.getTenantDomain())); } } return true; From 534db001fcd6faf6b2b6245ac7dff7b0144d60d6 Mon Sep 17 00:00:00 2001 From: Malith Dilshan <79596630+Malith-19@users.noreply.github.com> Date: Fri, 13 Dec 2024 10:21:11 +0530 Subject: [PATCH 7/8] Update the number to string in default.json. --- .../org.wso2.carbon.identity.core.server.feature.default.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/org.wso2.carbon.identity.core.server.feature.default.json b/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/org.wso2.carbon.identity.core.server.feature.default.json index 0500185b2f7c..c1c4a26de3a2 100644 --- a/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/org.wso2.carbon.identity.core.server.feature.default.json +++ b/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/org.wso2.carbon.identity.core.server.feature.default.json @@ -373,7 +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.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}\\/.*", From 78cc50603f5691954937ff7c5b809c0ba52b0953 Mon Sep 17 00:00:00 2001 From: Malith-19 Date: Fri, 13 Dec 2024 11:27:05 +0530 Subject: [PATCH 8/8] Update the default value. --- .../handlers/PasswordValidationConfigurationHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/src/main/java/org/wso2/carbon/identity/input/validation/mgt/model/handlers/PasswordValidationConfigurationHandler.java b/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/src/main/java/org/wso2/carbon/identity/input/validation/mgt/model/handlers/PasswordValidationConfigurationHandler.java index 1b3eabee79e3..81f910582a5a 100644 --- a/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/src/main/java/org/wso2/carbon/identity/input/validation/mgt/model/handlers/PasswordValidationConfigurationHandler.java +++ b/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/src/main/java/org/wso2/carbon/identity/input/validation/mgt/model/handlers/PasswordValidationConfigurationHandler.java @@ -73,7 +73,7 @@ public ValidationConfiguration getDefaultValidationConfiguration(String tenantDo if (isRuleBasedValidationByDefault()) { rules.add(getRuleConfig(LengthValidator.class.getSimpleName(), MIN_LENGTH, "8")); - rules.add(getRuleConfig(LengthValidator.class.getSimpleName(), MAX_LENGTH, "30")); + rules.add(getRuleConfig(LengthValidator.class.getSimpleName(), MAX_LENGTH, "64")); rules.add(getRuleConfig(NumeralValidator.class.getSimpleName(), MIN_LENGTH, "1")); rules.add(getRuleConfig(UpperCaseValidator.class.getSimpleName(), MIN_LENGTH, "1")); rules.add(getRuleConfig(LowerCaseValidator.class.getSimpleName(), MIN_LENGTH, "1")); @@ -85,7 +85,7 @@ public ValidationConfiguration getDefaultValidationConfiguration(String tenantDo } } else { rules.add(getRuleConfig(LengthValidator.class.getSimpleName(), MIN_LENGTH, "8")); - rules.add(getRuleConfig(LengthValidator.class.getSimpleName(), MAX_LENGTH, "30")); + rules.add(getRuleConfig(LengthValidator.class.getSimpleName(), MAX_LENGTH, "64")); rules.add(getRuleConfig(NumeralValidator.class.getSimpleName(), MIN_LENGTH, "1")); rules.add(getRuleConfig(UpperCaseValidator.class.getSimpleName(), MIN_LENGTH, "1")); rules.add(getRuleConfig(LowerCaseValidator.class.getSimpleName(), MIN_LENGTH, "1"));