use of org.gluu.site.ldap.persistence.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 (LdapMappingException ex) {
log.error("Failed to update entry with inum '{}' and DN: {}", ex, currentInumMap.getInum(), currentInumMap.getDn());
continue;
}
}
// Remove person from target server
try {
targetLdapEntryManager.removeWithSubtree(removedPerson.getDn());
result1.add(inum);
} catch (LdapMappingException ex) {
log.error("Failed to remove person entry with inum '{}' and DN: {}", ex, inum, removedPerson.getDn());
continue;
}
log.debug("Person with DN: '{}' removed from target server", removedPerson.getDn());
}
return new Pair<List<String>, List<String>>(result1, result2);
}
use of org.gluu.site.ldap.persistence.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;
}
use of org.gluu.site.ldap.persistence.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, returnAttributes, 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.site.ldap.persistence.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;
}
use of org.gluu.site.ldap.persistence.LdapEntryManager in project oxAuth by GluuFederation.
the class Manual method init.
@BeforeClass
public void init() {
final FileConfiguration fileConfiguration = new FileConfiguration(LDAP_FILE_PATH);
final Properties props = PropertiesDecrypter.decryptProperties(fileConfiguration.getProperties(), "passoword");
final LDAPConnectionProvider connectionProvider = new LDAPConnectionProvider(props);
MANAGER = new LdapEntryManager(new OperationsFacade(connectionProvider));
}
Aggregations