use of org.gluu.persist.PersistenceEntryManager 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.persist.PersistenceEntryManager 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.persist.PersistenceEntryManager in project oxTrust by GluuFederation.
the class ConfigurationFactory method loadConfigurationFromDb.
@Override
protected LdapOxTrustConfiguration loadConfigurationFromDb(String... returnAttributes) {
final PersistenceEntryManager persistenceEntryManager = persistenceEntryManagerInstance.get();
final String configurationDn = getConfigurationDn();
try {
final LdapOxTrustConfiguration conf = persistenceEntryManager.find(configurationDn, LdapOxTrustConfiguration.class, returnAttributes);
return conf;
} catch (BasePersistenceException ex) {
log.error("Failed to load configuration from LDAP", ex);
}
return null;
}
use of org.gluu.persist.PersistenceEntryManager in project oxTrust by GluuFederation.
the class CacheRefreshTimer method prepareLdapServerConnection.
private LdapServerConnection prepareLdapServerConnection(CacheRefreshConfiguration cacheRefreshConfiguration, GluuLdapConfiguration ldapConfiguration, boolean useLocalConnection) {
String ldapConfig = ldapConfiguration.getConfigId();
if (useLocalConnection) {
return new LdapServerConnection(ldapConfig, ldapEntryManager, getBaseDNs(ldapConfiguration));
}
PersistenceEntryManagerFactory entryManagerFactory = applicationFactory.getPersistenceEntryManagerFactory(LdapEntryManagerFactory.class);
String persistenceType = entryManagerFactory.getPersistenceType();
Properties ldapProperties = toLdapProperties(entryManagerFactory, ldapConfiguration);
Properties ldapDecryptedProperties = encryptionService.decryptAllProperties(ldapProperties);
// Try to get updated password via script
BindCredentials bindCredentials = externalCacheRefreshService.executeExternalGetBindCredentialsMethods(ldapConfig);
String bindPasswordPropertyKey = persistenceType + "#" + PropertiesDecrypter.BIND_PASSWORD;
if (bindCredentials != null) {
log.error("Using updated password which got from getBindCredentials method");
ldapDecryptedProperties.setProperty(persistenceType + ".bindDN", bindCredentials.getBindDn());
ldapDecryptedProperties.setProperty(bindPasswordPropertyKey, bindCredentials.getBindPassword());
}
if (log.isTraceEnabled()) {
Properties clonedLdapDecryptedProperties = (Properties) ldapDecryptedProperties.clone();
if (clonedLdapDecryptedProperties.getProperty(bindPasswordPropertyKey) != null) {
clonedLdapDecryptedProperties.setProperty(bindPasswordPropertyKey, "REDACTED");
}
log.trace("Attempting to create PersistenceEntryManager with properties: {}", clonedLdapDecryptedProperties);
}
PersistenceEntryManager customPersistenceEntryManager = entryManagerFactory.createEntryManager(ldapDecryptedProperties);
log.info("Created Cache Refresh PersistenceEntryManager: {}", customPersistenceEntryManager);
if (!customPersistenceEntryManager.getOperationService().isConnected()) {
log.error("Failed to connect to LDAP server using configuration {}", ldapConfig);
return null;
}
return new LdapServerConnection(ldapConfig, customPersistenceEntryManager, getBaseDNs(ldapConfiguration));
}
use of org.gluu.persist.PersistenceEntryManager in project oxTrust by GluuFederation.
the class CacheRefreshTimer method updateTargetEntriesViaVDS.
private List<String> updateTargetEntriesViaVDS(CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection targetServerConnection, Set<String> changedInums) {
List<String> result = new ArrayList<String>();
PersistenceEntryManager targetPersistenceEntryManager = targetServerConnection.getPersistenceEntryManager();
Filter filter = cacheRefreshService.createObjectClassPresenceFilter();
for (String changedInum : changedInums) {
String baseDn = "action=synchronizecache," + personService.getDnForPerson(changedInum);
try {
targetPersistenceEntryManager.findEntries(baseDn, DummyEntry.class, filter, SearchScope.SUB, null, null, 0, 0, cacheRefreshConfiguration.getLdapSearchSizeLimit());
result.add(changedInum);
log.debug("Updated entry with inum {}", changedInum);
} catch (BasePersistenceException ex) {
log.error("Failed to update entry with inum '{}' using baseDN {}", changedInum, baseDn, ex);
}
}
return result;
}
Aggregations