Search in sources :

Example 1 with LdapEntryManager

use of org.gluu.persist.ldap.impl.LdapEntryManager in project oxTrust by GluuFederation.

the class CacheRefreshTimer method removeTargetEntries.

private Pair<List<String>, List<String>> removeTargetEntries(LdapServerConnection inumDbServerConnection, LdapEntryManager targetLdapEntryManager, List<GluuSimplePerson> removedPersons, HashMap<String, GluuInumMap> inumInumMap) {
    String runDate = ldapEntryManager.encodeGeneralizedTime(new Date(this.lastFinishedTime));
    LdapEntryManager inumDbLdapEntryManager = inumDbServerConnection.getLdapEntryManager();
    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, runDate);
            try {
                inumDbLdapEntryManager.merge(removedInumMap);
                result2.add(removedInumMap.getInum());
            } catch (BaseMappingException ex) {
                log.error("Failed to update entry with inum '{}' and DN: {}", currentInumMap.getInum(), currentInumMap.getDn(), ex);
                continue;
            }
        }
        // Remove person from target server
        try {
            targetLdapEntryManager.removeRecursively(removedPerson.getDn());
            result1.add(inum);
        } catch (BaseMappingException 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) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) GluuInumMap(org.gluu.oxtrust.ldap.cache.model.GluuInumMap) LdapEntryManager(org.gluu.persist.ldap.impl.LdapEntryManager) ArrayList(java.util.ArrayList) Date(java.util.Date) Pair(org.xdi.util.Pair)

Example 2 with LdapEntryManager

use of org.gluu.persist.ldap.impl.LdapEntryManager in project oxTrust by GluuFederation.

the class CacheRefreshTimer method getSourcePersonsHashCodesMap.

private HashMap<String, Integer> getSourcePersonsHashCodesMap(LdapServerConnection inumDbServerConnection, Map<CacheCompoundKey, GluuSimplePerson> sourcePersonCacheCompoundKeyMap, HashMap<CacheCompoundKey, GluuInumMap> primaryKeyAttrValueInumMap) {
    LdapEntryManager inumDbLdapEntryManager = inumDbServerConnection.getLdapEntryManager();
    HashMap<String, Integer> result = new HashMap<String, Integer>();
    for (Entry<CacheCompoundKey, GluuSimplePerson> sourcePersonCacheCompoundKeyEntry : sourcePersonCacheCompoundKeyMap.entrySet()) {
        CacheCompoundKey cacheCompoundKey = sourcePersonCacheCompoundKeyEntry.getKey();
        GluuSimplePerson sourcePerson = sourcePersonCacheCompoundKeyEntry.getValue();
        GluuInumMap currentInumMap = primaryKeyAttrValueInumMap.get(cacheCompoundKey);
        result.put(currentInumMap.getInum(), inumDbLdapEntryManager.getHashCode(sourcePerson));
    }
    return result;
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) GluuInumMap(org.gluu.oxtrust.ldap.cache.model.GluuInumMap) LdapEntryManager(org.gluu.persist.ldap.impl.LdapEntryManager) HashMap(java.util.HashMap) CacheCompoundKey(org.gluu.oxtrust.ldap.cache.model.CacheCompoundKey)

Example 3 with LdapEntryManager

use of org.gluu.persist.ldap.impl.LdapEntryManager 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) {
    LdapEntryManager inumDbLdapEntryManager = inumDbServerConnection.getLdapEntryManager();
    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, inumDbLdapEntryManager, 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) GluuInumMap(org.gluu.oxtrust.ldap.cache.model.GluuInumMap) LdapEntryManager(org.gluu.persist.ldap.impl.LdapEntryManager) CacheCompoundKey(org.gluu.oxtrust.ldap.cache.model.CacheCompoundKey) HashMap(java.util.HashMap)

Example 4 with LdapEntryManager

use of org.gluu.persist.ldap.impl.LdapEntryManager in project oxTrust by GluuFederation.

the class CacheRefreshTimer method loadInumServerEntries.

private List<GluuInumMap> loadInumServerEntries(CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection inumDbServerConnection) {
    LdapEntryManager inumDbldapEntryManager = inumDbServerConnection.getLdapEntryManager();
    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 inumDbldapEntryManager.findEntries(inumbaseDn, GluuInumMap.class, filter, SearchScope.SUB, null, 0, cacheRefreshConfiguration.getLdapSearchSizeLimit());
}
Also used : LdapEntryManager(org.gluu.persist.ldap.impl.LdapEntryManager) Filter(org.gluu.search.filter.Filter)

Example 5 with LdapEntryManager

use of org.gluu.persist.ldap.impl.LdapEntryManager in project oxTrust by GluuFederation.

the class CacheRefreshTimer method loadSourceServerEntries.

private List<GluuSimplePerson> loadSourceServerEntries(CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection[] sourceServerConnections) {
    Filter customFilter = cacheRefreshService.createFilter(cacheRefreshConfiguration.getCustomLdapFilter());
    String[] keyAttributes = getCompoundKeyAttributes(cacheRefreshConfiguration);
    String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
    String[] keyObjectClasses = getCompoundKeyObjectClasses(cacheRefreshConfiguration);
    String[] sourceAttributes = getSourceAttributes(cacheRefreshConfiguration);
    String[] twoLettersArray = createTwoLettersArray();
    String[] returnAttributes = ArrayHelper.arrayMerge(keyAttributesWithoutValues, sourceAttributes);
    Set<String> addedDns = new HashSet<String>();
    List<GluuSimplePerson> sourcePersons = new ArrayList<GluuSimplePerson>();
    for (LdapServerConnection sourceServerConnection : sourceServerConnections) {
        String sourceServerName = sourceServerConnection.getSourceServerName();
        LdapEntryManager sourceLdapEntryManager = sourceServerConnection.getLdapEntryManager();
        String[] baseDns = sourceServerConnection.getBaseDns();
        for (String keyAttributeStart : twoLettersArray) {
            Filter filter = cacheRefreshService.createFilter(keyAttributes, keyObjectClasses, keyAttributeStart, customFilter);
            if (log.isDebugEnabled()) {
                log.trace("Using next filter to load entris from source server: {}", filter);
            }
            for (String baseDn : baseDns) {
                List<GluuSimplePerson> currentSourcePersons = sourceLdapEntryManager.findEntries(baseDn, GluuSimplePerson.class, filter, SearchScope.SUB, returnAttributes, 0, cacheRefreshConfiguration.getLdapSearchSizeLimit());
                // Add to result and ignore root entry if needed
                for (GluuSimplePerson currentSourcePerson : currentSourcePersons) {
                    currentSourcePerson.setSourceServerName(sourceServerName);
                    // if (!StringHelper.equalsIgnoreCase(baseDn,
                    // currentSourcePerson.getDn())) {
                    String currentSourcePersonDn = currentSourcePerson.getDn().toLowerCase();
                    if (!addedDns.contains(currentSourcePersonDn)) {
                        sourcePersons.add(currentSourcePerson);
                        addedDns.add(currentSourcePersonDn);
                    }
                // }
                }
            }
        }
    }
    return sourcePersons;
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) LdapEntryManager(org.gluu.persist.ldap.impl.LdapEntryManager) Filter(org.gluu.search.filter.Filter) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

LdapEntryManager (org.gluu.persist.ldap.impl.LdapEntryManager)20 Filter (org.gluu.search.filter.Filter)6 Properties (java.util.Properties)5 GluuSimplePerson (org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson)5 ArrayList (java.util.ArrayList)4 GluuInumMap (org.gluu.oxtrust.ldap.cache.model.GluuInumMap)3 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Produces (javax.enterprise.inject.Produces)2 Named (javax.inject.Named)2 SimpleSession (org.gluu.ldap.model.SimpleSession)2 CacheCompoundKey (org.gluu.oxtrust.ldap.cache.model.CacheCompoundKey)2 LdapEntryManagerFactory (org.gluu.persist.ldap.impl.LdapEntryManagerFactory)2 CustomAttribute (org.gluu.persist.model.base.CustomAttribute)2 FileConfiguration (org.xdi.util.properties.FileConfiguration)2 List (java.util.List)1