From 9b57202a06e49ccdb603890eff6c9e0dec064d52 Mon Sep 17 00:00:00 2001 From: KaveeshaPiumini Date: Mon, 18 Nov 2024 11:34:02 +0530 Subject: [PATCH] Return error code for a password policy violation error --- .../policy/handler/PasswordPolicyValidationHandler.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/handler/PasswordPolicyValidationHandler.java b/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/handler/PasswordPolicyValidationHandler.java index f31fefdd28..ce096fb5eb 100644 --- a/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/handler/PasswordPolicyValidationHandler.java +++ b/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/handler/PasswordPolicyValidationHandler.java @@ -21,6 +21,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.application.common.model.Property; +import org.wso2.carbon.identity.base.IdentityException; import org.wso2.carbon.identity.base.IdentityRuntimeException; import org.wso2.carbon.identity.core.handler.InitConfig; import org.wso2.carbon.identity.event.IdentityEventConstants; @@ -29,6 +30,7 @@ import org.wso2.carbon.identity.event.handler.AbstractEventHandler; import org.wso2.carbon.identity.governance.IdentityGovernanceException; import org.wso2.carbon.identity.governance.common.IdentityConnectorConfig; +import org.wso2.carbon.identity.mgt.constants.PasswordPolicyStatusCodes; import org.wso2.carbon.identity.mgt.policy.PolicyRegistry; import org.wso2.carbon.identity.mgt.policy.PolicyViolationException; import org.wso2.carbon.identity.mgt.policy.password.DefaultPasswordLengthPolicy; @@ -165,6 +167,10 @@ public void handleEvent(Event event) throws IdentityEventException { try { policyRegistry.enforcePasswordPolicies(credentials.toString(), userName); } catch (PolicyViolationException e) { + if (PasswordPolicyStatusCodes.ERROR_CODE_PASSWORD_POLICY_VIOLATION + .equals(e.getErrorCode())) { + throw IdentityException.error(IdentityEventException.class, e.getErrorCode(), e.getMessage(), e); + } throw Utils.handleEventException( PasswordPolicyConstants.ErrorMessages.ERROR_CODE_VALIDATING_PASSWORD_POLICY, e.getMessage(), e); }