Skip to content

Commit 346fcaf

Browse files
Merge pull request #6663 from Malith-19/refactor-username-recovery-implementation
Refactor the username recovery related implementations.
2 parents 0ca8227 + f279232 commit 346fcaf

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

components/identity-mgt/org.wso2.carbon.identity.mgt.endpoint.util/src/main/java/org/wso2/carbon/identity/mgt/endpoint/util/client/api/RecoveryApiV2.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void setApiClient(ApiClient apiClient) {
8686
/**
8787
* Initiate recovering the forgotten username.
8888
*
89-
* @param recoveryInitRequest Username recovery initiating request. (required)
89+
* @param recoveryInitRequest Username recovery initiating request (required).
9090
* @param tenantDomain Tenant Domain which user belongs. Default "carbon.super" (optional)
9191
* @param headers If reCaptcha respond is found, embedded in request header. (optional)
9292
* @return Account recovery options response object.

components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementDAO.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -6222,8 +6222,12 @@ private void performConfigCorrectionForUsernameRecoveryConfigs(Connection dbConn
62226222
List<IdentityProviderProperty> idpProperties)
62236223
throws SQLException {
62246224

6225-
// Enable all recovery options when Recovery.Notification.Username.Enable value is set as enabled.
6226-
// This keeps functionality consistent with previous API versions for migrating customers.
6225+
/*
6226+
Enable all recovery options when Recovery.Notification.Username.Enable value is true and
6227+
OnDemandConfig.OnInitialUse.EnableSMSUsernameRecoveryIfConnectorEnabled config is enabled in the toml.
6228+
This keeps functionality consistent with previous API versions for migrating customers.
6229+
*/
6230+
62276231
idpProperties.stream().filter(
62286232
idp -> IdPManagementConstants.
62296233
EMAIL_USERNAME_RECOVERY_PROPERTY.equals(idp.getName())).findFirst()
@@ -6233,7 +6237,7 @@ private void performConfigCorrectionForUsernameRecoveryConfigs(Connection dbConn
62336237
IdentityProviderProperty identityProviderProperty = new IdentityProviderProperty();
62346238
identityProviderProperty.setName(
62356239
IdPManagementConstants.EMAIL_USERNAME_RECOVERY_PROPERTY);
6236-
identityProviderProperty.setValue("true");
6240+
identityProviderProperty.setValue(String.valueOf(true));
62376241
idpProperties.add(identityProviderProperty);
62386242
});
62396243
if (Boolean.parseBoolean(IdentityUtil.getProperty(ENABLE_SMS_USERNAME_RECOVERY_IF_CONNECTOR_ENABLED))) {
@@ -6246,7 +6250,7 @@ private void performConfigCorrectionForUsernameRecoveryConfigs(Connection dbConn
62466250
IdentityProviderProperty identityProviderProperty = new IdentityProviderProperty();
62476251
identityProviderProperty.setName(
62486252
IdPManagementConstants.SMS_USERNAME_RECOVERY_PROPERTY);
6249-
identityProviderProperty.setValue("true");
6253+
identityProviderProperty.setValue(String.valueOf(true));
62506254
idpProperties.add(identityProviderProperty);
62516255
});
62526256
}

components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/util/IdPManagementUtil.java

+14-11
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,11 @@ public static void validatePasswordRecoveryWithCurrentAndPreviousConfigs(Map<Str
380380
}
381381
}
382382

383-
384383
/**
385-
* This method is used to validate the username recovery property values.
384+
* This method is used to validate the username recovery related property values.
386385
*
387-
* @param configurationDetails Configuration updates for governance configuration.
386+
* @param configurationDetails Configuration updates for governance configuration
387+
* @throws IdentityProviderManagementClientException if configurations contain invalid configurations.
388388
*/
389389
public static void validateUsernameRecoveryPropertyValues(Map<String, String> configurationDetails)
390390
throws IdentityProviderManagementClientException {
@@ -404,11 +404,12 @@ public static void validateUsernameRecoveryPropertyValues(Map<String, String> co
404404
boolean usernameRecoverySmsProperty = Boolean.parseBoolean(usernameRecoverySmsProp);
405405

406406
if (usernameRecoveryProperty &&
407-
StringUtils.isNotBlank(usernameRecoveryEmailProp) && !usernameRecoveryEmailProperty &&
408-
StringUtils.isNotBlank(usernameRecoverySmsProp) && !usernameRecoverySmsProperty) {
409-
// Disabling all recovery options when recovery connector is enabled is not allowed.
410-
// WARNING : Be mindful about compatibility of earlier recovery api versions when changing
411-
// this behaviour.
407+
!usernameRecoveryEmailProperty && StringUtils.isNotBlank(usernameRecoveryEmailProp) &&
408+
!usernameRecoverySmsProperty && StringUtils.isNotBlank(usernameRecoverySmsProp)) {
409+
/*
410+
Disabling all recovery options when recovery connector is enabled is not allowed.
411+
WARNING : Be mindful about compatibility of earlier recovery api versions when changing this behaviour.
412+
*/
412413
throw IdPManagementUtil
413414
.handleClientException(
414415
IdPManagementConstants.ErrorMessage.ERROR_CODE_INVALID_CONNECTOR_CONFIGURATION,
@@ -417,9 +418,11 @@ public static void validateUsernameRecoveryPropertyValues(Map<String, String> co
417418
}
418419
if (StringUtils.isNotBlank(usernameRecoveryProp) && !usernameRecoveryProperty &&
419420
(usernameRecoveryEmailProperty || usernameRecoverySmsProperty)) {
420-
// Enabling any recovery options when connector is disabled is not allowed.
421-
// WARNING : Be mindful about compatibility of earlier recovery api versions when changing
422-
// this behaviour.
421+
/*
422+
Enabling any recovery options when connector is disabled is not allowed.
423+
WARNING : Be mindful about compatibility of earlier recovery api versions when changing this behaviour.
424+
*/
425+
423426
throw IdPManagementUtil
424427
.handleClientException(
425428
IdPManagementConstants.ErrorMessage.ERROR_CODE_INVALID_CONNECTOR_CONFIGURATION,

0 commit comments

Comments
 (0)