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

Introduce config to disable account activation confirmation email notification #650

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -571,6 +571,8 @@ public static class ConnectorConfig {
".DisableRandomValueForCredentials";
public static final String EMAIL_ACCOUNT_LOCK_ON_CREATION = "EmailVerification.LockOnCreation";
public static final String EMAIL_VERIFICATION_NOTIFICATION_INTERNALLY_MANAGE = "EmailVerification.Notification.InternallyManage";
public static final String EMAIL_VERIFICATION_NOTIFICATION_ACCOUNT_ACTIVATION = "EmailVerification.AskPassword" +
".AccountActivation";

public static final String TENANT_ADMIN_ASK_PASSWORD_EXPIRY_TIME = "TenantRegistrationVerification." +
"AskPassword.ExpiryTime";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public Map<String, String> getPropertyNameMapping() {
"Enable account lock on creation");
nameMapping.put(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_NOTIFICATION_INTERNALLY_MANAGE,
"Manage notifications sending internally");
nameMapping.put(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_NOTIFICATION_ACCOUNT_ACTIVATION,
"Send account activation email");
nameMapping.put(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_EXPIRY_TIME,
"Email verification code expiry time");
nameMapping.put(IdentityRecoveryConstants.ConnectorConfig.ASK_PASSWORD_EXPIRY_TIME,
Expand All @@ -110,6 +112,8 @@ public Map<String, String> getPropertyDescriptionMapping() {
"The user account will be locked during user creation.");
descriptionMapping.put(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_NOTIFICATION_INTERNALLY_MANAGE,
"Disable if the client application handles notification sending.");
descriptionMapping.put(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_NOTIFICATION_ACCOUNT_ACTIVATION,
"Disable if account activation confirmation email is not required.");
descriptionMapping.put(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_EXPIRY_TIME,
"Set the time span that the verification e-mail would be valid, in minutes. (For infinite validity " +
"period, set -1)");
Expand All @@ -130,6 +134,7 @@ public String[] getPropertyNames() {
properties.add(IdentityRecoveryConstants.ConnectorConfig.ENABLE_EMAIL_VERIFICATION);
properties.add(IdentityRecoveryConstants.ConnectorConfig.EMAIL_ACCOUNT_LOCK_ON_CREATION);
properties.add(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_NOTIFICATION_INTERNALLY_MANAGE);
properties.add(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_NOTIFICATION_ACCOUNT_ACTIVATION);
properties.add(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_EXPIRY_TIME);
properties.add(IdentityRecoveryConstants.ConnectorConfig.ASK_PASSWORD_EXPIRY_TIME);
properties.add(IdentityRecoveryConstants.ConnectorConfig.ASK_PASSWORD_TEMP_PASSWORD_GENERATOR);
Expand All @@ -144,6 +149,7 @@ public Properties getDefaultPropertyValues(String tenantDomain) throws IdentityG
String enableEmailVerification = "false";
String enableEmailAccountLockOnCreation = "true";
String enableNotificationInternallyManage = "true";
String sentNotificationOnAccountActivation = "true";
String emailVerificationCodeExpiry = "1440";
String askPasswordCodeExpiry = "1440";
String askPasswordTempPassExtension = "org.wso2.carbon.user.mgt.common.DefaultPasswordGenerator";
Expand All @@ -160,6 +166,8 @@ public Properties getDefaultPropertyValues(String tenantDomain) throws IdentityG
IdentityRecoveryConstants.ConnectorConfig.EMAIL_ACCOUNT_LOCK_ON_CREATION);
String notificationInternallyManagedProperty = IdentityUtil.getProperty(
IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_NOTIFICATION_INTERNALLY_MANAGE);
String notificationOnAccountActivationProperty = IdentityUtil.getProperty(
IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_NOTIFICATION_ACCOUNT_ACTIVATION);

if (StringUtils.isNotEmpty(emailVerificationProperty)) {
enableEmailVerification = emailVerificationProperty;
Expand All @@ -170,6 +178,9 @@ public Properties getDefaultPropertyValues(String tenantDomain) throws IdentityG
if (StringUtils.isNotEmpty(notificationInternallyManagedProperty)) {
enableNotificationInternallyManage = notificationInternallyManagedProperty;
}
if (StringUtils.isNotEmpty(notificationOnAccountActivationProperty)) {
sentNotificationOnAccountActivation = notificationOnAccountActivationProperty;
}
if (StringUtils.isNotEmpty(emailVerificationCodeExpiryProperty)) {
emailVerificationCodeExpiry = emailVerificationCodeExpiryProperty;
}
Expand All @@ -191,6 +202,8 @@ public Properties getDefaultPropertyValues(String tenantDomain) throws IdentityG
enableEmailAccountLockOnCreation);
defaultProperties.put(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_NOTIFICATION_INTERNALLY_MANAGE,
enableNotificationInternallyManage);
defaultProperties.put(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_NOTIFICATION_ACCOUNT_ACTIVATION,
sentNotificationOnAccountActivation);
defaultProperties.put(IdentityRecoveryConstants.ConnectorConfig.ASK_PASSWORD_TEMP_PASSWORD_GENERATOR,
askPasswordTempPassExtension);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@ public User updateUserPassword(String code, String password, Property[] properti
boolean isNotificationSendWhenSuccess = Boolean.parseBoolean(Utils.getRecoveryConfigs(
IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_SEND_RECOVERY_NOTIFICATION_SUCCESS,
userRecoveryData.getUser().getTenantDomain()));
boolean isNotificationSendOnAccountActivation = Boolean.parseBoolean(Utils.getRecoveryConfigs(
IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_NOTIFICATION_ACCOUNT_ACTIVATION,
userRecoveryData.getUser().getTenantDomain()));
String domainQualifiedName = IdentityUtil.addDomainToName(userRecoveryData.getUser().getUserName(),
userRecoveryData.getUser().getUserStoreDomain());

Expand All @@ -564,7 +567,9 @@ public User updateUserPassword(String code, String password, Property[] properti
String emailTemplate = null;
if (isAskPasswordFlow(userRecoveryData) &&
isAskPasswordEmailTemplateTypeExists(userRecoveryData.getUser().getTenantDomain())) {
emailTemplate = IdentityRecoveryConstants.ACCOUNT_ACTIVATION_SUCCESS;
if (isNotificationSendOnAccountActivation) {
emailTemplate = IdentityRecoveryConstants.ACCOUNT_ACTIVATION_SUCCESS;
}
} else if (isNotificationSendWhenSuccess) {
emailTemplate = IdentityRecoveryConstants.NOTIFICATION_TYPE_PASSWORD_RESET_SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public void testGetPropertyNameMapping() {
"Enable account lock on creation");
nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_NOTIFICATION_INTERNALLY_MANAGE,
"Manage notifications sending internally");
nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_NOTIFICATION_ACCOUNT_ACTIVATION,
"Send account activation email");
nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_EXPIRY_TIME,
"Email verification code expiry time");
nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.ASK_PASSWORD_EXPIRY_TIME,
Expand All @@ -119,6 +121,9 @@ public void testGetPropertyDescriptionMapping() {
descriptionMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.
EMAIL_VERIFICATION_NOTIFICATION_INTERNALLY_MANAGE,
"Disable if the client application handles notification sending.");
descriptionMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.
EMAIL_VERIFICATION_NOTIFICATION_ACCOUNT_ACTIVATION,
"Disable if account activation confirmation email is not required.");
descriptionMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_EXPIRY_TIME,
"Set the time span that the verification e-mail would be valid, in minutes. (For infinite validity " +
"period, set -1)");
Expand All @@ -142,6 +147,7 @@ public void testGetPropertyNames() {
propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.ENABLE_EMAIL_VERIFICATION);
propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.EMAIL_ACCOUNT_LOCK_ON_CREATION);
propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_NOTIFICATION_INTERNALLY_MANAGE);
propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_NOTIFICATION_ACCOUNT_ACTIVATION);
propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_EXPIRY_TIME);
propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.ASK_PASSWORD_EXPIRY_TIME);
String[] propertiesArrayExpected = propertiesExpected.toArray(new String[0]);
Expand All @@ -159,6 +165,7 @@ public void testGetDefaultPropertyValues() throws IdentityGovernanceException {
String testEnableEmailVerification = "false";
String testEnableEmailAccountLockOnCreation = "true";
String testEnableNotificationInternallyManage = "true";
String testSentNotificationOnAccountActivation = "true";
String testEmailVerificationCodeExpiry = "1440";
String testAskPasswordCodeExpiry = "1440";
String testAskPasswordTempPassExtension = "org.wso2.carbon.user.mgt.common.DefaultPasswordGenerator";
Expand All @@ -174,6 +181,8 @@ public void testGetDefaultPropertyValues() throws IdentityGovernanceException {
testEnableEmailAccountLockOnCreation);
defaultPropertiesExpected.put(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_NOTIFICATION_INTERNALLY_MANAGE,
testEnableNotificationInternallyManage);
defaultPropertiesExpected.put(IdentityRecoveryConstants.ConnectorConfig.EMAIL_VERIFICATION_NOTIFICATION_ACCOUNT_ACTIVATION,
testSentNotificationOnAccountActivation);
defaultPropertiesExpected.put(IdentityRecoveryConstants.ConnectorConfig.ASK_PASSWORD_TEMP_PASSWORD_GENERATOR,
testAskPasswordTempPassExtension);
try {
Expand Down