Skip to content

Commit

Permalink
Merge pull request #906 from sadilchamishka/fix-username-recovery-fai…
Browse files Browse the repository at this point in the history
…l-when-multiple-user-exists
  • Loading branch information
sadilchamishka authored Jan 16, 2025
2 parents 510e258 + 6c38590 commit 8084e02
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public RecoveryChannelInfoDTO retrieveUsersRecoveryInformationForUsername(Map<St
NotificationChannelDTO[] notificationChannelDTOS = null;

for (org.wso2.carbon.user.core.common.User resultedUser : resultedUserList) {
username = resultedUser.getUsername();
username = resultedUser.getDomainQualifiedUsername();
User user = Utils.buildUser(username, tenantDomain);

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright (c) 2020, WSO2 LLC. (http://www.wso2.org)
* Copyright (c) 2020-2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* 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
*
Expand All @@ -15,6 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.recovery.internal.service.impl.username;

import org.apache.commons.collections.MapUtils;
Expand Down Expand Up @@ -355,11 +356,23 @@ private void triggerNotification(User user, String notificationChannel, String e

String combinedUsernames = user.getUserName();
String[] usernames = combinedUsernames.split(",");
String[] userStoreDomains = null;
if (user.getUserStoreDomain() != null) {
userStoreDomains = user.getUserStoreDomain().split(",");
}

int userIndex = 0;
for (String username : usernames) {
HashMap<String, Object> properties = new HashMap<>();
properties.put(IdentityEventConstants.EventProperty.USER_NAME, username);
properties.put(IdentityEventConstants.EventProperty.TENANT_DOMAIN, user.getTenantDomain());
properties.put(IdentityEventConstants.EventProperty.USER_STORE_DOMAIN, user.getUserStoreDomain());

String userStoreDomain = user.getUserStoreDomain();
if (userStoreDomains != null && userStoreDomains.length > userIndex) {
userStoreDomain = userStoreDomains[userIndex];
}
userIndex++;
properties.put(IdentityEventConstants.EventProperty.USER_STORE_DOMAIN, userStoreDomain);
properties.put(IdentityEventConstants.EventProperty.NOTIFICATION_CHANNEL, notificationChannel);
if (metaProperties != null) {
for (String key : metaProperties.keySet()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2024, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2016-2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down Expand Up @@ -1066,10 +1066,27 @@ public static void validateEmailUsername(User user) throws IdentityRecoveryClien
*/
public static User buildUser(String username, String tenantDomain) {

/* The User Account Recovery process can identify multiple users that match the specified conditions.
In such cases, the usernames are represented as a comma-separated list. */
String[] usernameSegments = username.split(",");
User user = new User();
user.setUserName(UserCoreUtil.removeDomainFromName(username));
user.setTenantDomain(tenantDomain);
user.setUserStoreDomain(IdentityUtil.extractDomainFromName(username));

for (String part : usernameSegments) {
String domainFreeName = UserCoreUtil.removeDomainFromName(part);
if (user.getUserName() != null) {
user.setUserName(user.getUserName() + "," + domainFreeName);
} else {
user.setUserName(domainFreeName);
}

String userStoreDomain = IdentityUtil.extractDomainFromName(part);
if (user.getUserStoreDomain() != null) {
user.setUserStoreDomain(user.getUserStoreDomain() + "," + userStoreDomain);
} else {
user.setUserStoreDomain(userStoreDomain);
}
}
return user;
}

Expand Down

0 comments on commit 8084e02

Please sign in to comment.