@Inject BeanManager manager;
@Inject
public void init() throws IdentityConfigurationException, IdentityException
{
IdentityConfigurationMetaDataImpl metadata = new IdentityConfigurationMetaDataImpl();
// Create the identity store configuration
List<IdentityStoreConfigurationMetaData> stores = new ArrayList<IdentityStoreConfigurationMetaData>();
String defaultStoreId = null;
Set<Bean<?>> storeBeans = manager.getBeans(IdentityStoreConfiguration.class);
for (Bean<?> storeBean : storeBeans)
{
IdentityStoreConfiguration config = (IdentityStoreConfiguration) manager
.getReference(storeBean, IdentityStoreConfiguration.class,
manager.createCreationalContext(storeBean));
if (config.isConfigured())
{
IdentityStoreConfigurationMetaDataImpl storeConfig = new IdentityStoreConfigurationMetaDataImpl();
config.configure(storeConfig);
stores.add(storeConfig);
if (defaultStoreId == null && storeConfig.getId() != null)
{
defaultStoreId = storeConfig.getId();
}
}
}
metadata.setIdentityStores(stores);
// Create the default realm
RealmConfigurationMetaDataImpl realm = new RealmConfigurationMetaDataImpl();
realm.setId(getDefaultRealm());
realm.setIdentityMapping("USER");
//realm.setGroupTypeMappings(groupTypeMappings)
realm.setOptions(new HashMap<String,List<String>>());
List<RealmConfigurationMetaData> realms = new ArrayList<RealmConfigurationMetaData>();
realms.add(realm);
metadata.setRealms(realms);
if (stores.size() > 0)
{
List<IdentityRepositoryConfigurationMetaData> repositories = new ArrayList<IdentityRepositoryConfigurationMetaData>();
IdentityRepositoryConfigurationMetaDataImpl repository = new IdentityRepositoryConfigurationMetaDataImpl();
repository.setClassName(WrapperIdentityStoreRepository.class.getName());
repository.setDefaultAttributeStoreId(defaultAttributeStoreId != null ? defaultAttributeStoreId : defaultStoreId);
repository.setDefaultIdentityStoreId(defaultIdentityStoreId != null ? defaultIdentityStoreId : defaultStoreId);
List<IdentityStoreMappingMetaData> mappings = new ArrayList<IdentityStoreMappingMetaData>();
IdentityStoreMappingMetaDataImpl mapping = new IdentityStoreMappingMetaDataImpl();
List<String> identityObjectTypes = new ArrayList<String>();
identityObjectTypes.add("USER");
identityObjectTypes.add("GROUP");
mapping.setIdentityObjectTypeMappings(identityObjectTypes);
mapping.setIdentityStoreId(defaultIdentityStoreId != null ? defaultIdentityStoreId : defaultStoreId);
mappings.add(mapping);
repository.setIdentityStoreToIdentityObjectTypeMappings(mappings);
repositories.add(repository);
metadata.setRepositories(repositories);
}
IdentityConfigurationImpl config = new IdentityConfigurationImpl();
config.configure(metadata);