Search in sources :

Example 11 with GluuSimplePerson

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

the class CacheRefreshTimer method getSourcePersonCompoundKeyMap.

private Map<CacheCompoundKey, GluuSimplePerson> getSourcePersonCompoundKeyMap(CacheRefreshConfiguration cacheRefreshConfiguration, List<GluuSimplePerson> sourcePersons) {
    Map<CacheCompoundKey, GluuSimplePerson> result = new HashMap<CacheCompoundKey, GluuSimplePerson>();
    Set<CacheCompoundKey> duplicateKeys = new HashSet<CacheCompoundKey>();
    String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
    for (GluuSimplePerson sourcePerson : sourcePersons) {
        String[][] keyAttributesValues = getKeyAttributesValues(keyAttributesWithoutValues, sourcePerson);
        CacheCompoundKey cacheCompoundKey = new CacheCompoundKey(keyAttributesValues);
        if (result.containsKey(cacheCompoundKey)) {
            duplicateKeys.add(cacheCompoundKey);
        }
        result.put(cacheCompoundKey, sourcePerson);
    }
    for (CacheCompoundKey duplicateKey : duplicateKeys) {
        log.error("Non-deterministic primary key. Skipping user with key: {}", duplicateKey);
        result.remove(duplicateKey);
    }
    return result;
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) CacheCompoundKey(org.gluu.oxtrust.ldap.cache.model.CacheCompoundKey) HashMap(java.util.HashMap) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 12 with GluuSimplePerson

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

the class CacheRefreshTimer method loadSourceServerEntriesWithoutLimits.

private List<GluuSimplePerson> loadSourceServerEntriesWithoutLimits(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[] 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();
        Filter filter = cacheRefreshService.createFilter(keyAttributes, keyObjectClasses, "", customFilter);
        if (log.isTraceEnabled()) {
            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)

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