Search in sources :

Example 1 with UniqueIDUserStoreManager

use of org.wso2.carbon.user.core.UniqueIDUserStoreManager in project carbon-identity-framework by wso2.

the class UserFunctionalityManagerImpl method isUserIdExists.

private boolean isUserIdExists(String userId, int tenantId) throws UserFunctionalityManagementClientException, UserFunctionalityManagementServerException {
    boolean isUserExists;
    try {
        UniqueIDUserStoreManager uniqueIdEnabledUserStoreManager = getUniqueIdEnabledUserStoreManager(UserFunctionalityManagerComponentDataHolder.getInstance().getRealmService(), IdentityTenantUtil.getTenantDomain(tenantId));
        isUserExists = uniqueIdEnabledUserStoreManager.isExistingUserWithID(userId);
        return isUserExists;
    } catch (UserStoreException e) {
        if (isUserNotExistingError(e, userId)) {
            if (log.isDebugEnabled()) {
                log.debug("Cannot retrieve user from userId: " + userId, e);
            }
            throw buildUserNotFoundError();
        }
        throw new UserFunctionalityManagementServerException(UserFunctionalityMgtConstants.ErrorMessages.ERROR_OCCURRED_WHILE_RETRIEVING_USER.getCode(), UserFunctionalityMgtConstants.ErrorMessages.ERROR_OCCURRED_WHILE_RETRIEVING_USER.getDescription());
    }
}
Also used : UniqueIDUserStoreManager(org.wso2.carbon.user.core.UniqueIDUserStoreManager) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserFunctionalityManagementServerException(org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementServerException)

Example 2 with UniqueIDUserStoreManager

use of org.wso2.carbon.user.core.UniqueIDUserStoreManager in project carbon-identity-framework by wso2.

the class UserFunctionalityManagerImpl method getUniqueIdEnabledUserStoreManager.

private UniqueIDUserStoreManager getUniqueIdEnabledUserStoreManager(RealmService realmService, String tenantDomain) throws UserStoreException, UserFunctionalityManagementClientException {
    UserStoreManager userStoreManager = realmService.getTenantUserRealm(IdentityTenantUtil.getTenantId(tenantDomain)).getUserStoreManager();
    if (!(userStoreManager instanceof UniqueIDUserStoreManager)) {
        if (log.isDebugEnabled()) {
            String msg = "Provided user store manager does not support unique user IDs in the tenant domain" + tenantDomain;
            log.debug(msg);
        }
        throw buildUserNotFoundError();
    }
    return (UniqueIDUserStoreManager) userStoreManager;
}
Also used : UniqueIDUserStoreManager(org.wso2.carbon.user.core.UniqueIDUserStoreManager) UserStoreManager(org.wso2.carbon.user.api.UserStoreManager) UniqueIDUserStoreManager(org.wso2.carbon.user.core.UniqueIDUserStoreManager)

Example 3 with UniqueIDUserStoreManager

use of org.wso2.carbon.user.core.UniqueIDUserStoreManager in project identity-governance by wso2-extensions.

the class RegexResolver method resolveUser.

@Override
public ResolvedUserResult resolveUser(String loginAttribute, List<String> allowedAttributes, String tenantDomain) {
    ResolvedUserResult resolvedUserResult = new ResolvedUserResult(ResolvedUserResult.UserResolvedStatus.FAIL);
    try {
        if (allowedAttributes == null) {
            return resolvedUserResult;
        }
        UserRealm userRealm = UserResolverUtil.getUserRealm(tenantDomain);
        UniqueIDUserStoreManager userStoreManager = UserResolverUtil.getUserStoreManager(tenantDomain);
        ClaimManager claimManager = userRealm.getClaimManager();
        for (String claimURI : allowedAttributes) {
            Claim claim = claimManager.getClaim(claimURI);
            if (claim == null) {
                continue;
            }
            String regex = claim.getRegEx();
            if (StringUtils.isBlank(regex)) {
                continue;
            }
            Pattern pattern = Pattern.compile(regex);
            String domainSeparateAttribute = UserCoreUtil.removeDomainFromName(loginAttribute);
            if (pattern.matcher(domainSeparateAttribute).matches()) {
                setResolvedUserResult(userStoreManager, claimURI, loginAttribute, resolvedUserResult, claim);
                break;
            }
        }
        /*
            resolve user if allowed attributes has only username claim,
            but username claim has no configured regex pattern.
             */
        if (allowedAttributes.size() == 1 && allowedAttributes.contains(UserCoreClaimConstants.USERNAME_CLAIM_URI)) {
            setResolvedUserResult(userStoreManager, UserCoreClaimConstants.USERNAME_CLAIM_URI, loginAttribute, resolvedUserResult, claimManager.getClaim(UserCoreClaimConstants.USERNAME_CLAIM_URI));
        }
    } catch (UserStoreException e) {
        log.error("Error occurred while resolving user name", e);
    }
    return resolvedUserResult;
}
Also used : ClaimManager(org.wso2.carbon.user.api.ClaimManager) Pattern(java.util.regex.Pattern) UserRealm(org.wso2.carbon.user.core.UserRealm) UniqueIDUserStoreManager(org.wso2.carbon.user.core.UniqueIDUserStoreManager) UserStoreException(org.wso2.carbon.user.api.UserStoreException) ResolvedUserResult(org.wso2.carbon.identity.multi.attribute.login.mgt.ResolvedUserResult) Claim(org.wso2.carbon.user.api.Claim)

Example 4 with UniqueIDUserStoreManager

use of org.wso2.carbon.user.core.UniqueIDUserStoreManager in project identity-governance by wso2-extensions.

the class RegexResolver method setResolvedUserResult.

private void setResolvedUserResult(UniqueIDUserStoreManager userStoreManager, String claimURI, String loginAttribute, ResolvedUserResult resolvedUserResult, Claim claim) throws org.wso2.carbon.user.core.UserStoreException {
    List<User> userList = userStoreManager.getUserListWithID(claimURI, loginAttribute, null);
    if (userList.size() == 1) {
        resolvedUserResult.setResolvedStatus(ResolvedUserResult.UserResolvedStatus.SUCCESS);
        resolvedUserResult.setResolvedClaim(claimURI);
        resolvedUserResult.setResolvedValue(loginAttribute);
        User user = userList.get(0);
        user.setUsername(user.getDomainQualifiedUsername());
        resolvedUserResult.setUser(user);
    } else if (userList.size() > 1) {
        resolvedUserResult.setErrorMessage("Found multiple users for " + claim.getDisplayTag() + " to value " + loginAttribute);
    }
}
Also used : User(org.wso2.carbon.user.core.common.User)

Example 5 with UniqueIDUserStoreManager

use of org.wso2.carbon.user.core.UniqueIDUserStoreManager in project identity-governance by wso2-extensions.

the class RegexResolver method authenticateWithIdentifier.

@Override
public AuthenticationResult authenticateWithIdentifier(String loginAttributeValue, List<String> allowedAttributes, Object credential, String tenantDomain) {
    AuthenticationResult authenticationResult = new AuthenticationResult(AuthenticationResult.AuthenticationStatus.FAIL);
    ClaimManager claimManager;
    try {
        if (allowedAttributes == null) {
            return authenticationResult;
        }
        UserRealm userRealm = UserResolverUtil.getUserRealm(tenantDomain);
        UniqueIDUserStoreManager userStoreManager = UserResolverUtil.getUserStoreManager(tenantDomain);
        claimManager = userRealm.getClaimManager();
        for (String claimURI : allowedAttributes) {
            Claim claim = claimManager.getClaim(claimURI);
            if (claim == null) {
                continue;
            }
            String regex = claim.getRegEx();
            if (StringUtils.isBlank(regex)) {
                continue;
            }
            Pattern pattern = Pattern.compile(regex);
            if (pattern.matcher(loginAttributeValue).matches()) {
                authenticationResult = userStoreManager.authenticateWithID(claimURI, loginAttributeValue, credential, StringUtils.EMPTY);
                if (AuthenticationResult.AuthenticationStatus.SUCCESS.equals(authenticationResult.getAuthenticationStatus())) {
                    break;
                }
            }
        }
        /*
            If allowed attributes has only username claim, get authenticationResult even if
            the username claim has no configured regex pattern.
             */
        if (allowedAttributes.size() == 1 && allowedAttributes.contains(UserCoreClaimConstants.USERNAME_CLAIM_URI)) {
            authenticationResult = userStoreManager.authenticateWithID(UserCoreClaimConstants.USERNAME_CLAIM_URI, loginAttributeValue, credential, StringUtils.EMPTY);
        }
    } catch (UserStoreException e) {
        log.error("Error occurred while resolving authenticationResult", e);
    }
    return authenticationResult;
}
Also used : ClaimManager(org.wso2.carbon.user.api.ClaimManager) Pattern(java.util.regex.Pattern) UserRealm(org.wso2.carbon.user.core.UserRealm) UniqueIDUserStoreManager(org.wso2.carbon.user.core.UniqueIDUserStoreManager) UserStoreException(org.wso2.carbon.user.api.UserStoreException) Claim(org.wso2.carbon.user.api.Claim) AuthenticationResult(org.wso2.carbon.user.core.common.AuthenticationResult)

Aggregations

UniqueIDUserStoreManager (org.wso2.carbon.user.core.UniqueIDUserStoreManager)4 UserStoreException (org.wso2.carbon.user.api.UserStoreException)3 Pattern (java.util.regex.Pattern)2 Claim (org.wso2.carbon.user.api.Claim)2 ClaimManager (org.wso2.carbon.user.api.ClaimManager)2 UserRealm (org.wso2.carbon.user.core.UserRealm)2 ResolvedUserResult (org.wso2.carbon.identity.multi.attribute.login.mgt.ResolvedUserResult)1 UserFunctionalityManagementServerException (org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementServerException)1 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)1 AuthenticationResult (org.wso2.carbon.user.core.common.AuthenticationResult)1 User (org.wso2.carbon.user.core.common.User)1