@Override public <T extends IdentityStore<?>> T getStoreForIdentityOperation(IdentityContext context, Class<T> storeType, Class<? extends AttributedType> type, IdentityOperation operation) { checkSupportedTypes(context.getPartition(), type); IdentityConfiguration identityConfiguration = getConfigurationForPartition(context, context.getPartition()); T identityStore = lookupStore(context, identityConfiguration, type, operation); if (identityStore == null) { throw MESSAGES.attributedTypeUnsupportedOperation(type, operation, type, operation); } return identityStore; }
public DefaultStoreSelector(PartitionManagerConfiguration configuration) { this.configuration = configuration; Map<IdentityConfiguration, Map<IdentityStoreConfiguration, IdentityStore<?>>> configuredStores = new HashMap<IdentityConfiguration, Map<IdentityStoreConfiguration, IdentityStore<?>>>(); for (IdentityConfiguration config : this.configuration.getConfigurations()) { Map<IdentityStoreConfiguration, IdentityStore<?>> storeMap = new HashMap<IdentityStoreConfiguration, IdentityStore<?>>(); for (IdentityStoreConfiguration storeConfig : config.getStoreConfiguration()) { storeMap.put(storeConfig, createIdentityStore(storeConfig)); } configuredStores.put(config, Collections.unmodifiableMap(storeMap)); } this.stores = Collections.unmodifiableMap(configuredStores); }
@Override public Set<CredentialStore<?>> getStoresForCredentialStorage(final IdentityContext context, Class<? extends CredentialStorage> storageClass) { IdentityConfiguration identityConfiguration = getConfigurationForPartition(context, context.getPartition()); Map<IdentityStoreConfiguration, IdentityStore<?>> storesConfig = this.stores.get(identityConfiguration); Set<CredentialStore<?>> credentialStores = new HashSet<CredentialStore<?>>(); if (storesConfig != null) { for (IdentityStoreConfiguration storeConfig : storesConfig.keySet()) { if (storeConfig.supportsCredential()) { for (Class<? extends CredentialHandler> credentialHandler : storeConfig.getCredentialHandlers()) { SupportsCredentials supportedCredentials = credentialHandler.getAnnotation(SupportsCredentials.class); if (supportedCredentials != null) { if (supportedCredentials.credentialStorage().equals(storageClass)) { CredentialStore<?> credentialStore = (CredentialStore<?>) getIdentityStoreAndInitializeContext(context, identityConfiguration, storeConfig); credentialStores.add(credentialStore); } } } } } } return credentialStores; }
@Override public IdentityStore<?> getStoreForRelationshipOperation(IdentityContext context, Class<? extends Relationship> relationshipClass, Relationship relationship, IdentityOperation operation) { Set<Partition> partitions = getRelationshipPartitions(relationship); IdentityStore<?> store = null; IdentityConfiguration config = getConfigurationForPartition(context, partitions.iterator().next()); store = getIdentityStoreAndInitializeContext(context, config, storeConfig); IdentityConfiguration config = getConfigurationForPartition(context, partition); store = getIdentityStoreAndInitializeContext(context, config, storeConfig); store = getIdentityStoreAndInitializeContext(context, cfg, storeConfig);
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; }
IdentityConfiguration getConfigurationForPartition(IdentityContext identityContext, Partition partition) { IdentityConfiguration partitionManagementConfig = this.configuration.getPartitionManagementConfig(); if (partitionManagementConfig == null) { Collection<IdentityConfiguration> configurations = this.configuration.getConfigurations(); if (configurations.size() == 1) { return configurations.iterator().next(); } } if (!this.partitionConfigurations.containsKey(partition)) { PartitionStore<?> store = getStoreForPartitionOperation(identityContext, partition.getClass()); partitionConfigurations.put(partition, this.configuration.getConfigurationByName(store.getConfigurationName(identityContext, partition))); } IdentityConfiguration identityConfiguration = partitionConfigurations.get(partition); if (identityConfiguration == null) { throw MESSAGES.partitionReferencesInvalidConfiguration(partition); } return identityConfiguration; }
this.storeSelector = new DefaultStoreSelector(this);
@Override public IdentityStore<?> getStoreForRelationshipOperation(IdentityContext context, Class<? extends Relationship> relationshipClass, Relationship relationship, IdentityOperation operation) { Set<Partition> partitions = getRelationshipPartitions(relationship); IdentityStore<?> store = null; IdentityConfiguration config = getConfigurationForPartition(context, partitions.iterator().next()); store = getIdentityStoreAndInitializeContext(context, config, storeConfig); IdentityConfiguration config = getConfigurationForPartition(context, partition); store = getIdentityStoreAndInitializeContext(context, config, storeConfig); store = getIdentityStoreAndInitializeContext(context, cfg, storeConfig);
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; }
IdentityConfiguration getConfigurationForPartition(IdentityContext identityContext, Partition partition) { IdentityConfiguration partitionManagementConfig = this.configuration.getPartitionManagementConfig(); if (partitionManagementConfig == null) { Collection<IdentityConfiguration> configurations = this.configuration.getConfigurations(); if (configurations.size() == 1) { return configurations.iterator().next(); } } if (!this.partitionConfigurations.containsKey(partition)) { PartitionStore<?> store = getStoreForPartitionOperation(identityContext, partition.getClass()); partitionConfigurations.put(partition, this.configuration.getConfigurationByName(store.getConfigurationName(identityContext, partition))); } IdentityConfiguration identityConfiguration = partitionConfigurations.get(partition); if (identityConfiguration == null) { throw MESSAGES.partitionReferencesInvalidConfiguration(partition); } return identityConfiguration; }
this.storeSelector = new DefaultStoreSelector(this);
@Override public Set<CredentialStore<?>> getStoresForCredentialStorage(final IdentityContext context, Class<? extends CredentialStorage> storageClass) { IdentityConfiguration identityConfiguration = getConfigurationForPartition(context, context.getPartition()); Map<IdentityStoreConfiguration, IdentityStore<?>> storesConfig = this.stores.get(identityConfiguration); Set<CredentialStore<?>> credentialStores = new HashSet<CredentialStore<?>>(); if (storesConfig != null) { for (IdentityStoreConfiguration storeConfig : storesConfig.keySet()) { if (storeConfig.supportsCredential()) { for (Class<? extends CredentialHandler> credentialHandler : storeConfig.getCredentialHandlers()) { SupportsCredentials supportedCredentials = credentialHandler.getAnnotation(SupportsCredentials.class); if (supportedCredentials != null) { if (supportedCredentials.credentialStorage().equals(storageClass)) { CredentialStore<?> credentialStore = (CredentialStore<?>) getIdentityStoreAndInitializeContext(context, identityConfiguration, storeConfig); credentialStores.add(credentialStore); } } } } } } return credentialStores; }
@Override public <T extends IdentityStore<?>> T getStoreForIdentityOperation(IdentityContext context, Class<T> storeType, Class<? extends AttributedType> type, IdentityOperation operation) { checkSupportedTypes(context.getPartition(), type); IdentityConfiguration identityConfiguration = getConfigurationForPartition(context, context.getPartition()); T identityStore = lookupStore(context, identityConfiguration, type, operation); if (identityStore == null) { throw MESSAGES.attributedTypeUnsupportedOperation(type, operation, type, operation); } return identityStore; }
@Override public <T extends AttributeStore<?>> T getStoreForAttributeOperation(IdentityContext context) { IdentityConfiguration attributeManagementConfig = this.configuration.getAttributeManagementConfig(); if (attributeManagementConfig != null) { Map<IdentityStoreConfiguration, IdentityStore<?>> configStores = stores.get(attributeManagementConfig); for (IdentityStoreConfiguration cfg : configStores.keySet()) { if (cfg.supportsAttribute()) { T store = getIdentityStoreAndInitializeContext(context, attributeManagementConfig, cfg); if (!AttributeStore.class.isInstance(store)) { throw MESSAGES.storeUnexpectedType(store.getClass(), AttributeStore.class); } return store; } } } return null; }
public DefaultStoreSelector(PartitionManagerConfiguration configuration) { this.configuration = configuration; Map<IdentityConfiguration, Map<IdentityStoreConfiguration, IdentityStore<?>>> configuredStores = new HashMap<IdentityConfiguration, Map<IdentityStoreConfiguration, IdentityStore<?>>>(); for (IdentityConfiguration config : this.configuration.getConfigurations()) { Map<IdentityStoreConfiguration, IdentityStore<?>> storeMap = new HashMap<IdentityStoreConfiguration, IdentityStore<?>>(); for (IdentityStoreConfiguration storeConfig : config.getStoreConfiguration()) { storeMap.put(storeConfig, createIdentityStore(storeConfig)); } configuredStores.put(config, Collections.unmodifiableMap(storeMap)); } this.stores = Collections.unmodifiableMap(configuredStores); }
@Override public Set<IdentityStore<?>> getStoresForIdentityQuery(final IdentityContext context, final Class<? extends IdentityType> identityType) { IdentityConfiguration identityConfiguration = getConfigurationForPartition(context, context.getPartition()); Map<Class<? extends IdentityType>, Set<IdentityStoreConfiguration>> cachedStoresForType = this.identityQueryStoresCache.get(context.getPartition().getName()); if (cachedStoresForType != null) { Set<IdentityStoreConfiguration> storeConfigs = cachedStoresForType.get(identityType); if (storeConfigs != null) { Set<IdentityStore<?>> identityStores = new HashSet<IdentityStore<?>>(); for (IdentityStoreConfiguration storeConfig : storeConfigs) { identityStores.add(getIdentityStoreAndInitializeContext(context, identityConfiguration, storeConfig)); } return identityStores; } } Set<IdentityStore<?>> identityStores = new HashSet<IdentityStore<?>>(); Set<IdentityStoreConfiguration> identityStoresConfig = new HashSet<IdentityStoreConfiguration>(); cachedStoresForType = new HashMap<Class<? extends IdentityType>, Set<IdentityStoreConfiguration>>(); cachedStoresForType.put(identityType, identityStoresConfig); for (IdentityStoreConfiguration storeConfig : identityConfiguration.getStoreConfiguration()) { if (storeConfig.supportsType(identityType, read)) { identityStores.add(getIdentityStoreAndInitializeContext(context, identityConfiguration, storeConfig)); identityStoresConfig.add(storeConfig); } } if (identityStores.isEmpty()) { throw MESSAGES.attributedTypeUnsupportedOperation(identityType, read, identityType, read); } this.identityQueryStoresCache.put(context.getPartition().getName(), cachedStoresForType); return identityStores; }
@Override public <T extends AttributeStore<?>> T getStoreForAttributeOperation(IdentityContext context) { IdentityConfiguration attributeManagementConfig = this.configuration.getAttributeManagementConfig(); if (attributeManagementConfig != null) { Map<IdentityStoreConfiguration, IdentityStore<?>> configStores = stores.get(attributeManagementConfig); for (IdentityStoreConfiguration cfg : configStores.keySet()) { if (cfg.supportsAttribute()) { T store = getIdentityStoreAndInitializeContext(context, attributeManagementConfig, cfg); if (!AttributeStore.class.isInstance(store)) { throw MESSAGES.storeUnexpectedType(store.getClass(), AttributeStore.class); } return store; } } } return null; }
@Override public Set<IdentityStore<?>> getStoresForIdentityQuery(final IdentityContext context, final Class<? extends IdentityType> identityType) { IdentityConfiguration identityConfiguration = getConfigurationForPartition(context, context.getPartition()); Map<Class<? extends IdentityType>, Set<IdentityStoreConfiguration>> cachedStoresForType = this.identityQueryStoresCache.get(context.getPartition().getName()); if (cachedStoresForType != null) { Set<IdentityStoreConfiguration> storeConfigs = cachedStoresForType.get(identityType); if (storeConfigs != null) { Set<IdentityStore<?>> identityStores = new HashSet<IdentityStore<?>>(); for (IdentityStoreConfiguration storeConfig : storeConfigs) { identityStores.add(getIdentityStoreAndInitializeContext(context, identityConfiguration, storeConfig)); } return identityStores; } } Set<IdentityStore<?>> identityStores = new HashSet<IdentityStore<?>>(); Set<IdentityStoreConfiguration> identityStoresConfig = new HashSet<IdentityStoreConfiguration>(); cachedStoresForType = new HashMap<Class<? extends IdentityType>, Set<IdentityStoreConfiguration>>(); cachedStoresForType.put(identityType, identityStoresConfig); for (IdentityStoreConfiguration storeConfig : identityConfiguration.getStoreConfiguration()) { if (storeConfig.supportsType(identityType, read)) { identityStores.add(getIdentityStoreAndInitializeContext(context, identityConfiguration, storeConfig)); identityStoresConfig.add(storeConfig); } } if (identityStores.isEmpty()) { throw MESSAGES.attributedTypeUnsupportedOperation(identityType, read, identityType, read); } this.identityQueryStoresCache.put(context.getPartition().getName(), cachedStoresForType); return identityStores; }
@Override public <T extends PartitionStore<?>> T getStoreForPartitionOperation(IdentityContext context, Class<? extends Partition> partitionClass) { IdentityConfiguration partitionManagementConfig = this.configuration.getPartitionManagementConfig(); Map<IdentityStoreConfiguration, IdentityStore<?>> configStores = stores.get(partitionManagementConfig); for (IdentityStoreConfiguration cfg : configStores.keySet()) { if (cfg.supportsType(partitionClass, create)) { T store = getIdentityStoreAndInitializeContext(context, partitionManagementConfig, cfg); if (!PartitionStore.class.isInstance(store)) { throw MESSAGES.storeUnexpectedType(store.getClass(), PartitionStore.class); } return store; } } throw MESSAGES.storeNotFound(PartitionStore.class, partitionClass); }
@Override public PermissionStore getStoreForPermissionOperation(IdentityContext context) { IdentityConfiguration identityConfiguration = getConfigurationForPartition(context, context.getPartition()); if (identityConfiguration == null) { for (IdentityConfiguration configuration : this.configuration.getConfigurations()) { for (IdentityStoreConfiguration storeConfig : configuration.getStoreConfiguration()) { if (storeConfig.supportsPermissions()) { return (PermissionStore) getIdentityStoreAndInitializeContext(context, configuration, storeConfig); } } } } else { for (IdentityStoreConfiguration storeConfig : identityConfiguration.getStoreConfiguration()) { if (storeConfig.supportsPermissions()) { return (PermissionStore) getIdentityStoreAndInitializeContext(context, identityConfiguration, storeConfig); } } } return null; }