Skip to content

Commit

Permalink
add supportMultiEmailsAndMobileNumbers config as a governance config
Browse files Browse the repository at this point in the history
  • Loading branch information
lashinijay committed Jun 3, 2024
1 parent 5cc6909 commit 4c19b27
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,6 @@ public class IdentityRecoveryConstants {
public static final String ACCOUNT_STATUS_DISABLED = "password.recovery.failed.account.disabled";
public static final String IGNORE_IF_TEMPLATE_NOT_FOUND = "ignoreIfTemplateNotFound";

/*
This config enables the support to store multiple mobile numbers and email addresses per user.
*/
public static final String SUPPORT_MULTIPLE_EMAILS_AND_MOBILE_NUMBERS_PER_USER =
"SupportMultipleEmailsAndMobileNumberPerUser.Enabled";

private IdentityRecoveryConstants() {

}
Expand Down Expand Up @@ -693,6 +687,9 @@ public static class ConnectorConfig {
public static final String ENABLE_MOBILE_VERIFICATION_BY_PRIVILEGED_USER = "UserClaimUpdate.MobileNumber." +
"EnableVerificationByPrivilegedUser";
public static final String USE_VERIFY_CLAIM_ON_UPDATE = "UserClaimUpdate.UseVerifyClaim";
// This config enables the support to store multiple mobile numbers and email addresses per user.
public static final String SUPPORT_MULTI_EMAILS_AND_MOBILE_NUMBERS_PER_USER =
"UserClaimUpdate.SupportMultiEmailsAndMobileNumbers.Enable";
public static final String ASK_PASSWORD_EXPIRY_TIME = "EmailVerification.AskPassword.ExpiryTime";
public static final String ASK_PASSWORD_TEMP_PASSWORD_GENERATOR = "EmailVerification.AskPassword.PasswordGenerator";
public static final String ASK_PASSWORD_DISABLE_RANDOM_VALUE_FOR_CREDENTIALS = "EmailVerification.AskPassword" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class UserClaimUpdateConfigImpl implements IdentityConnectorConfig {
private static final String DEFAULT_MOBILE_NUM_VERIFICATION_ON_UPDATE_SMS_OTP_EXPIRY_TIME = "5";
private static final String DEFAULT_ENABLE_VALUE_FOR_MOBILE_NUMBER_VERIFICATION_ON_UPDATE = "false";
private static final String DEFAULT_MOBILE_NUM_VERIFICATION_BY_PRIVILEGED_USERS = "false";
private static final String DEFAULT_SUPPORT_MULTI_EMAILS_AND_MOBILE_NUMBERS = "true";
private static final String USER_CLAIM_UPDATE_ELEMENT = "UserClaimUpdate";
private static final String ENABLE_ELEMENT = "Enable";
private static final String SEND_OTP_IN_EMAIL_ELEMENT = "SendOTPInEmail";
Expand All @@ -71,6 +72,7 @@ public class UserClaimUpdateConfigImpl implements IdentityConnectorConfig {
private static final String VERIFICATION_ON_UPDATE_ELEMENT = "VerificationOnUpdate";
private static final String NOTIFICATION_ON_UPDATE_ELEMENT = "NotificationOnUpdate";
private static final String ENABLE_MOBILE_VERIFICATION_PRIVILEGED_USER = "EnableVerificationByPrivilegedUser";
private static final String SUPPORT_MULTI_EMAILS_AND_MOBILE_NUMBERS_ELEMENT = "SupportMultiEmailsAndMobileNumbers";
private static String enableEmailVerificationOnUpdateProperty = null;
private static String enableSendOTPInEmailProperty = null;
private static String useUppercaseCharactersInOTPProperty = null;
Expand All @@ -82,6 +84,7 @@ public class UserClaimUpdateConfigImpl implements IdentityConnectorConfig {
private static String enableMobileNumVerificationOnUpdateProperty = null;
private static String mobileNumVerificationOnUpdateCodeExpiryProperty = null;
private static String mobileNumVerificationByPrivilegedUsersProperty = null;
private static String supportMultiEmailsAndMobileNumbersProperty = null;

@Override
public String getName() {
Expand Down Expand Up @@ -139,6 +142,8 @@ public Map<String, String> getPropertyNameMapping() {
"Enable mobile number verification by privileged users");
nameMapping.put(IdentityRecoveryConstants.ConnectorConfig.MOBILE_NUM_VERIFICATION_ON_UPDATE_EXPIRY_TIME,
"Mobile number verification on update SMS OTP expiry time");
nameMapping.put(IdentityRecoveryConstants.ConnectorConfig.SUPPORT_MULTI_EMAILS_AND_MOBILE_NUMBERS_PER_USER,
"Support multiple emails and mobile numbers per user");
return nameMapping;
}

Expand Down Expand Up @@ -171,6 +176,8 @@ public Map<String, String> getPropertyDescriptionMapping() {
"Validity time of the mobile number confirmation OTP in minutes.");
descriptionMapping.put(IdentityRecoveryConstants.ConnectorConfig.ENABLE_MOBILE_VERIFICATION_BY_PRIVILEGED_USER,
"Allow privileged users to initiate mobile number verification on update.");
descriptionMapping.put(IdentityRecoveryConstants.ConnectorConfig.SUPPORT_MULTI_EMAILS_AND_MOBILE_NUMBERS_PER_USER,
"Allow users to add multiple email addresses and mobile numbers to their account.");
return descriptionMapping;
}

Expand All @@ -189,6 +196,7 @@ public String[] getPropertyNames() {
properties.add(IdentityRecoveryConstants.ConnectorConfig.ENABLE_MOBILE_NUM_VERIFICATION_ON_UPDATE);
properties.add(IdentityRecoveryConstants.ConnectorConfig.MOBILE_NUM_VERIFICATION_ON_UPDATE_EXPIRY_TIME);
properties.add(IdentityRecoveryConstants.ConnectorConfig.ENABLE_MOBILE_VERIFICATION_BY_PRIVILEGED_USER);
properties.add(IdentityRecoveryConstants.ConnectorConfig.SUPPORT_MULTI_EMAILS_AND_MOBILE_NUMBERS_PER_USER);
return properties.toArray(new String[0]);
}

Expand All @@ -206,6 +214,7 @@ public Properties getDefaultPropertyValues(String tenantDomain) {
String enableMobileNumVerificationOnUpdate = DEFAULT_ENABLE_VALUE_FOR_MOBILE_NUMBER_VERIFICATION_ON_UPDATE;
String mobileNumVerificationOnUpdateCodeExpiry = DEFAULT_MOBILE_NUM_VERIFICATION_ON_UPDATE_SMS_OTP_EXPIRY_TIME;
String mobileNumVerificationByPrivilegedUsers = DEFAULT_MOBILE_NUM_VERIFICATION_BY_PRIVILEGED_USERS;
String supportMultiEmailsAndMobileNumbers = DEFAULT_SUPPORT_MULTI_EMAILS_AND_MOBILE_NUMBERS;

loadConfigurations();

Expand Down Expand Up @@ -242,6 +251,9 @@ public Properties getDefaultPropertyValues(String tenantDomain) {
if (StringUtils.isNotBlank(mobileNumVerificationByPrivilegedUsersProperty)) {
mobileNumVerificationByPrivilegedUsers = mobileNumVerificationByPrivilegedUsersProperty;
}
if (StringUtils.isNotBlank(supportMultiEmailsAndMobileNumbersProperty)) {
supportMultiEmailsAndMobileNumbers = supportMultiEmailsAndMobileNumbersProperty;
}

Properties properties = new Properties();
properties.put(IdentityRecoveryConstants.ConnectorConfig.ENABLE_EMAIL_VERIFICATION_ON_UPDATE,
Expand All @@ -266,6 +278,8 @@ public Properties getDefaultPropertyValues(String tenantDomain) {
mobileNumVerificationOnUpdateCodeExpiry);
properties.put(IdentityRecoveryConstants.ConnectorConfig.ENABLE_MOBILE_VERIFICATION_BY_PRIVILEGED_USER,
mobileNumVerificationByPrivilegedUsers);
properties.put(IdentityRecoveryConstants.ConnectorConfig.SUPPORT_MULTI_EMAILS_AND_MOBILE_NUMBERS_PER_USER,
supportMultiEmailsAndMobileNumbers);
return properties;
}

Expand All @@ -292,13 +306,17 @@ private void loadConfigurations() {

// Read configuration values defined in identity.xml.
OMElement userClaimUpdate = IdentityConfigParser.getInstance().getConfigElement(USER_CLAIM_UPDATE_ELEMENT);
OMElement supportMultiEmailsAndMobileNumbers = null;
Iterator claims = null;
OMElement otpConfigs = null;
if (userClaimUpdate != null) {
claims = userClaimUpdate.getChildrenWithName(new QName(IdentityCoreConstants
.IDENTITY_DEFAULT_NAMESPACE, CLAIM_ELEMENT));
otpConfigs = userClaimUpdate.getFirstChildWithName(new QName
(IdentityCoreConstants.IDENTITY_DEFAULT_NAMESPACE, OTP_ELEMENT));
supportMultiEmailsAndMobileNumbers = userClaimUpdate.getFirstChildWithName(
new QName(IdentityCoreConstants.IDENTITY_DEFAULT_NAMESPACE,
SUPPORT_MULTI_EMAILS_AND_MOBILE_NUMBERS_ELEMENT));
}

if (claims != null) {
Expand Down Expand Up @@ -362,6 +380,10 @@ private void loadConfigurations() {
otpLengthProperty = otpConfigs.getFirstChildWithName(new QName
(IdentityCoreConstants.IDENTITY_DEFAULT_NAMESPACE, OTP_LENGTH_ELEMENT)).getText();
}
if (supportMultiEmailsAndMobileNumbers != null) {
supportMultiEmailsAndMobileNumbersProperty = supportMultiEmailsAndMobileNumbers.getFirstChildWithName(
new QName(IdentityCoreConstants.IDENTITY_DEFAULT_NAMESPACE, ENABLE_ELEMENT)).getText();
}
}

@Override
Expand Down Expand Up @@ -399,7 +421,9 @@ public Map<String, Property> getMetaData() {
meta.put(IdentityRecoveryConstants.ConnectorConfig.MOBILE_NUM_VERIFICATION_ON_UPDATE_EXPIRY_TIME,
getPropertyObject(IdentityMgtConstants.DataTypes.INTEGER.getValue()));

meta.put(IdentityRecoveryConstants.ConnectorConfig.SUPPORT_MULTI_EMAILS_AND_MOBILE_NUMBERS_PER_USER,
getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()));

return meta;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ public void handleEvent(Event event) throws IdentityEventException {
Map<String, String> claims = (Map<String, String>) eventProperties.get(IdentityEventConstants.EventProperty
.USER_CLAIMS);

boolean supportMultipleMobileNumbers = Boolean.parseBoolean(IdentityUtil.getProperty(IdentityRecoveryConstants
.SUPPORT_MULTIPLE_EMAILS_AND_MOBILE_NUMBERS_PER_USER));
boolean supportMultipleMobileNumbers = Utils.isMultiEmailsAndMobileNumbersPerUserEnabled(user.getTenantDomain());

boolean enable = isMobileVerificationOnUpdateEnabled(user.getTenantDomain());

Expand Down Expand Up @@ -302,8 +301,7 @@ private void preSetUserClaimOnMobileNumberUpdate(Map<String, String> claims, Use
Utils.unsetThreadLocalToSkipSendingSmsOtpVerificationOnUpdate();
}

boolean supportMultipleMobileNumbers = Boolean.parseBoolean(IdentityUtil.getProperty(IdentityRecoveryConstants
.SUPPORT_MULTIPLE_EMAILS_AND_MOBILE_NUMBERS_PER_USER));
boolean supportMultipleMobileNumbers = Utils.isMultiEmailsAndMobileNumbersPerUserEnabled(user.getTenantDomain());

String mobileNumber = null;
List<String> exisitingVerifiedNumbersList = Utils.getExistingClaimValue(userStoreManager, user,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ public void handleEvent(Event event) throws IdentityEventException {
Map<String, String> claims = (Map<String, String>) eventProperties.get(IdentityEventConstants.EventProperty
.USER_CLAIMS);

boolean supportMultipleEmails = Boolean.parseBoolean(IdentityUtil
.getProperty(IdentityRecoveryConstants.SUPPORT_MULTIPLE_EMAILS_AND_MOBILE_NUMBERS_PER_USER));
boolean supportMultipleEmails = Utils.isMultiEmailsAndMobileNumbersPerUserEnabled(user.getTenantDomain());

boolean enable = false;

Expand Down Expand Up @@ -547,8 +546,7 @@ private void preSetUserClaimsOnEmailUpdate(Map<String, String> claims, UserStore
return;
}

boolean supportMultipleEmails = Boolean.parseBoolean(IdentityUtil
.getProperty(IdentityRecoveryConstants.SUPPORT_MULTIPLE_EMAILS_AND_MOBILE_NUMBERS_PER_USER));
boolean supportMultipleEmails = Utils.isMultiEmailsAndMobileNumbersPerUserEnabled(user.getTenantDomain());

String emailAddress = null;
List<String> existingVerifiedEmailAddresses = Utils.getExistingClaimValue(userStoreManager, user,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,8 @@ private UserRecoveryData validateSelfRegistrationCode(String code, String verifi
HashMap<String, String> userClaims = getClaimsListToUpdate(user, verifiedChannelType,
externallyVerifiedClaim, recoveryData.getRecoveryScenario().toString());

boolean supportMultipleEmailsAndMobileNumbers = Boolean.parseBoolean(IdentityUtil
.getProperty(IdentityRecoveryConstants.SUPPORT_MULTIPLE_EMAILS_AND_MOBILE_NUMBERS_PER_USER));
boolean supportMultipleEmailsAndMobileNumbers = Utils.isMultiEmailsAndMobileNumbersPerUserEnabled(user
.getTenantDomain());

if (RecoverySteps.VERIFY_EMAIL.equals(recoveryData.getRecoveryStep())) {
String pendingEmailClaimValue = recoveryData.getRemainingSetIds();
Expand Down Expand Up @@ -953,8 +953,8 @@ public void confirmVerificationCodeMe(String code, Map<String, String> propertie
UserStoreManager userStoreManager = getUserStoreManager(user);
HashMap<String, String> userClaims = new HashMap<>();

boolean supportMultipleEmailsAndMobileNumbers = Boolean.parseBoolean(IdentityUtil
.getProperty(IdentityRecoveryConstants.SUPPORT_MULTIPLE_EMAILS_AND_MOBILE_NUMBERS_PER_USER));
boolean supportMultipleEmailsAndMobileNumbers = Utils.isMultiEmailsAndMobileNumbersPerUserEnabled(user
.getTenantDomain());

if (RecoverySteps.VERIFY_MOBILE_NUMBER.equals(recoveryData.getRecoveryStep())) {
String pendingMobileNumberClaimValue = recoveryData.getRemainingSetIds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,23 @@ public static boolean isUseVerifyClaimEnabled() {
(IdentityRecoveryConstants.ConnectorConfig.USE_VERIFY_CLAIM_ON_UPDATE));
}

/**
* Check whether the supporting multiple email addresses and mobile numbers per user is enabled.
*
* @return True if the config is set to true, false otherwise.
*/
public static boolean isMultiEmailsAndMobileNumbersPerUserEnabled(String tenantDomain) {

try {
return Boolean.parseBoolean(getConnectorConfig(IdentityRecoveryConstants.ConnectorConfig
.SUPPORT_MULTI_EMAILS_AND_MOBILE_NUMBERS_PER_USER, tenantDomain));
} catch (IdentityEventException e) {
log.error("Error while getting connector configurations support multi emails and mobile numbers per" +
" user.", e);
return true;
}
}

/**
* Trigger recovery event.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ public void testGetPropertyNameMapping() {
"Mobile number verification on update SMS OTP expiry time");
nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.ENABLE_MOBILE_VERIFICATION_BY_PRIVILEGED_USER,
"Enable mobile number verification by privileged users");
nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SUPPORT_MULTI_EMAILS_AND_MOBILE_NUMBERS_PER_USER,
"Support multiple emails and mobile numbers per user");
Map<String, String> nameMapping = userClaimUpdateConfig.getPropertyNameMapping();
assertEquals(nameMapping, nameMappingExpected, "Maps are not equal.");
}
Expand Down Expand Up @@ -171,6 +173,8 @@ public void testGetPropertyDescriptionMapping() {
"Validity time of the mobile number confirmation OTP in minutes.");
descriptionMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.ENABLE_MOBILE_VERIFICATION_BY_PRIVILEGED_USER,
"Allow privileged users to initiate mobile number verification on update.");
descriptionMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SUPPORT_MULTI_EMAILS_AND_MOBILE_NUMBERS_PER_USER,
"Allow users to add multiple email addresses and mobile numbers to their account.");
Map<String, String> descriptionMapping = userClaimUpdateConfig.getPropertyDescriptionMapping();
assertEquals(descriptionMapping, descriptionMappingExpected, "Maps are not equal.");
}
Expand All @@ -189,6 +193,7 @@ public void testGetPropertyNames() {
propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.ENABLE_NOTIFICATION_ON_EMAIL_UPDATE);
propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.ENABLE_MOBILE_NUM_VERIFICATION_ON_UPDATE);
propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.MOBILE_NUM_VERIFICATION_ON_UPDATE_EXPIRY_TIME);
propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.ENABLE_MOBILE_VERIFICATION_BY_PRIVILEGED_USER);
String[] propertiesArrayExpected = propertiesExpected.toArray(new String[0]);

String[] properties = userClaimUpdateConfig.getPropertyNames();
Expand Down Expand Up @@ -244,7 +249,8 @@ public void testGetDefaultProperties() throws IdentityGovernanceException {
EMAIL_VERIFICATION_ON_UPDATE_OTP_LENGTH, IdentityRecoveryConstants.ConnectorConfig
.EMAIL_VERIFICATION_ON_UPDATE_EXPIRY_TIME, IdentityRecoveryConstants.ConnectorConfig
.ENABLE_MOBILE_NUM_VERIFICATION_ON_UPDATE, IdentityRecoveryConstants.ConnectorConfig
.MOBILE_NUM_VERIFICATION_ON_UPDATE_EXPIRY_TIME,"testproperty"};
.MOBILE_NUM_VERIFICATION_ON_UPDATE_EXPIRY_TIME, IdentityRecoveryConstants.ConnectorConfig
.SUPPORT_MULTI_EMAILS_AND_MOBILE_NUMBERS_PER_USER, "testproperty"};

IdentityConfigParser mockConfigParser = mock(IdentityConfigParser.class);
mockedIdentityConfigParser.when(IdentityConfigParser::getInstance).thenReturn(mockConfigParser);
Expand Down

0 comments on commit 4c19b27

Please sign in to comment.