Skip to content

Commit

Permalink
Add logic to handle the username recovery config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Malith-19 committed Oct 31, 2024
1 parent a70cfe3 commit d48b715
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ public class IdentityGovernanceServiceImpl implements IdentityGovernanceService
private static final String EMAIL_LINK_PASSWORD_RECOVERY_PROPERTY
= "Recovery.Notification.Password.emailLink.Enable";
private static final String SMS_OTP_PASSWORD_RECOVERY_PROPERTY = "Recovery.Notification.Password.smsOtp.Enable";
private static final String USERNAME_RECOVERY_ENABLE = "Recovery.Notification.Username.Enable";
private static final String USERNAME_RECOVERY_EMAIL_ENABLE = "Recovery.Notification.Username.Email.Enable";
private static final String USERNAME_RECOVERY_SMS_ENABLE = "Recovery.Notification.Username.SMS.Enable";
private static final String FALSE_STRING = "false";
private static final String TRUE_STRING = "true";

public void updateConfiguration(String tenantDomain, Map<String, String> configurationDetails)
throws IdentityGovernanceException {
Expand All @@ -70,6 +74,7 @@ public void updateConfiguration(String tenantDomain, Map<String, String> configu
updateEmailOTPNumericPropertyValue(configurationDetails);
IdPManagementUtil.validatePasswordRecoveryPropertyValues(configurationDetails);
updatePasswordRecoveryPropertyValues(configurationDetails, identityMgtProperties);
updateUsernameRecoveryPropertyValues(configurationDetails);

Check warning on line 77 in components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/IdentityGovernanceServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/IdentityGovernanceServiceImpl.java#L77

Added line #L77 was not covered by tests
for (IdentityProviderProperty identityMgtProperty : identityMgtProperties) {
IdentityProviderProperty prop = new IdentityProviderProperty();
String key = identityMgtProperty.getName();
Expand Down Expand Up @@ -407,4 +412,32 @@ private void updatePasswordRecoveryPropertyValues(Map<String, String> configurat
}
}
}

/**
* This method updates the username recovery property values based on the new configurations.
*
* @param configurationDetails Updating configuration details of the resident identity provider.
*/
private void updateUsernameRecoveryPropertyValues(Map<String, String> configurationDetails) {

if (configurationDetails.containsKey(USERNAME_RECOVERY_ENABLE) ||
configurationDetails.containsKey(USERNAME_RECOVERY_EMAIL_ENABLE) ||
configurationDetails.containsKey(USERNAME_RECOVERY_SMS_ENABLE)) {
boolean usernameRecoveryProperty = Boolean.parseBoolean(configurationDetails.get(USERNAME_RECOVERY_ENABLE));
boolean usernameRecoveryEmailProperty = Boolean.parseBoolean(
configurationDetails.get(USERNAME_RECOVERY_EMAIL_ENABLE));
boolean usernameRecoverySmsProperty = Boolean.parseBoolean(
configurationDetails.get(USERNAME_RECOVERY_SMS_ENABLE));

Check warning on line 430 in components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/IdentityGovernanceServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/IdentityGovernanceServiceImpl.java#L426-L430

Added lines #L426 - L430 were not covered by tests

// If user trying to update only username recovery config as in previous versions, automatically it will
// enable the email channel to maintain the backward compatibility.
if (usernameRecoveryProperty && !(usernameRecoverySmsProperty || usernameRecoveryEmailProperty)) {
configurationDetails.put(USERNAME_RECOVERY_EMAIL_ENABLE, TRUE_STRING);

Check warning on line 435 in components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/IdentityGovernanceServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/IdentityGovernanceServiceImpl.java#L435

Added line #L435 was not covered by tests
} else if (usernameRecoverySmsProperty || usernameRecoveryEmailProperty) {
configurationDetails.put(USERNAME_RECOVERY_ENABLE, TRUE_STRING);

Check warning on line 437 in components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/IdentityGovernanceServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/IdentityGovernanceServiceImpl.java#L437

Added line #L437 was not covered by tests
} else {
configurationDetails.put(USERNAME_RECOVERY_ENABLE, FALSE_STRING);

Check warning on line 439 in components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/IdentityGovernanceServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/IdentityGovernanceServiceImpl.java#L439

Added line #L439 was not covered by tests
}
}
}

Check warning on line 442 in components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/IdentityGovernanceServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

components/org.wso2.carbon.identity.governance/src/main/java/org/wso2/carbon/identity/governance/IdentityGovernanceServiceImpl.java#L442

Added line #L442 was not covered by tests
}

0 comments on commit d48b715

Please sign in to comment.