From eb9547e01d4fa08a3a2cfab41c1c7b4b563372fd Mon Sep 17 00:00:00 2001 From: asha15 <165079T@uom.lk> Date: Fri, 24 Nov 2023 08:51:20 +0530 Subject: [PATCH] return optional from buildPasswordRecoveryInitResponse --- .../v1/impl/core/PasswordRecoveryService.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/core/PasswordRecoveryService.java b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/core/PasswordRecoveryService.java index 5e35f762d..54b3c5c2b 100644 --- a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/core/PasswordRecoveryService.java +++ b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/core/PasswordRecoveryService.java @@ -79,7 +79,6 @@ public Response initiatePasswordRecovery(InitRequest initRequest) { boolean isNotificationBasedRecoveryEnabled = isNotificationBasedRecoveryEnabled(tenantDomain); boolean isQuestionBasedRecoveryAllowedForUser = isQuestionBasedRecoveryEnabled(tenantDomain); - RecoveryInformationDTO recoveryInformationDTO = null; ArrayList accountRecoveryTypes = new ArrayList<>(); List passwordRecoveryManagerList = PrivilegedCarbonContext .getThreadLocalCarbonContext().getOSGiServices(PasswordRecoveryManager.class, null); @@ -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 recoveryType = + buildPasswordRecoveryInitResponse(tenantDomain, recoveryInformationDTO); + recoveryType.ifPresent(accountRecoveryTypes::add); } if (accountRecoveryTypes.isEmpty()) { @@ -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 buildPasswordRecoveryInitResponse(String tenantDomain, + RecoveryInformationDTO recoveryInformationDTO) { if (recoveryInformationDTO == null) { - return accountRecoveryType; + return Optional.empty(); } + AccountRecoveryType accountRecoveryType = null; boolean isNotificationBasedRecoveryEnabled = recoveryInformationDTO.isNotificationBasedRecoveryEnabled(); boolean isQuestionBasedRecoveryAllowedForUser = recoveryInformationDTO.isQuestionBasedRecoveryAllowedForUser(); @@ -471,7 +471,7 @@ private AccountRecoveryType buildPasswordRecoveryInitResponse(String tenantDomai accountRecoveryType = buildAccountRecoveryType( Constants.RECOVER_WITH_CHALLENGE_QUESTIONS, null, apiCallsArrayList); } - return accountRecoveryType; + return Optional.ofNullable(accountRecoveryType); } /*