From 3a07029cbbd894f9c915de24d11747963f275ef7 Mon Sep 17 00:00:00 2001 From: dhaura Date: Fri, 15 Dec 2023 11:15:08 +0530 Subject: [PATCH 1/2] Fix multi attribute username resolving issue for resend code --- .../impl/ResendCodeApiServiceImpl.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.user.governance/src/main/java/org/wso2/carbon/identity/user/endpoint/impl/ResendCodeApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.governance/src/main/java/org/wso2/carbon/identity/user/endpoint/impl/ResendCodeApiServiceImpl.java index 98f91e765b..d8cbb7fd11 100644 --- a/components/org.wso2.carbon.identity.api.user.governance/src/main/java/org/wso2/carbon/identity/user/endpoint/impl/ResendCodeApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.governance/src/main/java/org/wso2/carbon/identity/user/endpoint/impl/ResendCodeApiServiceImpl.java @@ -1,18 +1,19 @@ /* + * Copyright (c) 2016, WSO2 LLC. (http://www.wso2.com). * - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.identity.user.endpoint.impl; @@ -35,8 +36,8 @@ import org.wso2.carbon.identity.user.endpoint.ResendCodeApiService; import org.wso2.carbon.identity.user.endpoint.dto.ErrorDTO; import org.wso2.carbon.identity.user.endpoint.dto.PropertyDTO; -import org.wso2.carbon.identity.user.endpoint.util.Utils; import org.wso2.carbon.identity.user.endpoint.dto.ResendCodeRequestDTO; +import org.wso2.carbon.identity.user.endpoint.util.Utils; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import java.util.List; @@ -44,6 +45,9 @@ import java.util.stream.Collectors; import javax.ws.rs.core.Response; +/** + * This class contains the implementation of Resend Code API Service. + */ public class ResendCodeApiServiceImpl extends ResendCodeApiService { private static final Log LOG = LogFactory.getLog(ResendCodeApiServiceImpl.class); private static final String RECOVERY_SCENARIO_KEY = "RecoveryScenario"; @@ -64,7 +68,7 @@ public Response resendCodePost(ResendCodeRequestDTO resendCodeRequestDTO) { ResolvedUserResult resolvedUserResult = FrameworkUtils.processMultiAttributeLoginIdentification( resendCodeRequestDTO.getUser().getUsername(), resendCodeRequestDTO.getUser().getTenantDomain()); if (ResolvedUserResult.UserResolvedStatus.SUCCESS.equals(resolvedUserResult.getResolvedStatus())) { - resendCodeRequestDTO.getUser().setUsername(resolvedUserResult.getUser().getUsername()); + resendCodeRequestDTO.getUser().setUsername(resolvedUserResult.getUser().getPreferredUsername()); } NotificationResponseBean notificationResponseBean = null; From babaa1372d346eaf366cd12f2e06b07c749758d2 Mon Sep 17 00:00:00 2001 From: dhaura Date: Tue, 19 Dec 2023 10:06:29 +0530 Subject: [PATCH 2/2] Instead of preferredUsername, remove user store domain from username --- .../identity/user/endpoint/impl/ResendCodeApiServiceImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/org.wso2.carbon.identity.api.user.governance/src/main/java/org/wso2/carbon/identity/user/endpoint/impl/ResendCodeApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.governance/src/main/java/org/wso2/carbon/identity/user/endpoint/impl/ResendCodeApiServiceImpl.java index d8cbb7fd11..f4c1efb666 100644 --- a/components/org.wso2.carbon.identity.api.user.governance/src/main/java/org/wso2/carbon/identity/user/endpoint/impl/ResendCodeApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.governance/src/main/java/org/wso2/carbon/identity/user/endpoint/impl/ResendCodeApiServiceImpl.java @@ -38,6 +38,7 @@ import org.wso2.carbon.identity.user.endpoint.dto.PropertyDTO; import org.wso2.carbon.identity.user.endpoint.dto.ResendCodeRequestDTO; import org.wso2.carbon.identity.user.endpoint.util.Utils; +import org.wso2.carbon.user.core.util.UserCoreUtil; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import java.util.List; @@ -68,7 +69,8 @@ public Response resendCodePost(ResendCodeRequestDTO resendCodeRequestDTO) { ResolvedUserResult resolvedUserResult = FrameworkUtils.processMultiAttributeLoginIdentification( resendCodeRequestDTO.getUser().getUsername(), resendCodeRequestDTO.getUser().getTenantDomain()); if (ResolvedUserResult.UserResolvedStatus.SUCCESS.equals(resolvedUserResult.getResolvedStatus())) { - resendCodeRequestDTO.getUser().setUsername(resolvedUserResult.getUser().getPreferredUsername()); + resendCodeRequestDTO.getUser().setUsername( + UserCoreUtil.removeDomainFromName(resolvedUserResult.getUser().getUsername())); } NotificationResponseBean notificationResponseBean = null;