Skip to content

Commit

Permalink
Convert property UseNumeric to UseAlphaNumeric.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpmadhavig committed Oct 27, 2023
1 parent 1b7d428 commit 0addf11
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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 @@ -51,6 +54,7 @@ public void updateConfiguration(String tenantDomain, Map<String, String> configu

IdentityProviderProperty[] identityMgtProperties = residentIdp.getIdpProperties();
List<IdentityProviderProperty> newProperties = new ArrayList<>();
convertPropertyUseNumericToUseAlphaNumeric(configurationDetails);
for (IdentityProviderProperty identityMgtProperty : identityMgtProperties) {
IdentityProviderProperty prop = new IdentityProviderProperty();
String key = identityMgtProperty.getName();
Expand Down Expand Up @@ -233,10 +237,51 @@ public ConnectorConfig getConnectorWithConfigs(String tenantDomain,

for (ConnectorConfig connectorConfig : connectorListWithConfigs) {
if (connectorConfig.getName().equals(connectorName)) {
// Should remove this logic eventually.
convertPropertyUseNumericToUseAlphaNumeric(connectorName, connectorConfig);
return connectorConfig;
}
}
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 convertPropertyUseNumericToUseAlphaNumeric(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 convert the property value useNumericCharacters to useAlphanumericCharacters.
*
* @param connectorName Name of the connector.
* @param connectorConfig Connector configuration.
*/
private void convertPropertyUseNumericToUseAlphaNumeric(String connectorName, ConnectorConfig connectorConfig) {

// 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 0addf11

Please sign in to comment.