Skip to content

Commit

Permalink
return optional from buildPasswordRecoveryInitResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
asha15 committed Nov 24, 2023
1 parent 8e9e7e8 commit eb9547e
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public Response initiatePasswordRecovery(InitRequest initRequest) {

boolean isNotificationBasedRecoveryEnabled = isNotificationBasedRecoveryEnabled(tenantDomain);
boolean isQuestionBasedRecoveryAllowedForUser = isQuestionBasedRecoveryEnabled(tenantDomain);
RecoveryInformationDTO recoveryInformationDTO = null;
ArrayList<AccountRecoveryType> accountRecoveryTypes = new ArrayList<>();
List<Object> passwordRecoveryManagerList = PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiServices(PasswordRecoveryManager.class, null);
Expand All @@ -94,10 +93,12 @@ public Response initiatePasswordRecovery(InitRequest initRequest) {
}

for (Object passwordRecoveryManager : passwordRecoveryManagerList) {
recoveryInformationDTO = ((PasswordRecoveryManager) passwordRecoveryManager).initiate(userClaims,
tenantDomain, RecoveryUtil.buildPropertiesMap(initRequest.getProperties()));
Optional.ofNullable(buildPasswordRecoveryInitResponse(tenantDomain, recoveryInformationDTO))
.ifPresent(accountRecoveryTypes::add);
RecoveryInformationDTO recoveryInformationDTO = ((PasswordRecoveryManager) passwordRecoveryManager)
.initiate(userClaims, tenantDomain,
RecoveryUtil.buildPropertiesMap(initRequest.getProperties()));
Optional<AccountRecoveryType> recoveryType =
buildPasswordRecoveryInitResponse(tenantDomain, recoveryInformationDTO);
recoveryType.ifPresent(accountRecoveryTypes::add);
}

if (accountRecoveryTypes.isEmpty()) {
Expand Down Expand Up @@ -433,15 +434,14 @@ private RecoveryChannelInformation buildRecoveryChannelInformation(
* @param recoveryInformationDTO RecoveryInformationDTO which wraps the password recovery information
* @return AccountRecoveryType object with recovery options available for the user.
*/
private AccountRecoveryType buildPasswordRecoveryInitResponse(String tenantDomain,
RecoveryInformationDTO recoveryInformationDTO) {

AccountRecoveryType accountRecoveryType = null;
private Optional<AccountRecoveryType> buildPasswordRecoveryInitResponse(String tenantDomain,
RecoveryInformationDTO recoveryInformationDTO) {

if (recoveryInformationDTO == null) {
return accountRecoveryType;
return Optional.empty();
}

AccountRecoveryType accountRecoveryType = null;
boolean isNotificationBasedRecoveryEnabled = recoveryInformationDTO.isNotificationBasedRecoveryEnabled();
boolean isQuestionBasedRecoveryAllowedForUser = recoveryInformationDTO.isQuestionBasedRecoveryAllowedForUser();

Expand Down Expand Up @@ -471,7 +471,7 @@ private AccountRecoveryType buildPasswordRecoveryInitResponse(String tenantDomai
accountRecoveryType = buildAccountRecoveryType(
Constants.RECOVER_WITH_CHALLENGE_QUESTIONS, null, apiCallsArrayList);
}
return accountRecoveryType;
return Optional.ofNullable(accountRecoveryType);
}

/*
Expand Down

0 comments on commit eb9547e

Please sign in to comment.