Skip to content

Commit

Permalink
Merge pull request #774 from sandushi/recaptcha-issue
Browse files Browse the repository at this point in the history
Refactor recaptcha prevalidator to handle multi attribute login scenario
  • Loading branch information
sandushi authored Oct 17, 2023
2 parents 60150dc + 54f3960 commit acecb3c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions components/org.wso2.carbon.identity.captcha/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
</Import-Package>
</instructions>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit acecb3c

Please sign in to comment.