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; }
@Override public void createRealm(Realm realm) { storeFactory.createPartitionStore(partitionStoreConfig).createPartition(realm); }
@Override public Realm getRealm(String name) { return storeFactory.createPartitionStore(partitionStoreConfig).getRealm(name); }
@Override public <T extends Partition> List<T> getPartitions(Class<T> partitionClass) { if (partitionClass == null) { throw MESSAGES.nullArgument("Partition class"); } List<T> partitions = new ArrayList<T>(); if (!getConfiguration().supportsPartition()) { partitions.add((T) createDefaultPartition()); } else { try { IdentityContext identityContext = getIdentityContext(); partitions.addAll(getStoreSelector().getStoreForPartitionOperation(identityContext, partitionClass).<T>get(identityContext, partitionClass)); for (T partition : partitions) { loadAttributes(identityContext, partition); } } catch (Exception e) { throw MESSAGES.partitionGetFailed(partitionClass, "not specified", e); } } return partitions; }
@Override protected void doRemove(Partition attributedType) { checkPartitionManagementSupported(); IdentityManager identityManager = createIdentityManager(attributedType); IdentityQueryBuilder queryBuilder = identityManager.getQueryBuilder(); IdentityQuery<IdentityType> query = queryBuilder.createIdentityQuery(IdentityType.class); for (IdentityType identityType : query.getResultList()) { identityManager.remove(identityType); } IdentityContext identityContext = getIdentityContext(); getStoreSelector().getStoreForPartitionOperation(identityContext, attributedType.getClass()).remove(identityContext, attributedType); }
@Override protected void doUpdate(Partition attributedType) { checkPartitionManagementSupported(); IdentityContext identityContext = getIdentityContext(); getStoreSelector().getStoreForPartitionOperation(identityContext, attributedType.getClass()).update(identityContext, attributedType); }
@Override public void add(Partition partition, String configurationName) throws IdentityManagementException { checkPartitionManagementSupported(); if (partition == null) { throw MESSAGES.nullArgument("Partition"); } if (isNullOrEmpty(configurationName)) { configurationName = getConfiguration().getDefaultConfigurationName(); } if (getConfiguration().getConfigurationByName(configurationName) != null) { checkUniqueness(partition); try { IdentityContext identityContext = getIdentityContext(); getStoreSelector().getStoreForPartitionOperation(identityContext, partition.getClass()).add(identityContext, partition, configurationName); addAttributes(identityContext, partition); fireEvent(new PartitionCreatedEvent(partition, this)); } catch (Exception e) { throw MESSAGES.partitionAddFailed(partition, configurationName, e); } } }
@Override public <T extends Partition> T lookupById(final Class<T> partitionClass, final String id) { if (partitionClass == null) { throw MESSAGES.nullArgument("Partition class"); } if (isNullOrEmpty(id)) { throw MESSAGES.nullArgument("Partition identifier"); } if (!getConfiguration().supportsPartition()) { return (T) createDefaultPartition(); } try { IdentityContext identityContext = getIdentityContext(); T partition = getStoreSelector().getStoreForPartitionOperation(identityContext, partitionClass).<T>lookupById(identityContext, partitionClass, id); if (partition != null) { loadAttributes(identityContext, (T) partition); } return partition; } catch (Exception e) { throw MESSAGES.partitionGetFailed(partitionClass, id, e); } }
@Override public void removeRealm(Realm realm) { storeFactory.createPartitionStore(partitionStoreConfig).removePartition(realm); }
@Override public Tier getTier(String id) { return storeFactory.createPartitionStore(partitionStoreConfig).getTier(id); }
@Override public <T extends Partition> List<T> getPartitions(Class<T> partitionClass) { if (partitionClass == null) { throw MESSAGES.nullArgument("Partition class"); } List<T> partitions = new ArrayList<T>(); if (!getConfiguration().supportsPartition()) { partitions.add((T) createDefaultPartition()); } else { try { IdentityContext identityContext = getIdentityContext(); partitions.addAll(getStoreSelector().getStoreForPartitionOperation(identityContext, partitionClass).<T>get(identityContext, partitionClass)); for (T partition : partitions) { loadAttributes(identityContext, partition); } } catch (Exception e) { throw MESSAGES.partitionGetFailed(partitionClass, "not specified", e); } } return partitions; }
@Override protected void doRemove(Partition attributedType) { checkPartitionManagementSupported(); IdentityManager identityManager = createIdentityManager(attributedType); IdentityQueryBuilder queryBuilder = identityManager.getQueryBuilder(); IdentityQuery<IdentityType> query = queryBuilder.createIdentityQuery(IdentityType.class); for (IdentityType identityType : query.getResultList()) { identityManager.remove(identityType); } IdentityContext identityContext = getIdentityContext(); getStoreSelector().getStoreForPartitionOperation(identityContext, attributedType.getClass()).remove(identityContext, attributedType); }
@Override protected void doUpdate(Partition attributedType) { checkPartitionManagementSupported(); IdentityContext identityContext = getIdentityContext(); getStoreSelector().getStoreForPartitionOperation(identityContext, attributedType.getClass()).update(identityContext, attributedType); }
@Override public void add(Partition partition, String configurationName) throws IdentityManagementException { checkPartitionManagementSupported(); if (partition == null) { throw MESSAGES.nullArgument("Partition"); } if (isNullOrEmpty(configurationName)) { configurationName = getConfiguration().getDefaultConfigurationName(); } if (getConfiguration().getConfigurationByName(configurationName) != null) { checkUniqueness(partition); try { IdentityContext identityContext = getIdentityContext(); getStoreSelector().getStoreForPartitionOperation(identityContext, partition.getClass()).add(identityContext, partition, configurationName); addAttributes(identityContext, partition); fireEvent(new PartitionCreatedEvent(partition, this)); } catch (Exception e) { throw MESSAGES.partitionAddFailed(partition, configurationName, e); } } }
@Override public <T extends Partition> T lookupById(final Class<T> partitionClass, final String id) { if (partitionClass == null) { throw MESSAGES.nullArgument("Partition class"); } if (isNullOrEmpty(id)) { throw MESSAGES.nullArgument("Partition identifier"); } if (!getConfiguration().supportsPartition()) { return (T) createDefaultPartition(); } try { IdentityContext identityContext = getIdentityContext(); T partition = getStoreSelector().getStoreForPartitionOperation(identityContext, partitionClass).<T>lookupById(identityContext, partitionClass, id); if (partition != null) { loadAttributes(identityContext, (T) partition); } return partition; } catch (Exception e) { throw MESSAGES.partitionGetFailed(partitionClass, id, e); } }
@Override public void removeTier(Tier tier) { storeFactory.createPartitionStore(partitionStoreConfig).removePartition(tier); }
@Override public <T extends Partition> T getPartition(Class<T> partitionClass, String name) { if (partitionClass == null) { throw MESSAGES.nullArgument("Partition class"); } if (isNullOrEmpty(name)) { throw MESSAGES.nullArgument("Partition name"); } if (!getConfiguration().supportsPartition()) { return (T) createDefaultPartition(); } try { IdentityContext identityContext = getIdentityContext(); T partition = getStoreSelector().getStoreForPartitionOperation(identityContext, partitionClass).<T>get(identityContext, partitionClass, name); if (partition != null) { loadAttributes(identityContext, (T) partition); } return partition; } catch (Exception e) { throw MESSAGES.partitionGetFailed(partitionClass, name, e); } }
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; }
@Override public void createTier(Tier tier) { storeFactory.createPartitionStore(partitionStoreConfig).createPartition(tier); }
@Override public <T extends Partition> T getPartition(Class<T> partitionClass, String name) { if (partitionClass == null) { throw MESSAGES.nullArgument("Partition class"); } if (isNullOrEmpty(name)) { throw MESSAGES.nullArgument("Partition name"); } if (!getConfiguration().supportsPartition()) { return (T) createDefaultPartition(); } try { IdentityContext identityContext = getIdentityContext(); T partition = getStoreSelector().getStoreForPartitionOperation(identityContext, partitionClass).<T>get(identityContext, partitionClass, name); if (partition != null) { loadAttributes(identityContext, (T) partition); } return partition; } catch (Exception e) { throw MESSAGES.partitionGetFailed(partitionClass, name, e); } }