Search in sources :

Example 6 with GluuSimplePerson

use of org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson in project oxTrust by GluuFederation.

the class CacheRefreshTimer method loadSourceServerEntries.

private List<GluuSimplePerson> loadSourceServerEntries(CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection[] sourceServerConnections) throws SearchException {
    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();
        PersistenceEntryManager sourcePersistenceEntryManager = sourceServerConnection.getPersistenceEntryManager();
        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 = sourcePersistenceEntryManager.findEntries(baseDn, GluuSimplePerson.class, filter, SearchScope.SUB, returnAttributes, null, 0, 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) PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) Filter(org.gluu.search.filter.Filter) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 7 with GluuSimplePerson

use of org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson in project oxTrust by GluuFederation.

the class CacheRefreshTimer method processTargetPersons.

private List<GluuSimplePerson> processTargetPersons(List<GluuSimplePerson> targetPersons, HashMap<String, Integer> currInumWithEntryHashCodeMap) {
    List<GluuSimplePerson> result = new ArrayList<GluuSimplePerson>();
    for (GluuSimplePerson targetPerson : targetPersons) {
        String personInum = targetPerson.getAttribute(OxTrustConstants.inum);
        if (!currInumWithEntryHashCodeMap.containsKey(personInum)) {
            log.debug("Person with such DN: '{}' isn't present on source server", targetPerson.getDn());
            result.add(targetPerson);
        }
    }
    return result;
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) ArrayList(java.util.ArrayList)

Example 8 with GluuSimplePerson

use of org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson 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) {
    PersistenceEntryManager inumDbPersistenceEntryManager = inumDbServerConnection.getPersistenceEntryManager();
    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(), inumDbPersistenceEntryManager.getHashCode(sourcePerson));
    }
    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) HashMap(java.util.HashMap) CacheCompoundKey(org.gluu.oxtrust.ldap.cache.model.CacheCompoundKey)

Example 9 with GluuSimplePerson

use of org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson in project oxTrust by GluuFederation.

the class CacheRefreshTimer method getRemovedPersons.

private List<GluuSimplePerson> getRemovedPersons(HashMap<String, Integer> currInumWithEntryHashCodeMap, Map<String, Integer> prevInumWithEntryHashCodeMap) {
    // First time run
    if (prevInumWithEntryHashCodeMap == null) {
        return new ArrayList<GluuSimplePerson>(0);
    }
    // Add all inums which not exist in new snapshot
    Set<String> deletedInums = new HashSet<String>();
    for (String prevInumKey : prevInumWithEntryHashCodeMap.keySet()) {
        if (!currInumWithEntryHashCodeMap.containsKey(prevInumKey)) {
            deletedInums.add(prevInumKey);
        }
    }
    List<GluuSimplePerson> deletedPersons = new ArrayList<GluuSimplePerson>(deletedInums.size());
    for (String deletedInum : deletedInums) {
        GluuSimplePerson person = new GluuSimplePerson();
        String personDn = personService.getDnForPerson(deletedInum);
        person.setDn(personDn);
        List<GluuCustomAttribute> customAttributes = new ArrayList<GluuCustomAttribute>();
        customAttributes.add(new GluuCustomAttribute(OxTrustConstants.inum, deletedInum));
        person.setCustomAttributes(customAttributes);
        deletedPersons.add(person);
    }
    return deletedPersons;
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 10 with GluuSimplePerson

use of org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson in project oxTrust by GluuFederation.

the class CacheRefreshTimer method updateTargetEntriesViaCopy.

private List<String> updateTargetEntriesViaCopy(CacheRefreshConfiguration cacheRefreshConfiguration, Map<CacheCompoundKey, GluuSimplePerson> sourcePersonCacheCompoundKeyMap, HashMap<CacheCompoundKey, GluuInumMap> primaryKeyAttrValueInumMap, Set<String> changedInums) {
    HashMap<String, CacheCompoundKey> inumCacheCompoundKeyMap = getInumCacheCompoundKeyMap(primaryKeyAttrValueInumMap);
    Map<String, String> targetServerAttributesMapping = getTargetServerAttributesMapping(cacheRefreshConfiguration);
    String[] customObjectClasses = appConfiguration.getPersonObjectClassTypes();
    List<String> result = new ArrayList<String>();
    if (!validateTargetServerSchema(cacheRefreshConfiguration, targetServerAttributesMapping, customObjectClasses)) {
        return result;
    }
    for (String targetInum : changedInums) {
        CacheCompoundKey compoundKey = inumCacheCompoundKeyMap.get(targetInum);
        if (compoundKey == null) {
            continue;
        }
        GluuSimplePerson sourcePerson = sourcePersonCacheCompoundKeyMap.get(compoundKey);
        if (sourcePerson == null) {
            continue;
        }
        if (updateTargetEntryViaCopy(sourcePerson, targetInum, customObjectClasses, targetServerAttributesMapping)) {
            result.add(targetInum);
        }
    }
    return result;
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) CacheCompoundKey(org.gluu.oxtrust.ldap.cache.model.CacheCompoundKey) ArrayList(java.util.ArrayList)

Aggregations

GluuSimplePerson (org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson)12 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)5 PersistenceEntryManager (org.gluu.persist.PersistenceEntryManager)5 LinkedHashSet (java.util.LinkedHashSet)4 CacheCompoundKey (org.gluu.oxtrust.ldap.cache.model.CacheCompoundKey)4 GluuInumMap (org.gluu.oxtrust.ldap.cache.model.GluuInumMap)4 HashMap (java.util.HashMap)3 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)3 Date (java.util.Date)2 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)2 Filter (org.gluu.search.filter.Filter)2 BasePersistenceException (org.gluu.persist.exception.BasePersistenceException)1 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)1 LdapEntryManager (org.gluu.persist.ldap.impl.LdapEntryManager)1 Pair (org.gluu.util.Pair)1 Pair (org.xdi.util.Pair)1