Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Property UseNumericChars to UseAlphanumericChars #777

Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.wso2.carbon.identity.governance;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig;
Expand All @@ -41,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.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 +55,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 +238,62 @@ public ConnectorConfig getConnectorWithConfigs(String tenantDomain,

for (ConnectorConfig connectorConfig : connectorListWithConfigs) {
if (connectorConfig.getName().equals(connectorName)) {
// Should remove this logic eventually.
if (isEmailOTPConnector(connectorName)) {
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 (connectorConfig.getProperties()[3].getName().equals(EMAIL_OTP_USE_ALPHANUMERIC_CHARS) &&
connectorConfig.getProperties()[4].getName().equals(EMAIL_OTP_USE_NUMERIC_CHARS)) {
mpmadhavig marked this conversation as resolved.
Show resolved Hide resolved

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.
* @return True if the connector is email OTP connector.
*/
private boolean isEmailOTPConnector(String connectorName) {

return connectorName.equals(EMAIL_OTP_AUTHENTICATOR);
mpmadhavig marked this conversation as resolved.
Show resolved Hide resolved
}
}