Skip to content

Commit

Permalink
Add primary domain to username if realm is passed as primary.
Browse files Browse the repository at this point in the history
  • Loading branch information
RushanNanayakkara committed Feb 2, 2024
1 parent 6e10a48 commit 3c5fcf1
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.wso2.carbon.identity.recovery.internal.IdentityRecoveryServiceDataHolder;
import org.wso2.carbon.identity.recovery.password.NotificationPasswordRecoveryManager;
import org.wso2.carbon.identity.recovery.util.Utils;
import org.wso2.carbon.user.core.UserCoreConstants;
import org.wso2.carbon.user.core.util.UserCoreUtil;

import javax.ws.rs.core.Response;
Expand Down Expand Up @@ -52,8 +53,17 @@ public Response recoverPasswordPost(RecoveryInitiatingRequestDTO recoveryInitiat
// If multi attribute login is enabled, resolve the user before sending recovery notification sending.
if (IdentityRecoveryServiceDataHolder.getInstance().getMultiAttributeLoginService()
.isEnabled(user.getTenantDomain())) {
String userDomainQualifiedUsername;
if (StringUtils.isNotBlank(user.getRealm())) {
String userDomainQualifiedUsername = UserCoreUtil.addDomainToName(user.getUsername(), user.getRealm());
//The PRIMARY domain is not appended by UserCoreUtil.addDomainToName() method. Adding it here.
//This is done to avoid user being resolved when PRIMARY is wrongly passed as the user's realm.
if (user.getRealm().equalsIgnoreCase(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME)) {
userDomainQualifiedUsername = UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME +
UserCoreConstants.DOMAIN_SEPARATOR + user.getUsername();
} else {
userDomainQualifiedUsername = UserCoreUtil.addDomainToName(user.getUsername(),
user.getRealm());
}
user.setUsername(userDomainQualifiedUsername);
}
ResolvedUserResult resolvedUserResult =
Expand Down

0 comments on commit 3c5fcf1

Please sign in to comment.