Skip to content

Refactor the username recovery related implementations. #6663

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

Merged
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 @@ -86,7 +86,7 @@ public void setApiClient(ApiClient apiClient) {
/**
* Initiate recovering the forgotten username.
*
* @param recoveryInitRequest Username recovery initiating request. (required)
* @param recoveryInitRequest Username recovery initiating request (required).
* @param tenantDomain Tenant Domain which user belongs. Default "carbon.super" (optional)
* @param headers If reCaptcha respond is found, embedded in request header. (optional)
* @return Account recovery options response object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6217,8 +6217,12 @@ private void performConfigCorrectionForUsernameRecoveryConfigs(Connection dbConn
List<IdentityProviderProperty> idpProperties)
throws SQLException {

// Enable all recovery options when Recovery.Notification.Username.Enable value is set as enabled.
// This keeps functionality consistent with previous API versions for migrating customers.
/*
Enable all recovery options when Recovery.Notification.Username.Enable value is true and
OnDemandConfig.OnInitialUse.EnableSMSUsernameRecoveryIfConnectorEnabled config is enabled in the toml.
This keeps functionality consistent with previous API versions for migrating customers.
*/

idpProperties.stream().filter(
idp -> IdPManagementConstants.
EMAIL_USERNAME_RECOVERY_PROPERTY.equals(idp.getName())).findFirst()
Expand All @@ -6228,7 +6232,7 @@ private void performConfigCorrectionForUsernameRecoveryConfigs(Connection dbConn
IdentityProviderProperty identityProviderProperty = new IdentityProviderProperty();
identityProviderProperty.setName(
IdPManagementConstants.EMAIL_USERNAME_RECOVERY_PROPERTY);
identityProviderProperty.setValue("true");
identityProviderProperty.setValue(String.valueOf(true));
idpProperties.add(identityProviderProperty);
});
if (Boolean.parseBoolean(IdentityUtil.getProperty(ENABLE_SMS_USERNAME_RECOVERY_IF_CONNECTOR_ENABLED))) {
Expand All @@ -6241,7 +6245,7 @@ private void performConfigCorrectionForUsernameRecoveryConfigs(Connection dbConn
IdentityProviderProperty identityProviderProperty = new IdentityProviderProperty();
identityProviderProperty.setName(
IdPManagementConstants.SMS_USERNAME_RECOVERY_PROPERTY);
identityProviderProperty.setValue("true");
identityProviderProperty.setValue(String.valueOf(true));
idpProperties.add(identityProviderProperty);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,11 @@ public static void validatePasswordRecoveryWithCurrentAndPreviousConfigs(Map<Str
}
}


/**
* This method is used to validate the username recovery property values.
* This method is used to validate the username recovery related property values.
*
* @param configurationDetails Configuration updates for governance configuration.
* @param configurationDetails Configuration updates for governance configuration
* @throws IdentityProviderManagementClientException if configurations contain invalid configurations.
*/
public static void validateUsernameRecoveryPropertyValues(Map<String, String> configurationDetails)
throws IdentityProviderManagementClientException {
Expand All @@ -404,11 +404,12 @@ public static void validateUsernameRecoveryPropertyValues(Map<String, String> co
boolean usernameRecoverySmsProperty = Boolean.parseBoolean(usernameRecoverySmsProp);

if (usernameRecoveryProperty &&
StringUtils.isNotBlank(usernameRecoveryEmailProp) && !usernameRecoveryEmailProperty &&
StringUtils.isNotBlank(usernameRecoverySmsProp) && !usernameRecoverySmsProperty) {
// Disabling all recovery options when recovery connector is enabled is not allowed.
// WARNING : Be mindful about compatibility of earlier recovery api versions when changing
// this behaviour.
!usernameRecoveryEmailProperty && StringUtils.isNotBlank(usernameRecoveryEmailProp) &&
!usernameRecoverySmsProperty && StringUtils.isNotBlank(usernameRecoverySmsProp)) {
/*
Disabling all recovery options when recovery connector is enabled is not allowed.
WARNING : Be mindful about compatibility of earlier recovery api versions when changing this behaviour.
*/
throw IdPManagementUtil
.handleClientException(
IdPManagementConstants.ErrorMessage.ERROR_CODE_INVALID_CONNECTOR_CONFIGURATION,
Expand All @@ -417,9 +418,11 @@ public static void validateUsernameRecoveryPropertyValues(Map<String, String> co
}
if (StringUtils.isNotBlank(usernameRecoveryProp) && !usernameRecoveryProperty &&
(usernameRecoveryEmailProperty || usernameRecoverySmsProperty)) {
// Enabling any recovery options when connector is disabled is not allowed.
// WARNING : Be mindful about compatibility of earlier recovery api versions when changing
// this behaviour.
/*
Enabling any recovery options when connector is disabled is not allowed.
WARNING : Be mindful about compatibility of earlier recovery api versions when changing this behaviour.
*/

throw IdPManagementUtil
.handleClientException(
IdPManagementConstants.ErrorMessage.ERROR_CODE_INVALID_CONNECTOR_CONFIGURATION,
Expand Down