From 54f396076f7c2ce7990053c20130be6f9525fed9 Mon Sep 17 00:00:00 2001 From: sandushi Date: Fri, 13 Oct 2023 16:29:52 +0530 Subject: [PATCH] Refactor recpatcha prevalidator to handle multi attribute login scenarios --- components/org.wso2.carbon.identity.captcha/pom.xml | 2 ++ .../connector/recaptcha/SSOLoginReCaptchaConfig.java | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/components/org.wso2.carbon.identity.captcha/pom.xml b/components/org.wso2.carbon.identity.captcha/pom.xml index f0f86f263a..e91d0eed07 100644 --- a/components/org.wso2.carbon.identity.captcha/pom.xml +++ b/components/org.wso2.carbon.identity.captcha/pom.xml @@ -197,6 +197,8 @@ version="${carbon.identity.account.lock.handler.imp.pkg.version.range}", org.wso2.securevault.*; version="${org.wso2.securevault.import.version.range}", org.wso2.carbon.context; version="${carbon.kernel.package.import.version.range}", + org.wso2.carbon.identity.multi.attribute.login.mgt.*; + version="${carbon.identity.framework.imp.pkg.version.range}", diff --git a/components/org.wso2.carbon.identity.captcha/src/main/java/org/wso2/carbon/identity/captcha/connector/recaptcha/SSOLoginReCaptchaConfig.java b/components/org.wso2.carbon.identity.captcha/src/main/java/org/wso2/carbon/identity/captcha/connector/recaptcha/SSOLoginReCaptchaConfig.java index 1b1832ea73..7be47a67a9 100644 --- a/components/org.wso2.carbon.identity.captcha/src/main/java/org/wso2/carbon/identity/captcha/connector/recaptcha/SSOLoginReCaptchaConfig.java +++ b/components/org.wso2.carbon.identity.captcha/src/main/java/org/wso2/carbon/identity/captcha/connector/recaptcha/SSOLoginReCaptchaConfig.java @@ -38,6 +38,8 @@ import org.wso2.carbon.identity.governance.IdentityGovernanceException; import org.wso2.carbon.identity.governance.IdentityGovernanceService; import org.wso2.carbon.identity.governance.common.IdentityConnectorConfig; +import org.wso2.carbon.identity.multi.attribute.login.mgt.ResolvedUserResult; +import org.wso2.carbon.user.core.util.UserCoreUtil; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import java.util.HashMap; @@ -121,6 +123,15 @@ public CaptchaPreValidationResponse preValidate(ServletRequest servletRequest, S AuthenticationContext context = FrameworkUtils.getAuthenticationContextFromCache(sessionDataKey); String tenantDomain = getTenant(context, username); + // Resolve the username from the multi attribute login service when the multi attribute login is enabled. + ResolvedUserResult resolvedUserResult = FrameworkUtils.processMultiAttributeLoginIdentification( + MultitenantUtils.getTenantAwareUsername(username), tenantDomain); + if (resolvedUserResult != null && ResolvedUserResult.UserResolvedStatus.SUCCESS. + equals(resolvedUserResult.getResolvedStatus())) { + username = UserCoreUtil.addTenantDomainToEntry(resolvedUserResult.getUser().getUsername(), + tenantDomain); + } + // Verify whether recaptcha is enforced always for basic authentication. Property[] connectorConfigs = null; try {