Skip to content

Commit

Permalink
Remove migrated config and write config to both old and new property.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpmadhavig committed Oct 26, 2023
1 parent 525b836 commit 1b87991
Showing 1 changed file with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> configurationDetails)
throws IdentityGovernanceException {
Expand All @@ -52,17 +55,13 @@ public void updateConfiguration(String tenantDomain, Map<String, String> configu

IdentityProviderProperty[] identityMgtProperties = residentIdp.getIdpProperties();
List<IdentityProviderProperty> 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());
}
Expand Down Expand Up @@ -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<String, String> 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.
*
Expand All @@ -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.");
}
}

}

0 comments on commit 1b87991

Please sign in to comment.