Search in sources :

Example 1 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager in project oxAuth by GluuFederation.

the class AppInitializer method reloadConfiguration.

private void reloadConfiguration() {
    PersistenceEntryManager localPersistenceEntryManager = persistenceEntryManagerInstance.get();
    log.trace("Attempting to use {}: {}", ApplicationFactory.PERSISTENCE_ENTRY_MANAGER_NAME, localPersistenceEntryManager.getOperationService());
    GluuConfiguration newConfiguration = loadConfiguration(localPersistenceEntryManager, "oxIDPAuthentication", "oxAuthenticationMode");
    List<GluuLdapConfiguration> newPersistenceAuthConfigs = loadPersistenceAuthConfigs(newConfiguration);
    if (!this.persistenceAuthConfigs.equals(newPersistenceAuthConfigs)) {
        recreatePersistenceAuthEntryManagers(newPersistenceAuthConfigs);
        this.persistenceAuthConfigs = newPersistenceAuthConfigs;
        event.select(ReloadAuthScript.Literal.INSTANCE).fire(ExternalAuthenticationService.MODIFIED_INTERNAL_TYPES_EVENT_TYPE);
    }
    setDefaultAuthenticationMethod(newConfiguration);
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) GluuConfiguration(org.oxauth.persistence.model.configuration.GluuConfiguration) GluuLdapConfiguration(org.gluu.model.ldap.GluuLdapConfiguration)

Example 2 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager in project oxAuth by GluuFederation.

the class AppInitializer method destroy.

public void destroy(@Observes @BeforeDestroyed(ApplicationScoped.class) ServletContext init) {
    log.info("Stopping services and closing DB connections at server shutdown...");
    log.debug("Checking who intiated destory", new Throwable());
    metricService.close();
    PersistenceEntryManager persistenceEntryManager = persistenceEntryManagerInstance.get();
    closePersistenceEntryManager(persistenceEntryManager, ApplicationFactory.PERSISTENCE_ENTRY_MANAGER_NAME);
    List<PersistenceEntryManager> persistenceAuthEntryManagers = persistenceAuthEntryManagerInstance.get();
    closePersistenceEntryManagers(persistenceAuthEntryManagers);
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager)

Example 3 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager in project oxAuth by GluuFederation.

the class AppInitializer method createMetricPersistenceEntryManager.

@Produces
@ApplicationScoped
@Named(ApplicationFactory.PERSISTENCE_METRIC_ENTRY_MANAGER_NAME)
@ReportMetric
public PersistenceEntryManager createMetricPersistenceEntryManager() {
    Properties connectionProperties = prepareCustomPersistanceProperties(ApplicationFactory.PERSISTENCE_METRIC_CONFIG_GROUP_NAME);
    PersistenceEntryManager persistenceEntryManager = applicationFactory.getPersistenceEntryManagerFactory().createEntryManager(connectionProperties);
    log.info("Created {}: {} with operation service: {}", new Object[] { ApplicationFactory.PERSISTENCE_METRIC_ENTRY_MANAGER_NAME, persistenceEntryManager, persistenceEntryManager.getOperationService() });
    externalPersistenceExtensionService.executePersistenceExtensionAfterCreate(connectionProperties, persistenceEntryManager);
    return persistenceEntryManager;
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) Properties(java.util.Properties) Named(javax.inject.Named) Produces(javax.enterprise.inject.Produces) ReportMetric(org.gluu.service.metric.inject.ReportMetric) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 4 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager in project oxAuth by GluuFederation.

the class AppInitializer method createPersistenceAuthEntryManager.

@Produces
@ApplicationScoped
@Named(ApplicationFactory.PERSISTENCE_AUTH_ENTRY_MANAGER_NAME)
public List<PersistenceEntryManager> createPersistenceAuthEntryManager() {
    List<PersistenceEntryManager> persistenceAuthEntryManagers = new ArrayList<PersistenceEntryManager>();
    if (this.persistenceAuthConfigs.size() == 0) {
        return persistenceAuthEntryManagers;
    }
    PersistenceEntryManagerFactory persistenceEntryManagerFactory = applicationFactory.getPersistenceEntryManagerFactory(LdapEntryManagerFactory.class);
    List<Properties> persistenceAuthProperties = prepareAuthConnectionProperties(this.persistenceAuthConfigs, persistenceEntryManagerFactory.getPersistenceType());
    log.trace("Attempting to create LDAP auth PersistenceEntryManager with properties: {}", persistenceAuthProperties);
    for (int i = 0; i < persistenceAuthProperties.size(); i++) {
        PersistenceEntryManager persistenceAuthEntryManager = persistenceEntryManagerFactory.createEntryManager(persistenceAuthProperties.get(i));
        log.debug("Created {}#{}: {}", new Object[] { ApplicationFactory.PERSISTENCE_AUTH_ENTRY_MANAGER_NAME, i, persistenceAuthEntryManager });
        persistenceAuthEntryManagers.add(persistenceAuthEntryManager);
        externalPersistenceExtensionService.executePersistenceExtensionAfterCreate(persistenceAuthProperties.get(i), persistenceAuthEntryManager);
    }
    return persistenceAuthEntryManagers;
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) ArrayList(java.util.ArrayList) PersistenceEntryManagerFactory(org.gluu.persist.PersistenceEntryManagerFactory) Properties(java.util.Properties) Named(javax.inject.Named) Produces(javax.enterprise.inject.Produces) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 5 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager in project oxAuth by GluuFederation.

the class AppInitializer method recreatePersistenceAuthEntryManagers.

public void recreatePersistenceAuthEntryManagers(List<GluuLdapConfiguration> newPersistenceAuthConfigs) {
    // Get existing application scoped instance
    List<PersistenceEntryManager> oldPersistenceAuthEntryManagers = CdiUtil.getContextBean(beanManager, new ParameterizedTypeImpl(List.class, PersistenceEntryManager.class), ApplicationFactory.PERSISTENCE_AUTH_ENTRY_MANAGER_NAME);
    // Recreate components
    this.persistenceAuthConfigs = newPersistenceAuthConfigs;
    // Close existing connections
    closePersistenceEntryManagers(oldPersistenceAuthEntryManagers);
    // Destroy old Ldap auth entry managers
    for (PersistenceEntryManager oldPersistenceAuthEntryManager : oldPersistenceAuthEntryManagers) {
        log.debug("Attempting to destroy {}: {}", ApplicationFactory.PERSISTENCE_AUTH_ENTRY_MANAGER_NAME, oldPersistenceAuthEntryManager);
        oldPersistenceAuthEntryManager.destroy();
        log.debug("Destroyed {}: {}", ApplicationFactory.PERSISTENCE_AUTH_ENTRY_MANAGER_NAME, oldPersistenceAuthEntryManager);
        externalPersistenceExtensionService.executePersistenceExtensionAfterDestroy(oldPersistenceAuthEntryManager);
    }
    // Force to create new Ldap auth entry managers bean
    List<PersistenceEntryManager> persistenceAuthEntryManagers = persistenceAuthEntryManagerInstance.get();
    persistenceAuthEntryManagerInstance.destroy(persistenceAuthEntryManagers);
    log.info("Recreated instance {}: {}", ApplicationFactory.PERSISTENCE_AUTH_ENTRY_MANAGER_NAME, persistenceAuthEntryManagers);
    // Force to create new auth configuration bean
    List<GluuLdapConfiguration> oldPersistenceAuthConfigs = persistenceAuthConfigInstance.get();
    persistenceAuthConfigInstance.destroy(oldPersistenceAuthConfigs);
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) List(java.util.List) ArrayList(java.util.ArrayList) ParameterizedTypeImpl(org.jboss.weld.util.reflection.ParameterizedTypeImpl) GluuLdapConfiguration(org.gluu.model.ldap.GluuLdapConfiguration)

Aggregations

PersistenceEntryManager (org.gluu.persist.PersistenceEntryManager)38 Properties (java.util.Properties)8 SchemaEntry (org.gluu.model.SchemaEntry)7 ArrayList (java.util.ArrayList)6 ApplicationScoped (javax.enterprise.context.ApplicationScoped)5 Produces (javax.enterprise.inject.Produces)5 Named (javax.inject.Named)5 GluuSimplePerson (org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson)5 BasePersistenceException (org.gluu.persist.exception.BasePersistenceException)5 PersistenceEntryManagerFactory (org.gluu.persist.PersistenceEntryManagerFactory)4 Filter (org.gluu.search.filter.Filter)4 GluuLdapConfiguration (org.gluu.model.ldap.GluuLdapConfiguration)3 GluuInumMap (org.gluu.oxtrust.ldap.cache.model.GluuInumMap)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 CustomScriptType (org.gluu.model.custom.script.CustomScriptType)2 CacheCompoundKey (org.gluu.oxtrust.ldap.cache.model.CacheCompoundKey)2 ApplicationInitializedEvent (org.gluu.service.cdi.event.ApplicationInitializedEvent)2