From 1aa671f51f55749ef0d37e26ce8911fb1910f8f9 Mon Sep 17 00:00:00 2001 From: mpmadhavig Date: Thu, 12 Oct 2023 17:47:37 +0530 Subject: [PATCH] Authenticate user with username instead of userid when UserStorePreferenceOrderConfigured. --- .../attribute/login/resolver/regex/RegexResolver.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/components/org.wso2.carbon.identity.multi.attribute.login/org.wso2.carbon.identity.multi.attribute.login.resolver.regex/src/main/java/org/wso2/carbon/identity/multi/attribute/login/resolver/regex/RegexResolver.java b/components/org.wso2.carbon.identity.multi.attribute.login/org.wso2.carbon.identity.multi.attribute.login.resolver.regex/src/main/java/org/wso2/carbon/identity/multi/attribute/login/resolver/regex/RegexResolver.java index 65c9a44b07..68a78c4213 100644 --- a/components/org.wso2.carbon.identity.multi.attribute.login/org.wso2.carbon.identity.multi.attribute.login.resolver.regex/src/main/java/org/wso2/carbon/identity/multi/attribute/login/resolver/regex/RegexResolver.java +++ b/components/org.wso2.carbon.identity.multi.attribute.login/org.wso2.carbon.identity.multi.attribute.login.resolver.regex/src/main/java/org/wso2/carbon/identity/multi/attribute/login/resolver/regex/RegexResolver.java @@ -162,7 +162,7 @@ private void resolveDistinctUsersForClaims(String loginAttribute, List a if (distinctUsers.size() == 1) { Map.Entry> entry = distinctUsers.entrySet().iterator().next(); setResolvedUserResult(entry.getValue(), entry.getKey(), loginAttribute, resolvedUserResult, - claimManager.getClaim(entry.getKey())); + claimManager.getClaim(entry.getKey()), !userStorePreferenceOrder.isEmpty()); } else { resolvedUserResult.setErrorMessage("Found multiple users for " + allowedAttributes + " to value " + loginAttribute); @@ -283,7 +283,8 @@ private IterativeUserStoreManager generateUserStoreChain(List userStoreP } private void setResolvedUserResult(List userList, String claimURI, - String loginAttribute, ResolvedUserResult resolvedUserResult, Claim claim) + String loginAttribute, ResolvedUserResult resolvedUserResult, Claim claim, + boolean IsUserStorePreferenceOrderConfigured) throws org.wso2.carbon.user.core.UserStoreException { if (userList.size() == 1) { @@ -291,6 +292,10 @@ private void setResolvedUserResult(List userList, String claimURI, resolvedUserResult.setResolvedClaim(claimURI); resolvedUserResult.setResolvedValue(loginAttribute); User user = userList.get(0); + // To authenticate user with the username and password flow. + if (IsUserStorePreferenceOrderConfigured) { + user.setUserID(null); + } user.setUsername(user.getDomainQualifiedUsername()); resolvedUserResult.setUser(user); } else if (userList.size() > 1) {