diff --git a/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/IdentityGovernanceServiceImpl.java b/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/IdentityGovernanceServiceImpl.java index f6a4ae08a..239a2c5cb 100644 --- a/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/IdentityGovernanceServiceImpl.java +++ b/components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/IdentityGovernanceServiceImpl.java @@ -42,6 +42,9 @@ public class IdentityGovernanceServiceImpl implements IdentityGovernanceService { private static final Log log = LogFactory.getLog(IdentityGovernanceServiceImpl.class); + private static final String EMAIL_OTP_AUTHENTICATOR = "email-otp-authenticator"; + public static final String EMAIL_OTP_USE_ALPHANUMERIC_CHARS = "EmailOTP.OtpRegex.UseAlphanumericChars"; + public static final String EMAIL_OTP_USE_NUMERIC_CHARS = "EmailOTP.OtpRegex.UseNumericChars"; public void updateConfiguration(String tenantDomain, Map configurationDetails) throws IdentityGovernanceException { @@ -52,17 +55,13 @@ public void updateConfiguration(String tenantDomain, Map configu IdentityProviderProperty[] identityMgtProperties = residentIdp.getIdpProperties(); List newProperties = new ArrayList<>(); + migratePropertyUseNumericToUseAlphaNumeric(configurationDetails); for (IdentityProviderProperty identityMgtProperty : identityMgtProperties) { IdentityProviderProperty prop = new IdentityProviderProperty(); String key = identityMgtProperty.getName(); prop.setName(key); if (configurationDetails.containsKey(key)) { prop.setValue(configurationDetails.get(key)); - if (Objects.equals(key, "EmailOTP.OtpRegex.Migrated")) { - prop.setValue("true"); - } else { - prop.setValue(configurationDetails.get(key)); - } } else { prop.setValue(identityMgtProperty.getValue()); } @@ -247,6 +246,21 @@ public ConnectorConfig getConnectorWithConfigs(String tenantDomain, return null; } + /** + * This method is used to make sure property value useNumericCharacters and useAlphanumericCharacters both uses + * same user input. + * + * @param configurationDetails Configuration details of the email OTP connector. + */ + private void migratePropertyUseNumericToUseAlphaNumeric(Map configurationDetails) { + + if (configurationDetails.containsKey(EMAIL_OTP_USE_ALPHANUMERIC_CHARS) && + configurationDetails.containsKey(EMAIL_OTP_USE_NUMERIC_CHARS)) { + boolean useNumericChars = !Boolean.parseBoolean(configurationDetails.get(EMAIL_OTP_USE_ALPHANUMERIC_CHARS)); + configurationDetails.put(EMAIL_OTP_USE_NUMERIC_CHARS, String.valueOf(useNumericChars)); + } + } + /** * This method is used to migrate the property value useNumericCharacters to useAlphanumericCharacters. * @@ -255,18 +269,20 @@ public ConnectorConfig getConnectorWithConfigs(String tenantDomain, */ private void migratePropertyUseNumericToUseAlphaNumeric(String connectorName, ConnectorConfig connectorConfig) { - if (connectorName.equals("email-otp-authenticator")) { - if (connectorConfig.getProperties().length == 6) { - boolean isMigrated = Boolean.parseBoolean(connectorConfig.getProperties()[5].getValue()); - if (!isMigrated && connectorConfig.getProperties()[4].getValue() != null ) { - // Extract the value of the useNumericCharacters property. - boolean useAlphanumericChars = !Boolean.parseBoolean(connectorConfig.getProperties()[4].getValue()); - // Assign the value to the alphanumeric property. - connectorConfig.getProperties()[3].setValue(String.valueOf(useAlphanumericChars)); - connectorConfig.getProperties()[5].setValue(String.valueOf(true)); - } + // If any of the following conditions are false, it simply doesn't migrate the config. + if (connectorName.equals(EMAIL_OTP_AUTHENTICATOR) && + connectorConfig.getProperties()[3].getName().equals(EMAIL_OTP_USE_ALPHANUMERIC_CHARS) && + connectorConfig.getProperties()[4].getName().equals(EMAIL_OTP_USE_NUMERIC_CHARS)) { + + if (connectorConfig.getProperties()[4].getValue() != null) { + // Extract the value of the useNumericCharacters property. + boolean useAlphanumericChars = !Boolean.parseBoolean(connectorConfig.getProperties()[4].getValue()); + // Assign the value to the alphanumeric property. + connectorConfig.getProperties()[3].setValue(String.valueOf(useAlphanumericChars)); } + } else { + log.warn("Connector property migration skipped due to invalid email OTP authenticator property " + + "configuration."); } } - }