Search in sources :

Example 31 with PersistenceEntryManager

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

the class ConfigurationFactory method generateWebKeys.

private void generateWebKeys() {
    log.info("Failed to load JWKS. Attempting to generate new JWKS...");
    String newWebKeys = null;
    try {
        final AbstractCryptoProvider cryptoProvider = CryptoProviderFactory.getCryptoProvider(getAppConfiguration());
        // Generate new JWKS
        JSONObject jsonObject = AbstractCryptoProvider.generateJwks(cryptoProvider, getAppConfiguration());
        newWebKeys = jsonObject.toString();
        // Attempt to load new JWKS
        jwks = ServerUtil.createJsonMapper().readValue(newWebKeys, WebKeysConfiguration.class);
        // Store new JWKS in LDAP
        Conf conf = loadConfigurationFromLdap();
        conf.setWebKeys(jwks);
        long nextRevision = conf.getRevision() + 1;
        conf.setRevision(nextRevision);
        final PersistenceEntryManager ldapManager = persistenceEntryManagerInstance.get();
        ldapManager.merge(conf);
        log.info("Generated new JWKS successfully.");
        log.trace("JWKS keys: " + conf.getWebKeys().getKeys().stream().map(JSONWebKey::getKid).collect(Collectors.toList()));
        log.trace("KeyStore keys: " + cryptoProvider.getKeys());
    } catch (Exception ex2) {
        log.error("Failed to re-generate JWKS keys", ex2);
    }
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) JSONObject(org.json.JSONObject) AbstractCryptoProvider(org.gluu.oxauth.model.crypto.AbstractCryptoProvider) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) ConfigurationException(org.gluu.exception.ConfigurationException)

Example 32 with PersistenceEntryManager

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

the class ConfigurationFactory method loadConfigurationFromLdap.

private Conf loadConfigurationFromLdap(String... returnAttributes) {
    final PersistenceEntryManager ldapManager = persistenceEntryManagerInstance.get();
    final String dn = this.baseConfiguration.getString("oxauth_ConfigurationEntryDN");
    try {
        final Conf conf = ldapManager.find(dn, Conf.class, returnAttributes);
        return conf;
    } catch (BasePersistenceException ex) {
        ex.printStackTrace();
        log.error(ex.getMessage());
    }
    return null;
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException)

Example 33 with PersistenceEntryManager

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

the class AppInitializer method closePersistenceEntryManagers.

private void closePersistenceEntryManagers(List<PersistenceEntryManager> oldPersistenceEntryManagers) {
    // Close existing connections
    for (PersistenceEntryManager oldPersistenceEntryManager : oldPersistenceEntryManagers) {
        log.debug("Attempting to destroy {}: {}", ApplicationFactory.PERSISTENCE_AUTH_ENTRY_MANAGER_NAME, oldPersistenceEntryManager);
        oldPersistenceEntryManager.destroy();
        log.debug("Destroyed {}: {}", ApplicationFactory.PERSISTENCE_AUTH_ENTRY_MANAGER_NAME, oldPersistenceEntryManager);
        externalPersistenceExtensionService.executePersistenceExtensionAfterDestroy(oldPersistenceEntryManager);
    }
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager)

Example 34 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager 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)

Example 35 with PersistenceEntryManager

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

the class AppInitializer method recreatePersistanceEntryManagerImpl.

protected void recreatePersistanceEntryManagerImpl(Instance<PersistenceEntryManager> instance, String persistenceEntryManagerName, Annotation... qualifiers) {
    // Get existing application scoped instance
    PersistenceEntryManager oldPersistenceEntryManager = CdiUtil.getContextBean(beanManager, PersistenceEntryManager.class, persistenceEntryManagerName);
    // Close existing connections
    closePersistenceEntryManager(oldPersistenceEntryManager, persistenceEntryManagerName);
    // Force to create new bean
    PersistenceEntryManager persistenceEntryManager = instance.get();
    instance.destroy(persistenceEntryManager);
    log.info("Recreated instance {}: {} with operation service: {}", persistenceEntryManagerName, persistenceEntryManager, persistenceEntryManager.getOperationService());
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager)

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