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());
}
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations