@Override public User execute() throws IdentityStoreException, UserNotFoundException { return identityStore.getUser(uniqueUserId); } }).pushEvent(IdentityStoreInterceptorConstants.POST_GET_USER_BY_ID, (eventProperties) -> {
@Override public User execute() throws IdentityStoreException, UserNotFoundException { return identityStore.getUser(claim); } }).pushEvent(IdentityStoreInterceptorConstants.POST_GET_USER_BY_CLAIM, (eventProperties) -> {
@Override public User execute() throws IdentityStoreException, UserNotFoundException { return identityStore.getUser(claim, domainName); } }).pushEvent(IdentityStoreInterceptorConstants.POST_GET_USER_BY_CLAIM_DOMAIN,
@Override public User getUser(Claim claim) throws IdentityStoreException, UserNotFoundException { return identityStore.getUser(claim); }
@Override public User getUser(Claim claim, String domainName) throws IdentityStoreException, UserNotFoundException { return identityStore.getUser(claim); }
@Override public User getUser(String uniqueUserId) throws IdentityStoreException, UserNotFoundException { if (cacheStatus.get(UNIQUE_USER_CACHE) && isNullOrEmpty(uniqueUserId)) { return doGetUser(uniqueUserId, identityStore.getPrimaryDomainName()); } User user = identityStore.getUser(uniqueUserId); user.setIdentityStore(this); return user; }
User user = realmService.getIdentityStore().getUser(userUniqueId);
private User doGetUser(String uniqueUserId, String domainName) throws IdentityStoreException, UserNotFoundException { Cache<String, User> userCache = cacheManager.getCache(UNIQUE_USER_CACHE, String.class, User.class); User user = userCache.get(uniqueUserId.hashCode() + ":" + domainName.hashCode()); if (user == null) { user = identityStore.getUser(uniqueUserId); userCache.put(user.getUniqueUserId().hashCode() + ":" + user.getDomainName().hashCode(), user); user.setIdentityStore(this); return user; } user.setIdentityStore(this); return user; }
@Override public void deleteUser(String userId) throws NotFoundException, CharonException, NotImplementedException, BadRequestException { if (log.isDebugEnabled()) { log.debug("Deleting user: " + userId); } try { org.wso2.carbon.identity.mgt.User user = identityStore.getUser(userId); List<Claim> claims = user.getClaims(); boolean isAdminUser = claims.stream().anyMatch(claim -> USERNAME_CLAIM.equals(claim.getClaimUri()) && ADMIN_USERNAME.equals(claim.getValue())); if (isAdminUser) { throw new BadRequestException("Cannot Delete admin user from the System"); } identityStore.deleteUser(userId); if (log.isDebugEnabled()) { log.debug("User with the id : " + userId + " is deleted through SCIM."); } } catch (UserNotFoundException e) { throw new NotFoundException("User with the user id : " + userId + " does not exists."); } catch (IdentityStoreException e) { throw new CharonException("Error in deleting the user with the id: " + userId, e); } }
@Override public List<ChallengeQuestionSetEntry> getChallengeQuestionList(String userUniqueId) throws IdentityRecoveryException, IdentityStoreException, UserNotFoundException { List<ChallengeQuestionSetEntry> challengeQuestionSetEntryList = new ArrayList<ChallengeQuestionSetEntry>(); if (challengeQuestionManager == null || realmService == null) { throw new IdentityRecoveryException("Challenge question manager or Realm service is not available."); } User user = realmService.getIdentityStore().getUser(userUniqueId); List<ChallengeQuestion> challengeQuestions = challengeQuestionManager.getAllChallengeQuestionsForUser(user); Map<String, List<ChallengeQuestion>> groupedChallengeQuestionMap = challengeQuestions.stream() .collect(Collectors .groupingBy(ChallengeQuestion::getQuestionSetId)); for (Map.Entry<String, List<ChallengeQuestion>> entry : groupedChallengeQuestionMap.entrySet()) { ChallengeQuestionSetEntry challengeQuestionSetEntry = new ChallengeQuestionSetEntry(); challengeQuestionSetEntry.setChallengeQuestionSetId(encodeChallengeQuestionSetId(entry.getKey())); List<ChallengeQuestion> encodedSetIdChallengeQuestionsList = entry.getValue().stream(). map(challengeQuestion -> { challengeQuestion.setQuestionSetId(encodeChallengeQuestionSetId(challengeQuestion .getQuestionSetId())); return challengeQuestion; }).collect(Collectors.toList()); challengeQuestionSetEntry.setChallengeQuestionList(encodedSetIdChallengeQuestionsList); challengeQuestionSetEntryList.add(challengeQuestionSetEntry); } return challengeQuestionSetEntryList; }
@Override public void deleteChallengeQuestionForUser(String userUniqueId, String questionId, String questionSetId) throws IdentityRecoveryException, IdentityStoreException, UserNotFoundException, UserPortalUIException { if (challengeQuestionManager == null || realmService == null) { throw new IdentityRecoveryException("Challenge question manager or Realm service is not available."); } int minNumOfSecurityQuestions = challengeQuestionManager.getMinimumNoOfChallengeQuestionsToAnswer(); User user = realmService.getIdentityStore().getUser(userUniqueId); List<UserChallengeAnswer> existingAnswers = challengeQuestionManager.getChallengeAnswersOfUser(userUniqueId); if (minNumOfSecurityQuestions < existingAnswers.size()) { existingAnswers.removeIf(answer -> StringUtils.equals(answer.getQuestion().getQuestionId(), questionId) && StringUtils.equals(answer.getQuestion().getQuestionSetId(), new String(Base64.getDecoder().decode(questionSetId.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8))); challengeQuestionManager.setChallengesOfUser(user, existingAnswers); } else { String error = "Cannot delete security question. You need to have at least" + minNumOfSecurityQuestions + "security questions"; throw new UserPortalUIException(error); } }
@Override public User getUser(String userId, Map<String, Boolean> requiredAttributes) throws CharonException, BadRequestException, NotFoundException { if (log.isDebugEnabled()) { log.debug("Retrieving user: " + userId); } try { org.wso2.carbon.identity.mgt.User userStoreUser = identityStore.getUser(userId); //TODO:We need to pass the scim claim dialect for this method List<Claim> claimList = userStoreUser.getClaims(); //TODO this is a temporary method. need to remove this once the claim management is completed. claimList = ClaimMapper.getInstance().convertToScimDialect(claimList); User scimUser = getSCIMUser(userStoreUser, claimList); if (log.isDebugEnabled()) { log.debug("User: " + scimUser.getUserName() + " is retrieved through SCIM."); } return scimUser; } catch (IdentityStoreException e) { throw new CharonException("Error in getting user from the userid :" + userId, e); } catch (UserNotFoundException e) { throw new NotFoundException("User not found with the given userid :" + userId); } }
private static boolean isAccountInState(String uniqueUserId, UserState.Group group) throws IdentityRecoveryException { RealmService realmService = IdentityRecoveryServiceDataHolder.getInstance().getRealmService(); IdentityStore identityStore = realmService.getIdentityStore(); String state; try { state = identityStore.getUser(uniqueUserId).getState(); } catch (IdentityStoreException e) { throw Utils.handleServerException( IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_FAILED_TO_LOAD_USER_CLAIMS, null, e); } catch (UserNotFoundException e) { throw Utils.handleServerException( IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_FAILED_TO_LOAD_USER_CLAIMS, null, e); } return UserState.valueOf(state).isInGroup(group); }
List<Claim> claimValueList = identityStore.getUser(user.getUniqueUserId()).getClaims(metaClaimList); scimGroup.setMember(user.getUniqueUserId(), claimValueList.get(0).getValue());