Search in sources :

Example 1 with PersistenceEntryManagerFactory

use of org.gluu.persist.PersistenceEntryManagerFactory 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 2 with PersistenceEntryManagerFactory

use of org.gluu.persist.PersistenceEntryManagerFactory in project oxCore by GluuFederation.

the class ConfigurationFactory method createPersistenceEntryManager.

private PersistenceEntryManager createPersistenceEntryManager() {
    Properties connectionProperties = preparePersistanceProperties();
    PersistenceEntryManagerFactory persistenceEntryManagerFactory = persistanceFactoryService.getPersistenceEntryManagerFactory(persistenceConfiguration);
    PersistenceEntryManager persistenceEntryManager = persistenceEntryManagerFactory.createEntryManager(connectionProperties);
    LOG.info("Created PersistenceEntryManager: {} with operation service: {}", new Object[] { persistenceEntryManager, persistenceEntryManager.getOperationService() });
    return persistenceEntryManager;
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) PersistenceEntryManagerFactory(org.gluu.persist.PersistenceEntryManagerFactory) Properties(java.util.Properties)

Example 3 with PersistenceEntryManagerFactory

use of org.gluu.persist.PersistenceEntryManagerFactory in project oxTrust by GluuFederation.

the class CacheRefreshTimer method prepareLdapServerConnection.

private LdapServerConnection prepareLdapServerConnection(CacheRefreshConfiguration cacheRefreshConfiguration, GluuLdapConfiguration ldapConfiguration, boolean useLocalConnection) {
    String ldapConfig = ldapConfiguration.getConfigId();
    if (useLocalConnection) {
        return new LdapServerConnection(ldapConfig, ldapEntryManager, getBaseDNs(ldapConfiguration));
    }
    PersistenceEntryManagerFactory entryManagerFactory = applicationFactory.getPersistenceEntryManagerFactory(LdapEntryManagerFactory.class);
    String persistenceType = entryManagerFactory.getPersistenceType();
    Properties ldapProperties = toLdapProperties(entryManagerFactory, ldapConfiguration);
    Properties ldapDecryptedProperties = encryptionService.decryptAllProperties(ldapProperties);
    // Try to get updated password via script
    BindCredentials bindCredentials = externalCacheRefreshService.executeExternalGetBindCredentialsMethods(ldapConfig);
    String bindPasswordPropertyKey = persistenceType + "#" + PropertiesDecrypter.BIND_PASSWORD;
    if (bindCredentials != null) {
        log.error("Using updated password which got from getBindCredentials method");
        ldapDecryptedProperties.setProperty(persistenceType + ".bindDN", bindCredentials.getBindDn());
        ldapDecryptedProperties.setProperty(bindPasswordPropertyKey, bindCredentials.getBindPassword());
    }
    if (log.isTraceEnabled()) {
        Properties clonedLdapDecryptedProperties = (Properties) ldapDecryptedProperties.clone();
        if (clonedLdapDecryptedProperties.getProperty(bindPasswordPropertyKey) != null) {
            clonedLdapDecryptedProperties.setProperty(bindPasswordPropertyKey, "REDACTED");
        }
        log.trace("Attempting to create PersistenceEntryManager with properties: {}", clonedLdapDecryptedProperties);
    }
    PersistenceEntryManager customPersistenceEntryManager = entryManagerFactory.createEntryManager(ldapDecryptedProperties);
    log.info("Created Cache Refresh PersistenceEntryManager: {}", customPersistenceEntryManager);
    if (!customPersistenceEntryManager.getOperationService().isConnected()) {
        log.error("Failed to connect to LDAP server using configuration {}", ldapConfig);
        return null;
    }
    return new LdapServerConnection(ldapConfig, customPersistenceEntryManager, getBaseDNs(ldapConfiguration));
}
Also used : BindCredentials(org.gluu.model.custom.script.model.bind.BindCredentials) PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) PersistenceEntryManagerFactory(org.gluu.persist.PersistenceEntryManagerFactory) Properties(java.util.Properties)

Example 4 with PersistenceEntryManagerFactory

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

the class AppInitializer method createPersistenceAuthEntryManager.

/*
	 * Utility method which can be used in custom scripts
	 */
public PersistenceEntryManager createPersistenceAuthEntryManager(GluuLdapConfiguration persistenceAuthConfig) {
    PersistenceEntryManagerFactory persistenceEntryManagerFactory = applicationFactory.getPersistenceEntryManagerFactory();
    Properties persistenceConnectionProperties = prepareAuthConnectionProperties(persistenceAuthConfig, persistenceEntryManagerFactory.getPersistenceType());
    PersistenceEntryManager persistenceAuthEntryManager = persistenceEntryManagerFactory.createEntryManager(persistenceConnectionProperties);
    log.debug("Created custom authentication PersistenceEntryManager: {}", persistenceAuthEntryManager);
    externalPersistenceExtensionService.executePersistenceExtensionAfterCreate(persistenceConnectionProperties, persistenceAuthEntryManager);
    return persistenceAuthEntryManager;
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) PersistenceEntryManagerFactory(org.gluu.persist.PersistenceEntryManagerFactory) Properties(java.util.Properties)

Aggregations

Properties (java.util.Properties)4 PersistenceEntryManager (org.gluu.persist.PersistenceEntryManager)4 PersistenceEntryManagerFactory (org.gluu.persist.PersistenceEntryManagerFactory)4 ArrayList (java.util.ArrayList)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Produces (javax.enterprise.inject.Produces)1 Named (javax.inject.Named)1 BindCredentials (org.gluu.model.custom.script.model.bind.BindCredentials)1