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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations