Skip to content

Commit

Permalink
Merge pull request #741 from Thumimku/disable-password-policy-validation
Browse files Browse the repository at this point in the history
Disable password policy validation handler by default
  • Loading branch information
Thumimku authored Sep 15, 2023
2 parents fdb9a1e + a44fb31 commit 4989d86
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ public Map<String, String> getPropertyDescriptionMapping() {
public void init(InitConfig configuration) throws IdentityRuntimeException {

super.init(configuration);
IdentityPasswordPolicyServiceDataHolder.getInstance().getBundleContext().registerService
(IdentityConnectorConfig.class.getName(), this, null);
}

public String[] getPropertyNames() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,8 +46,16 @@ protected void activate(ComponentContext context) {
}
BundleContext bundleContext = context.getBundleContext();
IdentityPasswordPolicyServiceDataHolder.getInstance().setBundleContext(bundleContext);
PasswordPolicyValidationHandler handler = new PasswordPolicyValidationHandler();
context.getBundleContext().registerService(AbstractEventHandler.class.getName(), handler, null);
if (IdentityPasswordPolicyServiceDataHolder.getInstance().isPasswordPolicyHandlerEnabled()) {

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.");
}
}
} catch (Exception e) {
log.error("Error while activating password policy component.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;
}
Expand Down

0 comments on commit 4989d86

Please sign in to comment.