Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address multiple users exist in different user stores when recovering username #906

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,25 @@ public static void validateEmailUsername(User user) throws IdentityRecoveryClien
*/
public static User buildUser(String username, String tenantDomain) {

String[] parts = username.split(",");
sadilchamishka marked this conversation as resolved.
Show resolved Hide resolved
User user = new User();
user.setUserName(UserCoreUtil.removeDomainFromName(username));
user.setTenantDomain(tenantDomain);
user.setUserStoreDomain(IdentityUtil.extractDomainFromName(username));

for (String part : parts) {
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
Loading