Search in sources :

Example 16 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager in project oxTrust 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 persistanceEntryManager = persistenceEntryManagerInstance.get();
    closePersistenceEntryManager(persistanceEntryManager, ApplicationFactory.PERSISTENCE_ENTRY_MANAGER_NAME);
    PersistenceEntryManager persistanceMetricEntryManager = persistenceMetricEntryManagerInstance.get();
    closePersistenceEntryManager(persistanceMetricEntryManager, ApplicationFactory.PERSISTENCE_METRIC_ENTRY_MANAGER_NAME);
    PersistenceEntryManager persistanceCentralEntryManager = persistenceCentralEntryManagerInstance.get();
    if (persistanceCentralEntryManager != null) {
        closePersistenceEntryManager(persistanceCentralEntryManager, ApplicationFactory.PERSISTENCE_CENTRAL_ENTRY_MANAGER_NAME);
    }
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager)

Example 17 with PersistenceEntryManager

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

the class AppInitializer method createPersistenceEntryManager.

@Produces
@ApplicationScoped
@Named(ApplicationFactory.PERSISTENCE_ENTRY_MANAGER_NAME)
public PersistenceEntryManager createPersistenceEntryManager() {
    Properties connectionProperties = preparePersistanceProperties();
    PersistenceEntryManager persistenceEntryManager = applicationFactory.getPersistenceEntryManagerFactory().createEntryManager(connectionProperties);
    log.info("Created {}: {} with operation service: {}", new Object[] { ApplicationFactory.PERSISTENCE_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) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 18 with PersistenceEntryManager

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

the class CacheRefreshTimer method removeTargetEntries.

private Pair<List<String>, List<String>> removeTargetEntries(LdapServerConnection inumDbServerConnection, PersistenceEntryManager targetPersistenceEntryManager, List<GluuSimplePerson> removedPersons, HashMap<String, GluuInumMap> inumInumMap) {
    Date runDate = new Date(this.lastFinishedTime);
    PersistenceEntryManager inumDbPersistenceEntryManager = inumDbServerConnection.getPersistenceEntryManager();
    List<String> result1 = new ArrayList<String>();
    List<String> result2 = new ArrayList<String>();
    for (GluuSimplePerson removedPerson : removedPersons) {
        String inum = removedPerson.getAttribute(OxTrustConstants.inum);
        // Update GluuInumMap if it exist
        GluuInumMap currentInumMap = inumInumMap.get(inum);
        if (currentInumMap == null) {
            log.warn("Can't find inum entry of person with DN: {}", removedPerson.getDn());
        } else {
            GluuInumMap removedInumMap = getMarkInumMapEntryAsRemoved(currentInumMap, ldapEntryManager.encodeTime(removedPerson.getDn(), runDate));
            try {
                inumDbPersistenceEntryManager.merge(removedInumMap);
                result2.add(removedInumMap.getInum());
            } catch (BasePersistenceException ex) {
                log.error("Failed to update entry with inum '{}' and DN: {}", currentInumMap.getInum(), currentInumMap.getDn(), ex);
                continue;
            }
        }
        // Remove person from target server
        try {
            targetPersistenceEntryManager.removeRecursively(removedPerson.getDn());
            result1.add(inum);
        } catch (BasePersistenceException ex) {
            log.error("Failed to remove person entry with inum '{}' and DN: {}", inum, removedPerson.getDn(), ex);
            continue;
        }
        log.debug("Person with DN: '{}' removed from target server", removedPerson.getDn());
    }
    return new Pair<List<String>, List<String>>(result1, result2);
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) GluuInumMap(org.gluu.oxtrust.ldap.cache.model.GluuInumMap) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) ArrayList(java.util.ArrayList) Date(java.util.Date) Pair(org.gluu.util.Pair)

Example 19 with PersistenceEntryManager

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

the class CacheRefreshTimer method addNewInumServerEntries.

private HashMap<CacheCompoundKey, GluuInumMap> addNewInumServerEntries(CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection inumDbServerConnection, Map<CacheCompoundKey, GluuSimplePerson> sourcePersonCacheCompoundKeyMap, HashMap<CacheCompoundKey, GluuInumMap> primaryKeyAttrValueInumMap) {
    PersistenceEntryManager inumDbPersistenceEntryManager = inumDbServerConnection.getPersistenceEntryManager();
    String inumbaseDn = inumDbServerConnection.getBaseDns()[0];
    HashMap<CacheCompoundKey, GluuInumMap> result = new HashMap<CacheCompoundKey, GluuInumMap>();
    String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
    for (Entry<CacheCompoundKey, GluuSimplePerson> sourcePersonCacheCompoundKeyEntry : sourcePersonCacheCompoundKeyMap.entrySet()) {
        CacheCompoundKey cacheCompoundKey = sourcePersonCacheCompoundKeyEntry.getKey();
        GluuSimplePerson sourcePerson = sourcePersonCacheCompoundKeyEntry.getValue();
        if (log.isTraceEnabled()) {
            log.trace("Checking source entry with key: '{}', and DN: {}", cacheCompoundKey, sourcePerson.getDn());
        }
        GluuInumMap currentInumMap = primaryKeyAttrValueInumMap.get(cacheCompoundKey);
        if (currentInumMap == null) {
            String[][] keyAttributesValues = getKeyAttributesValues(keyAttributesWithoutValues, sourcePerson);
            currentInumMap = addGluuInumMap(inumbaseDn, inumDbPersistenceEntryManager, keyAttributesWithoutValues, keyAttributesValues);
            result.put(cacheCompoundKey, currentInumMap);
            log.debug("Added new inum entry for DN: {}", sourcePerson.getDn());
        } else {
            log.trace("Inum entry for DN: '{}' exist", sourcePerson.getDn());
        }
    }
    return result;
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) GluuInumMap(org.gluu.oxtrust.ldap.cache.model.GluuInumMap) CacheCompoundKey(org.gluu.oxtrust.ldap.cache.model.CacheCompoundKey) HashMap(java.util.HashMap)

Example 20 with PersistenceEntryManager

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

the class CacheRefreshTimer method loadInumServerEntries.

private List<GluuInumMap> loadInumServerEntries(CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection inumDbServerConnection) {
    PersistenceEntryManager inumDbPersistenceEntryManager = inumDbServerConnection.getPersistenceEntryManager();
    String inumbaseDn = inumDbServerConnection.getBaseDns()[0];
    Filter filterObjectClass = Filter.createEqualityFilter(OxConstants.OBJECT_CLASS, OxTrustConstants.objectClassInumMap);
    Filter filterStatus = Filter.createNOTFilter(Filter.createEqualityFilter(OxTrustConstants.gluuStatus, GluuStatus.INACTIVE.getValue()));
    Filter filter = Filter.createANDFilter(filterObjectClass, filterStatus);
    return inumDbPersistenceEntryManager.findEntries(inumbaseDn, GluuInumMap.class, filter, SearchScope.SUB, null, null, 0, 0, cacheRefreshConfiguration.getLdapSearchSizeLimit());
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) Filter(org.gluu.search.filter.Filter)

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