@Override public String getUserIdentifier() { return user.getUniqueUserId(); } }
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 Set<Claim> getClaims() throws IdentityStoreException, UserNotFoundException { return new HashSet(user.getClaims()); }
public User build() { //TODO Add authorizationStore with M3 if (userId == null || identityStore == null || domainName == null) { throw new StoreException(String.format("Required data missing for building user." + " userId: %s, identityStore: %s, domainName: %s", userId, identityStore, domainName)); } User user = new User(userId, domainName, state); user.setIdentityStore(identityStore); return user; } }
if (log.isDebugEnabled()) { log.debug("There are more than one user in the result set : " + user.toString()); triggerNotification(user.getUniqueUserId(), IdentityRecoveryConstants.NOTIFICATION_ACCOUNT_ID_RECOVERY, user); joiner.add(user1.getUniqueUserId()); });
@Override public UUFUser addUser(Map<String, String> userClaims, Map<String, String> credentials) throws UserPortalUIException { UserBean userBean = new UserBean(); List<Claim> claimsList = new ArrayList<>(); List<Callback> credentialsList = new ArrayList<>(); User identityUser; for (Map.Entry<String, String> credential : credentials.entrySet()) { PasswordCallback passwordCallback = new PasswordCallback("password", false); passwordCallback.setPassword(credential.getValue().toCharArray()); credentialsList.add(passwordCallback); } for (Map.Entry<String, String> entry : userClaims.entrySet()) { Claim claim = new Claim(); claim.setClaimUri(entry.getKey()); claim.setValue(entry.getValue()); claimsList.add(claim); } userBean.setClaims(claimsList); userBean.setCredentials(credentialsList); try { identityUser = getRealmService().getIdentityStore().addUser(userBean); } catch (IdentityStoreException e) { String error = "Error while adding user."; LOGGER.error(error, e); throw new UserPortalUIException(error); } return new UUFUser(null, identityUser.getUniqueUserId(), identityUser.getDomainName()); }
List<Claim> claimValueList = identityStore.getUser(user.getUniqueUserId()).getClaims(metaClaimList); scimGroup.setMember(user.getUniqueUserId(), claimValueList.get(0).getValue());
private void triggerNotification(String userUniqueId, String type, User user) throws IdentityRecoveryException { String eventName = EventConstants.Event.TRIGGER_NOTIFICATION; HashMap<String, Object> properties = new HashMap<>(); properties.put(EventConstants.EventProperty.USER_UNIQUE_ID, userUniqueId); properties.put(EventConstants.EventProperty.USER_STORE_DOMAIN, user.getDomainName()); properties.put(IdentityRecoveryConstants.TEMPLATE_TYPE, type); Event identityMgtEvent = new Event(eventName, properties); EventContext eventContext = new EventContext(); try { IdentityRecoveryServiceDataHolder.getInstance().getIdentityEventService().pushEvent(identityMgtEvent, eventContext); } catch (IdentityException e) { throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_TRIGGER_NOTIFICATION, userUniqueId, e); } }
@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; }
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); }
@Override public UUFUser addUser(Map<String, String> userClaims, Map<String, String> credentials, String domainName) throws UserPortalUIException { UserBean userBean = new UserBean(); List<Claim> claimsList = new ArrayList<>(); List<Callback> credentialsList = new ArrayList<>(); User identityUser; for (Map.Entry<String, String> credential : credentials.entrySet()) { PasswordCallback passwordCallback = new PasswordCallback("password", false); passwordCallback.setPassword(credential.getValue().toCharArray()); credentialsList.add(passwordCallback); } for (Map.Entry<String, String> entry : userClaims.entrySet()) { Claim claim = new Claim(); claim.setClaimUri(entry.getKey()); claim.setValue(entry.getValue()); claimsList.add(claim); } userBean.setClaims(claimsList); userBean.setCredentials(credentialsList); try { identityUser = getRealmService().getIdentityStore().addUser(userBean, domainName); } catch (IdentityStoreException e) { String error = "Error while adding user."; LOGGER.error(error, e); throw new UserPortalUIException(error); } return new UUFUser(null, identityUser.getUniqueUserId(), identityUser.getDomainName()); }
log.debug(String.format("Setting user challenge question answers in %s's profile.", user.toString())); .getQuestion().getQuestion() != null && userChallengeAnswer.getAnswer() != null) { String oldValue = Utils.getClaimFromIdentityStore(user.getUniqueUserId(), userChallengeAnswer.getQuestion().getQuestionSetId().trim()); IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_QUESTION_OF_USER, user.getUniqueUserId(), e);
private void validateUser(User user) throws IdentityRecoveryException { if (user == null || StringUtils.isBlank(user.getUniqueUserId())) { throw Utils.handleClientException( IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_INVALID_USER, "Invalid User Data provided."); } }
@Override public UUFUser authenticate(String username, char[] password, String domain) throws UserPortalUIException { try { //TODO if different claim is used, need identify that claim. Claim usernameClaim = new Claim(IdentityMgtConstants.CLAIM_ROOT_DIALECT, IdentityMgtConstants.USERNAME_CLAIM, username); PasswordCallback passwordCallback = new PasswordCallback("password", false); passwordCallback.setPassword(password); AuthenticationContext authenticationContext = getRealmService().getIdentityStore() .authenticate(usernameClaim, new Callback[]{passwordCallback}, domain); User identityUser = authenticationContext.getUser(); //TODO if another claim used, need to load username claim return new UUFUser(username, identityUser.getUniqueUserId(), identityUser.getDomainName()); } catch (AuthenticationFailure e) { String error = "Invalid credentials."; if (LOGGER.isDebugEnabled()) { LOGGER.debug(error, e); } throw new UserPortalUIException("Invalid credentials."); } catch (IdentityStoreException e) { String error = "Failed to authenticate user."; LOGGER.error(error, e); throw new UserPortalUIException(error); } }
@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); } }
public List<String> getUserChallengeQuestionIds(User user) throws IdentityRecoveryException { validateUser(user); if (log.isDebugEnabled()) { log.debug("Retrieving answered Challenge question set ids from the user profile."); } List<String> challengesUris = getChallengeQuestionUris(user.getUniqueUserId()); if (challengesUris.isEmpty()) { String msg = "No associated challenge question found for the user : " + user.getUniqueUserId(); if (log.isDebugEnabled()) { log.debug(msg); } } return challengesUris; }
private List<Object> listUsersWithPagination(int startIndex, int count) throws CharonException { try { //get the user list according to the start index and the count values provided. //TODO : Add the domain of the store and need to fix IDENTITY-5784 to remove +1 from count if (count > 1) { count++; } List<org.wso2.carbon.identity.mgt.User> userList = identityStore.listUsers(startIndex, count); List<Object> userObjectList = new ArrayList<>(); //we need to set the first item of the array to be the number of users in the given domain. userObjectList.add(userList.size()); //convert identity store users to objects. for (org.wso2.carbon.identity.mgt.User user : userList) { //get the details of the users. //TODO:We need to pass the scim claim dialect for this method List<Claim> claimList = user.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(user, claimList); userObjectList.add(scimUser); } return userObjectList; } catch (IdentityStoreException | UserNotFoundException e) { throw new CharonException("Error in getting the user list with start index :" + startIndex + " and " + "count of :" + count, e); } }
private String getLocaleOfUser(User user) throws IdentityRecoveryException { String locale = IdentityRecoveryConstants.LOCALE_EN_US; try { String userLocale = Utils.getClaimFromIdentityStore(user.getUniqueUserId(), IdentityRecoveryConstants.Questions .LOCALE_CLAIM); if (StringUtils.isNotBlank(userLocale)) { locale = userLocale; } } catch (IdentityStoreException e) { String errorMsg = String.format("Error when retrieving the locale claim of user '%s'.", user.getUniqueUserId()); log.error(errorMsg); throw new IdentityRecoveryServerException(errorMsg, e); } catch (UserNotFoundException e) { String errorMsg = String.format("Error when retrieving the locale claim of user '%s'.", user.getUniqueUserId()); log.error(errorMsg); throw new IdentityRecoveryServerException(errorMsg, e); } return locale; }
@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); } }
List<Claim> claimsList = identityStore.getClaimsOfUser(user.getUniqueUserId()); claim.setDialectUri(dialectUri); claimsList.add(claim); identityStore.updateUserClaims(user.getUniqueUserId(), claimsList);