Skip to content

Commit

Permalink
Merge pull request #777 from mpmadhavig/fix-change-emailotp-config-to…
Browse files Browse the repository at this point in the history
…-is-alphanumeric

Convert Property UseNumericChars to UseAlphanumericChars
  • Loading branch information
mpmadhavig authored Dec 4, 2023
2 parents 3080948 + 6388271 commit d078c37
Showing 1 changed file with 62 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.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,68 @@ public ConnectorConfig getConnectorWithConfigs(String tenantDomain,

for (ConnectorConfig connectorConfig : connectorListWithConfigs) {
if (connectorConfig.getName().equals(connectorName)) {
// Should remove this logic eventually.
if (isEmailOTPConnectorWithNewConfig(connectorName, connectorConfig)) {
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) {

// Verify the order of the connector properties hasn't changed.
if (EMAIL_OTP_USE_ALPHANUMERIC_CHARS.equals(connectorConfig.getProperties()[3].getName()) &&
EMAIL_OTP_USE_NUMERIC_CHARS.equals(connectorConfig.getProperties()[4].getName())) {
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.debug("The order of the connector properties has changed for the connector: " + connectorName);
}
}

/**
* This method is used to check whether the connector is email OTP connector or not.
*
* @param connectorName Name of the connector.
* @param connectorConfig Connector configuration.
*
* @return True if the connector is email OTP connector and have both old and new email OTP type related configs.
*/
private boolean isEmailOTPConnectorWithNewConfig(String connectorName, ConnectorConfig connectorConfig) {

/*
If the new config is also added, the length of the properties will be 5 with both old
and new OTP type properties. Here the purpose of adding 'at least check' is to allow
developers to safely add new configs.
*/
return EMAIL_OTP_AUTHENTICATOR.equals(connectorName) && connectorConfig.getProperties().length >= 5;
}
}

0 comments on commit d078c37

Please sign in to comment.