@Override public Set<IdentityStore<?>> getStoresForRelationshipQuery( IdentityContext context, Class<? extends Relationship> relationshipClass, Set<Partition> partitions) { Set<IdentityStore<?>> identityStores = new HashSet<IdentityStore<?>>(); // If _no_ parameters have been specified for the query at all, we return all stores that // support the // specified relationship class if (partitions.isEmpty()) { for (IdentityConfiguration config : configurations) { if (config.getRelationshipPolicy().isGlobalRelationshipSupported(relationshipClass) || config.getRelationshipPolicy().isSelfRelationshipSupported(relationshipClass)) { for (IdentityStoreConfiguration storeConfig : config.getStoreConfiguration()) { if (storeConfig.supportsType(relationshipClass, IdentityOperation.create) || Relationship.class.equals(relationshipClass)) { identityStores.add( getIdentityStoreAndInitializeContext(context, config, storeConfig)); } } } } } else { for (Partition partition : partitions) { IdentityConfiguration config = getConfigurationForPartition(partition); if (config.getRelationshipPolicy().isGlobalRelationshipSupported(relationshipClass)) { for (IdentityStoreConfiguration storeConfig : config.getStoreConfiguration()) { if (storeConfig.supportsType(relationshipClass, IdentityOperation.create) || Relationship.class.equals(relationshipClass)) { identityStores.add( getIdentityStoreAndInitializeContext(context, config, storeConfig)); } } } } } if (identityStores.isEmpty()) { throw MESSAGES.attributedTypeUnsupportedOperation( relationshipClass, IdentityOperation.read, relationshipClass, IdentityOperation.read); } return identityStores; }
private boolean isPartitionSupported(final List<IdentityConfiguration> configurations) { for (IdentityConfiguration configuration : configurations) { for (IdentityStoreConfiguration storeConfig : configuration.getStoreConfiguration()) { if (storeConfig.supportsPartition() && storeConfig.supportsType(Realm.class, IdentityOperation.create)) { return true; } } } return false; }
public <T extends IdentityStore<?>> T lookupStore( IdentityContext context, IdentityConfiguration configuration, Class<? extends AttributedType> type, IdentityOperation operation) { for (IdentityStoreConfiguration storeConfig : configuration.getStoreConfiguration()) { if (storeConfig.supportsType(type, operation)) { return getIdentityStoreAndInitializeContext(context, configuration, storeConfig); } } return null; }
@Override public <T extends PartitionStore<?>> T getStoreForPartitionOperation(IdentityContext context) { Map<IdentityStoreConfiguration, IdentityStore<?>> configStores = stores.get(this.partitionManagementConfig); for (IdentityStoreConfiguration cfg : configStores.keySet()) { if (cfg.supportsType(Partition.class, IdentityOperation.create)) { T store = getIdentityStoreAndInitializeContext(context, this.partitionManagementConfig, cfg); if (!PartitionStore.class.isInstance(store)) { throw MESSAGES.storeUnexpectedType(store.getClass(), PartitionStore.class); } return store; } } throw MESSAGES.storeNotFound(PartitionStore.class); }
@Override public Set<IdentityStore<?>> getStoresForIdentityQuery( final IdentityContext context, final Class<? extends IdentityType> identityType) { Set<IdentityStore<?>> identityStores = new HashSet<IdentityStore<?>>(); for (IdentityConfiguration configuration : this.configurations) { for (IdentityStoreConfiguration storeConfig : configuration.getStoreConfiguration()) { if (storeConfig.supportsType(identityType, IdentityOperation.read) || IdentityType.class.equals(identityType)) { identityStores.add( getIdentityStoreAndInitializeContext(context, configuration, storeConfig)); } } } if (identityStores.isEmpty()) { throw MESSAGES.attributedTypeUnsupportedOperation( identityType, IdentityOperation.read, identityType, IdentityOperation.read); } return identityStores; }
@Override public IdentityStore<?> getStoreForRelationshipOperation( IdentityContext context, Class<? extends Relationship> relationshipClass, Relationship relationship, IdentityOperation operation) { Set<Partition> partitions = relationshipMetadata.getRelationshipPartitions(relationship); IdentityStore<?> store = null; // Check if the partition can manage its own relationship if (partitions.size() == 1) { IdentityConfiguration config; if (this.partitionManagementConfig != null) { config = getConfigurationForPartition(partitions.iterator().next()); } else { config = this.configurations.iterator().next(); } if (config.getRelationshipPolicy().isSelfRelationshipSupported(relationshipClass)) { for (IdentityStoreConfiguration storeConfig : config.getStoreConfiguration()) { if (storeConfig.supportsType(relationshipClass, operation)) { store = getIdentityStoreAndInitializeContext(context, config, storeConfig); } } } } else { // This is a multi-partition relationship - use the configuration that supports the global // relationship type for (Partition partition : partitions) { IdentityConfiguration config = getConfigurationForPartition(partition); if (config.getRelationshipPolicy().isGlobalRelationshipSupported(relationshipClass)) { for (IdentityStoreConfiguration storeConfig : config.getStoreConfiguration()) { if (storeConfig.supportsType(relationshipClass, operation)) { store = getIdentityStoreAndInitializeContext(context, config, storeConfig); } } } } } // If none of the participating partition configurations support the relationship, try to find // another configuration // that supports the global relationship as a last ditch effort if (store == null) { for (IdentityConfiguration cfg : configurations) { if (cfg.getRelationshipPolicy().isGlobalRelationshipSupported(relationshipClass)) { // found one for (IdentityStoreConfiguration storeConfig : cfg.getStoreConfiguration()) { if (storeConfig.supportsType(relationshipClass, operation)) { store = getIdentityStoreAndInitializeContext(context, cfg, storeConfig); } } } } } if (store == null) { throw MESSAGES.attributedTypeUnsupportedOperation( relationshipClass, operation, relationshipClass, operation); } return store; }