private boolean isUsernamePresent(UserBean userBean) { return userBean.getClaims().stream() .filter(claim -> USERNAME_CLAIM.equals(claim.getClaimUri()) && !isNullOrEmpty(claim.getValue())) .findAny() .isPresent(); }
public List<String> getGroupsOfUser(String domainUserId) throws DomainException { List<DomainGroup> domainGroups; try { domainGroups = uniqueIdResolver.getGroupsOfUser(domainUserId, this.id); } catch (UniqueIdResolverException e) { throw new DomainException(String.format("Failed to retrieve the unique group ids for user id - %s.", domainUserId), e); } if (domainGroups == null || domainGroups.isEmpty()) { return Collections.emptyList(); } return domainGroups.stream() .filter(Objects::nonNull) .filter(uniqueUser -> !isNullOrEmpty(uniqueUser.getDomainGroupId())) .map(DomainGroup::getDomainGroupId) .collect(Collectors.toList()); }
public List<String> listDomainGroups(int offset, int length) throws DomainException { List<DomainGroup> domainGroups; try { domainGroups = this.uniqueIdResolver.listGroups(offset, length, this.id); } catch (UniqueIdResolverException e) { throw new DomainException("Failed to retrieve partitions of groups.", e); } if (domainGroups == null || domainGroups.isEmpty()) { return Collections.emptyList(); } return domainGroups.stream() .filter(Objects::nonNull) .filter(domainGroup -> !isNullOrEmpty(domainGroup.getDomainGroupId())) .map(DomainGroup::getDomainGroupId) .collect(Collectors.toList()); }
private static List<MetaClaimMapping> getMetaClaimMappings(String storeConnectorId, List<DomainAttributeConfigEntry> attributeConfigEntries) { if (attributeConfigEntries.isEmpty()) { return Collections.emptyList(); } return attributeConfigEntries.stream() .filter(Objects::nonNull) .filter(domainAttributeConfigEntry -> !StringUtils.isNullOrEmpty(domainAttributeConfigEntry .getClaimUri()) && !StringUtils.isNullOrEmpty(domainAttributeConfigEntry.getAttribute())) .map(domainAttributeConfigEntry -> { MetaClaim metaClaim = new MetaClaim(CLAIM_ROOT_DIALECT, domainAttributeConfigEntry.getClaimUri(), domainAttributeConfigEntry.getProperties()); return new MetaClaimMapping(metaClaim, storeConnectorId, domainAttributeConfigEntry.getAttribute()); }).collect(Collectors.toList()); } }
@Override public Group getGroup(String uniqueGroupId) throws IdentityStoreException, GroupNotFoundException { if (cacheStatus.get(UNIQUE_GROUP_CACHE) && !isNullOrEmpty(uniqueGroupId)) { return doGetGroup(uniqueGroupId, identityStore.getPrimaryDomainName()); } Group group = identityStore.getGroup(uniqueGroupId); group.setIdentityStore(this); return group; }
@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; }
@Override public void updateUserClaims(String uniqueUserId, List<Claim> claimsToAdd, List<Claim> claimsToRemove) throws IdentityStoreException, UserNotFoundException { if (isNullOrEmpty(uniqueUserId)) { throw new IdentityStoreClientException("Invalid user unique id."); } if ((claimsToAdd == null || claimsToAdd.isEmpty()) && (claimsToRemove == null || claimsToRemove.isEmpty())) { return; } SimpleEntry<Integer, String> decodedUniqueUserId = getDecodedUniqueEntityId(uniqueUserId); Domain domain = domains.get(decodedUniqueUserId.getKey()); try { domain.updateUserClaims(decodedUniqueUserId.getValue(), claimsToAdd, claimsToRemove); } catch (DomainException e) { throw new IdentityStoreServerException(String.format("Failed to update claims of user - %s", uniqueUserId)); } }
private static <T extends StoreConnectorConfig> List<StoreConnectorConfig> getStoreConnectorConfig (List<ConnectorConfigEntry> connectorConfigEntries, Class<T> classType) { return connectorConfigEntries.stream() .filter(Objects::nonNull) .filter(connectorConfigEntry -> !StringUtils.isNullOrEmpty(connectorConfigEntry.getConnectorId()) && !StringUtils.isNullOrEmpty(connectorConfigEntry.getConnectorType())) .map(connectorConfigEntry -> { if (classType.equals(IdentityStoreConnectorConfig.class)) { return new IdentityStoreConnectorConfig(connectorConfigEntry.getConnectorId(), connectorConfigEntry.getConnectorType(), connectorConfigEntry.isReadOnly(), connectorConfigEntry.getProperties()); } return new CredentialStoreConnectorConfig(connectorConfigEntry.getConnectorId(), connectorConfigEntry.getConnectorType(), connectorConfigEntry.isReadOnly(), connectorConfigEntry.getProperties()); }) .collect(Collectors.toList()); }
@Override public void deleteUser(String uniqueUserId) throws IdentityStoreException, UserNotFoundException { if (isNullOrEmpty(uniqueUserId)) { throw new IdentityStoreClientException("Invalid user unique id."); } SimpleEntry<Integer, String> decodedUniqueUserId = getDecodedUniqueEntityId(uniqueUserId); Domain domain = domains.get(decodedUniqueUserId.getKey()); try { domain.deleteUser(decodedUniqueUserId.getValue()); } catch (DomainException e) { throw new IdentityStoreServerException(String.format("Failed to delete user - %s", uniqueUserId)); } }
@Override public void deleteGroup(String uniqueGroupId) throws IdentityStoreException, GroupNotFoundException { if (isNullOrEmpty(uniqueGroupId)) { throw new IdentityStoreClientException("Invalid group unique id."); } SimpleEntry<Integer, String> decodedUniqueGroupId = getDecodedUniqueEntityId(uniqueGroupId); Domain domain = domains.get(decodedUniqueGroupId.getKey()); try { domain.deleteGroup(decodedUniqueGroupId.getValue()); } catch (DomainException e) { throw new IdentityStoreServerException(String.format("Failed to delete user - %s", uniqueGroupId)); } }
@Override public List<Claim> getClaimsOfGroup(String uniqueGroupId) throws IdentityStoreException, GroupNotFoundException { if (isNullOrEmpty(uniqueGroupId)) { throw new IdentityStoreClientException("Invalid unique group id."); } SimpleEntry<Integer, String> decodedUniqueGroupId = getDecodedUniqueEntityId(uniqueGroupId); Domain domain = domains.get(decodedUniqueGroupId.getKey()); try { return domain.getClaimsOfGroup(decodedUniqueGroupId.getValue()); } catch (DomainException e) { throw new IdentityStoreServerException(String.format("Failed to get claims of unique goup - %s.", uniqueGroupId), e); } }
@Override public void updateUserClaims(String uniqueUserId, List<Claim> claims) throws IdentityStoreException, UserNotFoundException { if (isNullOrEmpty(uniqueUserId)) { throw new IdentityStoreClientException("Invalid user unique id."); } SimpleEntry<Integer, String> decodedUniqueUserId = getDecodedUniqueEntityId(uniqueUserId); Domain domain = domains.get(decodedUniqueUserId.getKey()); try { domain.updateUserClaims(decodedUniqueUserId.getValue(), claims); } catch (DomainException e) { throw new IdentityStoreServerException(String.format("Failed to update claims of user - %s", uniqueUserId)); } }
@Override public List<Claim> getClaimsOfUser(String uniqueUserId) throws IdentityStoreException, UserNotFoundException { if (isNullOrEmpty(uniqueUserId)) { throw new IdentityStoreClientException("Invalid unique user id."); } SimpleEntry<Integer, String> decodedUniqueUserId = getDecodedUniqueEntityId(uniqueUserId); Domain domain = domains.get(decodedUniqueUserId.getKey()); try { return domain.getClaimsOfUser(decodedUniqueUserId.getValue()); } catch (DomainException e) { throw new IdentityStoreServerException(String.format("Failed to get claims of unique user - %s.", uniqueUserId), e); } }
@Override public void updateGroupClaims(String uniqueGroupId, List<Claim> claims) throws IdentityStoreException, GroupNotFoundException { if (isNullOrEmpty(uniqueGroupId)) { throw new IdentityStoreClientException("Invalid group unique id."); } SimpleEntry<Integer, String> decodedUniqueGroupId = getDecodedUniqueEntityId(uniqueGroupId); Domain domain = domains.get(decodedUniqueGroupId.getKey()); try { domain.updateGroupClaims(decodedUniqueGroupId.getValue(), claims); } catch (DomainException e) { throw new IdentityStoreServerException(String.format("Failed to update claims of group - %s", uniqueGroupId)); } }
@Override public void updateUserCredentials(String uniqueUserId, List<Callback> credentials) throws IdentityStoreException, UserNotFoundException { if (isNullOrEmpty(uniqueUserId)) { throw new IdentityStoreClientException("Invalid user unique id."); } SimpleEntry<Integer, String> decodedUniqueUserId = getDecodedUniqueEntityId(uniqueUserId); Domain domain = domains.get(decodedUniqueUserId.getKey()); try { domain.updateUserCredentials(decodedUniqueUserId.getValue(), credentials); } catch (DomainException e) { throw new IdentityStoreServerException(String.format("Failed to update credentials of user - %s", uniqueUserId)); } }
@Override public void updateUsersOfGroup(String uniqueGroupId, List<String> uniqueUserIds) throws IdentityStoreException { if (isNullOrEmpty(uniqueGroupId)) { throw new IdentityStoreClientException("Invalid group unique id."); } SimpleEntry<Integer, String> decodedUniqueGroupId = getDecodedUniqueEntityId(uniqueGroupId); List<String> domainGroupIds = new ArrayList<>(); if (uniqueUserIds != null && !uniqueUserIds.isEmpty()) { domainGroupIds = getDomainEntityIds(uniqueUserIds, decodedUniqueGroupId.getKey()); } Domain domain = domains.get(decodedUniqueGroupId.getKey()); try { domain.updateUsersOfGroup(decodedUniqueGroupId.getValue(), domainGroupIds); } catch (DomainException e) { throw new IdentityStoreServerException(String.format("Failed to update users of group - %s", uniqueGroupId)); } }
@Override public void updateGroupsOfUser(String uniqueUserId, List<String> uniqueGroupIds) throws IdentityStoreException { if (isNullOrEmpty(uniqueUserId)) { throw new IdentityStoreClientException("Invalid user unique id."); } SimpleEntry<Integer, String> decodedUniqueUserId = getDecodedUniqueEntityId(uniqueUserId); List<String> domainGroupIds = new ArrayList<>(); if (uniqueGroupIds != null && !uniqueGroupIds.isEmpty()) { domainGroupIds = getDomainEntityIds(uniqueGroupIds, decodedUniqueUserId.getKey()); } Domain domain = domains.get(decodedUniqueUserId.getKey()); try { domain.updateGroupsOfUser(decodedUniqueUserId.getValue(), domainGroupIds); } catch (DomainException e) { throw new IdentityStoreServerException(String.format("Failed to update groups of user - %s", uniqueUserId)); } }
@Override public void setUserState(String uniqueUserId, String targetState) throws IdentityStoreException, UserNotFoundException { if (isNullOrEmpty(uniqueUserId)) { throw new UserNotFoundException("Invalid unique user id."); } SimpleEntry<Integer, String> decodedUniqueUserId = getDecodedUniqueEntityId(uniqueUserId); Domain domain = domains.get(decodedUniqueUserId.getKey()); try { domain.setUserState(decodedUniqueUserId.getValue(), targetState); } catch (DomainException e) { throw new IdentityStoreServerException("Failed to set user state", e); } }
@Override public Group getGroup(Claim claim) throws IdentityStoreException, GroupNotFoundException { if (claim == null || isNullOrEmpty(claim.getValue())) { throw new IdentityStoreClientException("Invalid claim."); } Domain domain; try { domain = getPrimaryDomain(); } catch (DomainException e) { throw new IdentityStoreServerException("Error while retrieving the primary domain.", e); } return doGetGroup(claim, domain); }
@Override public User getUser(Claim claim) throws IdentityStoreException, UserNotFoundException { if (claim == null || isNullOrEmpty(claim.getValue())) { throw new IdentityStoreClientException("Provided claim is invalid."); } Domain domain; try { domain = getPrimaryDomain(); } catch (DomainException e) { throw new IdentityStoreServerException("Error while retrieving the primary domain.", e); } return doGetUser(claim, domain); }