From 18b1658747520cb400f6dd084eee58ba31534a73 Mon Sep 17 00:00:00 2001 From: Thumimku Date: Fri, 4 Aug 2023 13:30:45 +0530 Subject: [PATCH 1/2] disable password policy validation handler --- .../constants/PasswordPolicyConstants.java | 1 + .../IdentityPasswordPolicyServiceComponent.java | 14 ++++++++++---- .../IdentityPasswordPolicyServiceDataHolder.java | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/constants/PasswordPolicyConstants.java b/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/constants/PasswordPolicyConstants.java index 7bfbe740fc..25ce59e216 100644 --- a/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/constants/PasswordPolicyConstants.java +++ b/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/constants/PasswordPolicyConstants.java @@ -26,6 +26,7 @@ public class PasswordPolicyConstants { public static final String PW_POLICY_LENGTH_CLASS = "passwordPolicy.class.PasswordLengthPolicy"; public static final String PW_POLICY_NAME_CLASS = "passwordPolicy.class.PasswordNamePolicy"; public static final String PW_POLICY_PATTERN_CLASS = "passwordPolicy.class.PasswordPatternPolicy"; + public static final String PW_POLICY_HANDLER_ENABLED = "PasswordPolicy.PasswordPolicyValidationHandler.Enable"; public enum ErrorMessages { diff --git a/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/internal/IdentityPasswordPolicyServiceComponent.java b/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/internal/IdentityPasswordPolicyServiceComponent.java index abacfe7821..6edaba1956 100644 --- a/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/internal/IdentityPasswordPolicyServiceComponent.java +++ b/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/internal/IdentityPasswordPolicyServiceComponent.java @@ -43,10 +43,16 @@ protected void activate(ComponentContext context) { if (log.isDebugEnabled()) { log.debug("Password Policy Service component is enabled"); } - BundleContext bundleContext = context.getBundleContext(); - IdentityPasswordPolicyServiceDataHolder.getInstance().setBundleContext(bundleContext); - PasswordPolicyValidationHandler handler = new PasswordPolicyValidationHandler(); - context.getBundleContext().registerService(AbstractEventHandler.class.getName(), handler, null); + if (IdentityPasswordPolicyServiceDataHolder.getInstance().isPasswordPolicyHandlerEnabled()) { + BundleContext bundleContext = context.getBundleContext(); + IdentityPasswordPolicyServiceDataHolder.getInstance().setBundleContext(bundleContext); + PasswordPolicyValidationHandler handler = new PasswordPolicyValidationHandler(); + context.getBundleContext().registerService(AbstractEventHandler.class.getName(), handler, null); + } else { + if (log.isDebugEnabled()) { + log.debug("Password Policy Validation Handler is disabled."); + } + } } catch (Exception e) { log.error("Error while activating password policy component.", e); } diff --git a/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/internal/IdentityPasswordPolicyServiceDataHolder.java b/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/internal/IdentityPasswordPolicyServiceDataHolder.java index db9b22894a..79780c7cc0 100644 --- a/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/internal/IdentityPasswordPolicyServiceDataHolder.java +++ b/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/internal/IdentityPasswordPolicyServiceDataHolder.java @@ -16,8 +16,11 @@ package org.wso2.carbon.identity.password.policy.internal; +import org.apache.commons.lang.StringUtils; import org.osgi.framework.BundleContext; +import org.wso2.carbon.identity.core.util.IdentityUtil; import org.wso2.carbon.identity.governance.IdentityGovernanceService; +import org.wso2.carbon.identity.password.policy.constants.PasswordPolicyConstants; public class IdentityPasswordPolicyServiceDataHolder { @@ -33,6 +36,19 @@ public static IdentityPasswordPolicyServiceDataHolder getInstance() { return instance; } + public boolean isPasswordPolicyHandlerEnabled() { + + String passwordPolicyHandlerEnabled = + IdentityUtil.getProperty(PasswordPolicyConstants.PW_POLICY_HANDLER_ENABLED); + if (StringUtils.isBlank(passwordPolicyHandlerEnabled)) { + /* + This indicates config not in the identity.xml. In that case, we need to maintain default behaviour. + */ + return false; + } + return Boolean.parseBoolean(passwordPolicyHandlerEnabled); + } + public IdentityGovernanceService getIdentityGovernanceService() { return identityGovernanceService; } From a44fb3136e9d073d6e606d6a5abae3f6af280b39 Mon Sep 17 00:00:00 2001 From: Thumimku Date: Tue, 12 Sep 2023 10:50:14 +0530 Subject: [PATCH 2/2] move service registration to service component --- .../policy/handler/PasswordPolicyValidationHandler.java | 2 -- .../internal/IdentityPasswordPolicyServiceComponent.java | 7 +++++-- 2 files changed, 5 insertions(+), 4 deletions(-) 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 7a34f02f00..f31fefdd28 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 @@ -232,8 +232,6 @@ public Map getPropertyDescriptionMapping() { public void init(InitConfig configuration) throws IdentityRuntimeException { super.init(configuration); - IdentityPasswordPolicyServiceDataHolder.getInstance().getBundleContext().registerService - (IdentityConnectorConfig.class.getName(), this, null); } public String[] getPropertyNames() { diff --git a/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/internal/IdentityPasswordPolicyServiceComponent.java b/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/internal/IdentityPasswordPolicyServiceComponent.java index 6edaba1956..63fc3e21a8 100644 --- a/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/internal/IdentityPasswordPolicyServiceComponent.java +++ b/components/org.wso2.carbon.identity.password.policy/src/main/java/org/wso2/carbon/identity/password/policy/internal/IdentityPasswordPolicyServiceComponent.java @@ -21,6 +21,7 @@ import org.osgi.service.component.ComponentContext; import org.wso2.carbon.identity.event.handler.AbstractEventHandler; import org.wso2.carbon.identity.governance.IdentityGovernanceService; +import org.wso2.carbon.identity.governance.common.IdentityConnectorConfig; import org.wso2.carbon.identity.password.policy.handler.PasswordPolicyValidationHandler; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; @@ -43,11 +44,13 @@ protected void activate(ComponentContext context) { if (log.isDebugEnabled()) { log.debug("Password Policy Service component is enabled"); } + BundleContext bundleContext = context.getBundleContext(); + IdentityPasswordPolicyServiceDataHolder.getInstance().setBundleContext(bundleContext); if (IdentityPasswordPolicyServiceDataHolder.getInstance().isPasswordPolicyHandlerEnabled()) { - BundleContext bundleContext = context.getBundleContext(); - IdentityPasswordPolicyServiceDataHolder.getInstance().setBundleContext(bundleContext); + PasswordPolicyValidationHandler handler = new PasswordPolicyValidationHandler(); context.getBundleContext().registerService(AbstractEventHandler.class.getName(), handler, null); + context.getBundleContext().registerService(IdentityConnectorConfig.class.getName(), handler, null); } else { if (log.isDebugEnabled()) { log.debug("Password Policy Validation Handler is disabled.");