private boolean isUsernamePresent(UserBean userBean) { return userBean.getClaims().stream() .filter(claim -> USERNAME_CLAIM.equals(claim.getClaimUri()) && !isNullOrEmpty(claim.getValue())) .findAny() .isPresent(); }
/** * Initialization of JMS ConnectionFactory with the user specified properties. * * @param properties Properties to be added to the initial context. * @throws JMSConnectorException Thrown when initial context name is wrong or when creating connection factory. */ public JMSServerConnectionFactory(Properties properties) throws JMSConnectorException { super(properties); isSharedSubscription = Boolean.parseBoolean(properties.getProperty(JMSConstants.PARAM_IS_SHARED_SUBSCRIPTION)); noPubSubLocal = Boolean.valueOf(properties.getProperty(JMSConstants.PARAM_PUBSUB_NO_LOCAL)); subscriptionName = properties.getProperty(JMSConstants.PARAM_DURABLE_SUB_ID); if (isSharedSubscription && subscriptionName == null) { logger.warn("Subscription name is not given. Therefore declaring a non-shared subscription"); isSharedSubscription = false; } isDurable = !StringUtils.isNullOrEmptyAfterTrim(properties.getProperty(JMSConstants.PARAM_DURABLE_SUB_ID)); String msgSelector = properties.getProperty(JMSConstants.PARAM_MSG_SELECTOR); if (null != msgSelector) { messageSelector = msgSelector; } this.destinationName = properties.getProperty(JMSConstants.PARAM_DESTINATION_NAME); }
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()); }
/** * Initialization of JMS ConnectionFactory with the user specified properties. * * @param properties Properties to be added to the initial context. * @throws JMSConnectorException Thrown when initial context name is wrong or when creating connection factory. */ public JMSServerConnectionFactory(Properties properties) throws JMSConnectorException { super(properties); isSharedSubscription = Boolean.parseBoolean(properties.getProperty(JMSConstants.PARAM_IS_SHARED_SUBSCRIPTION)); noPubSubLocal = Boolean.valueOf(properties.getProperty(JMSConstants.PARAM_PUBSUB_NO_LOCAL)); subscriptionName = properties.getProperty(JMSConstants.PARAM_DURABLE_SUB_ID); if (isSharedSubscription && subscriptionName == null) { logger.warn("Subscription name is not given. Therefore declaring a non-shared subscription"); isSharedSubscription = false; } isDurable = !StringUtils.isNullOrEmptyAfterTrim(properties.getProperty(JMSConstants.PARAM_DURABLE_SUB_ID)); String msgSelector = properties.getProperty(JMSConstants.PARAM_MSG_SELECTOR); if (null != msgSelector) { messageSelector = msgSelector; } this.destinationName = properties.getProperty(JMSConstants.PARAM_DESTINATION_NAME); }
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 Map<String, String> resolveInheritingDialects(Map<String, Map<String, String>> initialMappings, ClaimMappingEntry claimMappingEntry) { Map<String, String> ownClaims = initialMappings.get(claimMappingEntry.getMappingDialectURI()); if (!StringUtils.isNullOrEmptyAfterTrim(claimMappingEntry.getInherits())) { Map<String, String> inheritingMap = initialMappings.get(claimMappingEntry.getInherits()); ownClaims.putAll(inheritingMap); return ownClaims; } else { return ownClaims; } }
/** * Get domain id and domain unique entity id. * * @param uniqueEntityId unique entity id. * @return domain and unique entity id. * @throws IdentityStoreException Identity Store Exception. */ private SimpleEntry<Integer, String> getDecodedUniqueEntityId(String uniqueEntityId) throws IdentityStoreException { String[] decodedUniqueEntityIdParts = uniqueEntityId.split("\\.", 2); if (decodedUniqueEntityIdParts.length != 2 || isNullOrEmpty(decodedUniqueEntityIdParts[0]) || isNullOrEmpty(decodedUniqueEntityIdParts[1])) { throw new IdentityStoreClientException("invalid unique entity id."); } int domainId; try { domainId = Integer.parseInt(decodedUniqueEntityIdParts[0]); } catch (NumberFormatException e) { throw new IdentityStoreClientException("invalid unique entity id."); } if (!domains.containsKey(domainId)) { throw new IdentityStoreClientException("invalid unique entity id."); } return new SimpleEntry<>(domainId, decodedUniqueEntityIdParts[1]); }
if (connectionFactoryType != null) { if (JMSConstants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(connectionFactoryType)) { boolean isDurable = !StringUtils.isNullOrEmptyAfterTrim( connectorConfig.get(JMSConstants.PARAM_SUB_DURABLE));
@Override public void updateUserProfile(String uniqueUserId, Map<String, String> updatedClaimsMap) throws UserPortalUIException { if (updatedClaimsMap == null || updatedClaimsMap.isEmpty()) { return; } List<Claim> updatedClaims = updatedClaimsMap.entrySet().stream() .filter(entry -> !StringUtils.isNullOrEmpty(entry.getKey())) .map(entry -> new Claim(IdentityMgtConstants.CLAIM_ROOT_DIALECT, entry.getKey(), entry.getValue())) .collect(Collectors.toList()); try { getRealmService().getIdentityStore().updateUserClaims(uniqueUserId, updatedClaims, null); } catch (IdentityStoreException | UserNotFoundException e) { String error = "Failed to updated user profile."; LOGGER.error(error, e); throw new UserPortalUIException(error); } }
if (connectionFactoryType != null) { if (JMSConstants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(connectionFactoryType)) { boolean isDurable = !StringUtils.isNullOrEmptyAfterTrim( connectorConfig.get(JMSConstants.PARAM_SUB_DURABLE));
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()); } }
readOnlyList.add(claimConfigEntry.getClaimURI()); if (!StringUtils.isNullOrEmptyAfterTrim(claimConfigEntry.getValidator())) { validatingList.add(claimConfigEntry.getClaimURI()); if (!StringUtils.isNullOrEmptyAfterTrim(claimConfigEntry.getVerifier())) { verifyingList.add(claimConfigEntry.getClaimURI()); if (!StringUtils.isNullOrEmptyAfterTrim(claimConfigEntry.getTransformer())) { transformingList.add(claimConfigEntry.getClaimURI());
/** * Reads domain configurations. * * @param storeConnectorConfigMap connector id to connector configuration map. * @return domain configurations. * @throws CarbonIdentityMgtConfigException */ public static List<DomainConfig> getDomainConfigs(Map<String, StoreConnectorConfig> storeConnectorConfigMap) throws CarbonIdentityMgtConfigException { DomainConfigFile domainConfigFile = buildDomainConfig(); if (domainConfigFile.getDomains().isEmpty()) { return Collections.emptyList(); } return domainConfigFile.getDomains().stream() .filter(Objects::nonNull) .filter(domainConfigEntry -> !StringUtils.isNullOrEmpty(domainConfigEntry.getName())) .map(domainConfigEntry -> getDomainConfig(storeConnectorConfigMap, domainConfigEntry)) .collect(Collectors.toList()); }
private Map<String, List<String>> getConnectorIdToAttributeNameMap(List<MetaClaim> metaClaims) { Map<String, List<String>> connectorIdToAttributeNameMap = new HashMap<>(); if (!metaClaims.isEmpty()) { metaClaims.stream() .filter(Objects::nonNull) .filter(metaClaim -> !isNullOrEmpty(metaClaim.getClaimUri())) .forEach(metaClaim -> { Optional<MetaClaimMapping> optional = metaClaimMappings.stream() .filter(metaClaimMapping -> metaClaimMapping.getMetaClaim().getClaimUri() .equals(metaClaim.getClaimUri())) .findFirst(); if (optional.isPresent()) { MetaClaimMapping metaClaimMapping = optional.get(); List<String> attributeNames = connectorIdToAttributeNameMap.get(metaClaimMapping .getIdentityStoreConnectorId()); if (attributeNames == null) { attributeNames = new ArrayList<String>(); connectorIdToAttributeNameMap.put(metaClaimMapping .getIdentityStoreConnectorId(), attributeNames); } attributeNames.add(metaClaimMapping.getAttributeName()); } } ); } return connectorIdToAttributeNameMap; }
@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 User getUser(Claim claim, String domainName) throws IdentityStoreException, UserNotFoundException { if (isNullOrEmpty(domainName)) { return getUser(claim); } if (claim == null || isNullOrEmpty(claim.getValue())) { throw new IdentityStoreClientException("Invalid claim."); } Domain domain; try { domain = getDomainFromDomainName(domainName); } catch (DomainException e) { throw new IdentityStoreServerException(String.format("Error while retrieving domain from the domain name " + "- %s", domainName), e); } return doGetUser(claim, domain); }
@Override public Group getGroup(Claim claim, String domainName) throws IdentityStoreException, GroupNotFoundException { if (isNullOrEmpty(domainName)) { return getGroup(claim); } if (claim == null || isNullOrEmpty(claim.getValue())) { throw new IdentityStoreClientException("Invalid claim."); } Domain domain; try { domain = getDomainFromDomainName(domainName); } catch (DomainException e) { throw new IdentityStoreServerException(String.format("Error while retrieving domain from the domain name " + "- %s", domainName), e); } return doGetGroup(claim, domain); }
@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)); } }
@Override public List<Claim> getClaimsOfUser(String uniqueUserId, List<MetaClaim> metaClaims) throws UserPortalUIException { List<Claim> claimList = null; if (StringUtils.isNullOrEmpty(uniqueUserId)) { throw new UserPortalUIException("Invalid unique user id."); } if (metaClaims != null && !metaClaims.isEmpty()) { try { claimList = getRealmService().getIdentityStore().getClaimsOfUser(uniqueUserId, metaClaims); } catch (IdentityStoreException | UserNotFoundException e) { String error = "Failed to get claims of the user."; LOGGER.error(error, e); throw new UserPortalUIException(error); } } else { claimList = Collections.emptyList(); } return claimList; }