gluu
クラス | 公開メンバ関数 | 限定公開変数類 | 非公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer クラス
org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer 連携図
Collaboration graph

クラス

class  LdapServerConnection
 

公開メンバ関数

void initTimer ()
 
void process (@Observes @Scheduled CacheRefreshEvent cacheRefreshEvent)
 
void processInt ()
 

限定公開変数類

ApplicationFactory applicationFactory
 
AttributeService attributeService
 

非公開メンバ関数

boolean isStartCacheRefresh (CacheRefreshConfiguration cacheRefreshConfiguration, GluuAppliance currentAppliance)
 
void processImpl (CacheRefreshConfiguration cacheRefreshConfiguration, GluuAppliance currentAppliance)
 
boolean detectChangedEntries (CacheRefreshConfiguration cacheRefreshConfiguration, GluuAppliance currentAppliance, LdapServerConnection[] sourceServerConnections, LdapServerConnection inumDbServerConnection, LdapServerConnection targetServerConnection, CacheRefreshUpdateMethod updateMethod)
 
ArrayList< GluuInumMapapplyChangesToInumMap (HashMap< String, GluuInumMap > inumInumMap, HashMap< CacheCompoundKey, GluuInumMap > addedPrimaryKeyAttrValueInumMap, List< String > removedGluuInumMaps)
 
Set< String > getChangedInums (HashMap< String, Integer > currInumWithEntryHashCodeMap, Map< String, Integer > prevInumWithEntryHashCodeMap, boolean includeDeleted)
 
List< GluuSimplePersongetRemovedPersons (HashMap< String, Integer > currInumWithEntryHashCodeMap, Map< String, Integer > prevInumWithEntryHashCodeMap)
 
List< String > updateTargetEntriesViaVDS (CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection targetServerConnection, Set< String > changedInums)
 
List< String > updateTargetEntriesViaCopy (CacheRefreshConfiguration cacheRefreshConfiguration, Map< CacheCompoundKey, GluuSimplePerson > sourcePersonCacheCompoundKeyMap, HashMap< CacheCompoundKey, GluuInumMap > primaryKeyAttrValueInumMap, Set< String > changedInums)
 
boolean validateTargetServerSchema (CacheRefreshConfiguration cacheRefreshConfiguration, Map< String, String > targetServerAttributesMapping, String[] customObjectClasses)
 
boolean validateTargetServerSchema (List< String > targetObjectClasses, List< String > targetAttributes)
 
boolean updateTargetEntryViaCopy (GluuSimplePerson sourcePerson, String targetInum, String[] targetCustomObjectClasses, Map< String, String > targetServerAttributesMapping)
 
HashMap< String, CacheCompoundKeygetInumCacheCompoundKeyMap (HashMap< CacheCompoundKey, GluuInumMap > primaryKeyAttrValueInumMap)
 
Pair< List< String >, List< String > > removeTargetEntries (LdapServerConnection inumDbServerConnection, PersistenceEntryManager targetPersistenceEntryManager, List< GluuSimplePerson > removedPersons, HashMap< String, GluuInumMap > inumInumMap)
 
GluuInumMap getMarkInumMapEntryAsRemoved (GluuInumMap currentInumMap, String date)
 
void markInumMapEntryKeyValuesAsRemoved (String[] keyValues, String suffix)
 
List< GluuInumMaploadInumServerEntries (CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection inumDbServerConnection)
 
List< GluuSimplePersonloadSourceServerEntriesWithoutLimits (CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection[] sourceServerConnections)
 
List< GluuSimplePersonloadSourceServerEntries (CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection[] sourceServerConnections)
 
List< GluuSimplePersonloadTargetServerEntries (CacheRefreshConfiguration cacheRefreshConfiguration, PersistenceEntryManager targetPersistenceEntryManager)
 
GluuInumMap addGluuInumMap (String inumbBaseDn, PersistenceEntryManager inumDbPersistenceEntryManager, String[] primaryKeyAttrName, String[][] primaryKeyValues)
 
HashMap< CacheCompoundKey, GluuInumMapaddNewInumServerEntries (CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection inumDbServerConnection, Map< CacheCompoundKey, GluuSimplePerson > sourcePersonCacheCompoundKeyMap, HashMap< CacheCompoundKey, GluuInumMap > primaryKeyAttrValueInumMap)
 
HashMap< CacheCompoundKey, GluuInumMapgetAllInumServerEntries (HashMap< CacheCompoundKey, GluuInumMap > primaryKeyAttrValueInumMap, HashMap< CacheCompoundKey, GluuInumMap > addedPrimaryKeyAttrValueInumMap)
 
HashMap< String, Integer > getSourcePersonsHashCodesMap (LdapServerConnection inumDbServerConnection, Map< CacheCompoundKey, GluuSimplePerson > sourcePersonCacheCompoundKeyMap, HashMap< CacheCompoundKey, GluuInumMap > primaryKeyAttrValueInumMap)
 
List< GluuSimplePersonprocessTargetPersons (List< GluuSimplePerson > targetPersons, HashMap< String, Integer > currInumWithEntryHashCodeMap)
 
HashMap< CacheCompoundKey, GluuInumMapgetPrimaryKeyAttrValueInumMap (List< GluuInumMap > inumMaps)
 
HashMap< String, GluuInumMapgetInumInumMap (List< GluuInumMap > inumMaps)
 
Map< CacheCompoundKey, GluuSimplePersongetSourcePersonCompoundKeyMap (CacheRefreshConfiguration cacheRefreshConfiguration, List< GluuSimplePerson > sourcePersons)
 
LdapServerConnection [] prepareLdapServerConnections (CacheRefreshConfiguration cacheRefreshConfiguration, List< GluuLdapConfiguration > ldapConfigurations)
 
LdapServerConnection prepareLdapServerConnection (CacheRefreshConfiguration cacheRefreshConfiguration, GluuLdapConfiguration ldapConfiguration)
 
LdapServerConnection prepareLdapServerConnection (CacheRefreshConfiguration cacheRefreshConfiguration, GluuLdapConfiguration ldapConfiguration, boolean useLocalConnection)
 
void closeLdapServerConnection (LdapServerConnection... ldapServerConnections)
 
String [] createTwoLettersArray ()
 
String [][] getKeyAttributesValues (String[] attrs, GluuSimplePerson person)
 
void updateApplianceStatus (GluuAppliance currentAppliance, long lastRun)
 
String toIntString (Number number)
 
String getInumCachePath (CacheRefreshConfiguration cacheRefreshConfiguration)
 
CacheRefreshUpdateMethod getUpdateMethod (CacheRefreshConfiguration cacheRefreshConfiguration)
 
String [] getSourceAttributes (CacheRefreshConfiguration cacheRefreshConfiguration)
 
String [] getCompoundKeyAttributes (CacheRefreshConfiguration cacheRefreshConfiguration)
 
String [] getCompoundKeyObjectClasses (CacheRefreshConfiguration cacheRefreshConfiguration)
 
String [] getCompoundKeyAttributesWithoutValues (CacheRefreshConfiguration cacheRefreshConfiguration)
 
Map< String, String > getTargetServerAttributesMapping (CacheRefreshConfiguration cacheRefreshConfiguration)
 
Properties toLdapProperties (GluuLdapConfiguration ldapConfiguration)
 
String [] getBaseDNs (GluuLdapConfiguration ldapConfiguration)
 

非公開変数類

Logger log
 
Event< TimerEvent > timerEvent
 
ConfigurationFactory configurationFactory
 
CacheRefreshService cacheRefreshService
 
IPersonService personService
 
PersistenceEntryManager ldapEntryManager
 
ApplianceService applianceService
 
CacheRefreshSnapshotFileService cacheRefreshSnapshotFileService
 
ExternalCacheRefreshService externalCacheRefreshService
 
SchemaService schemaService
 
InumService inumService
 
AppConfiguration appConfiguration
 
EncryptionService encryptionService
 
ObjectSerializationService objectSerializationService
 
AtomicBoolean isActive
 
long lastFinishedTime
 

静的非公開変数類

static final String LETTERS_FOR_SEARCH = "abcdefghijklmnopqrstuvwxyz1234567890."
 
static final String [] TARGET_PERSON_RETURN_ATTRIBUTES = { OxTrustConstants.inum }
 
static final int DEFAULT_INTERVAL = 60
 

詳解

Check periodically if source servers contains updates and trigger target server entry update if needed

著者
Yuriy Movchan Date: 05.05.2011

関数詳解

◆ addGluuInumMap()

GluuInumMap org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.addGluuInumMap ( String  inumbBaseDn,
PersistenceEntryManager  inumDbPersistenceEntryManager,
String []  primaryKeyAttrName,
String  primaryKeyValues[][] 
)
inlineprivate
900  {
901  String inum = cacheRefreshService.generateInumForNewInumMap(inumbBaseDn, inumDbPersistenceEntryManager);
902  String inumDn = cacheRefreshService.getDnForInum(inumbBaseDn, inum);
903 
904  GluuInumMap inumMap = new GluuInumMap();
905  inumMap.setDn(inumDn);
906  inumMap.setInum(inum);
907  inumMap.setPrimaryKeyAttrName(primaryKeyAttrName[0]);
908  inumMap.setPrimaryKeyValues(primaryKeyValues[0]);
909  if (primaryKeyAttrName.length > 1) {
910  inumMap.setSecondaryKeyAttrName(primaryKeyAttrName[1]);
911  inumMap.setSecondaryKeyValues(primaryKeyValues[1]);
912  }
913  if (primaryKeyAttrName.length > 2) {
914  inumMap.setTertiaryKeyAttrName(primaryKeyAttrName[2]);
915  inumMap.setTertiaryKeyValues(primaryKeyValues[2]);
916  }
917  inumMap.setStatus(GluuStatus.ACTIVE);
918  cacheRefreshService.addInumMap(inumDbPersistenceEntryManager, inumMap);
919 
920  return inumMap;
921  }
CacheRefreshService cacheRefreshService
Definition: CacheRefreshTimer.java:109
void addInumMap(PersistenceEntryManager ldapEntryManager, GluuInumMap inumMap)
Definition: CacheRefreshService.java:102
String getDnForInum(String baseDn, String inum)
Definition: CacheRefreshService.java:126
String generateInumForNewInumMap(String inumbBaseDn, PersistenceEntryManager ldapEntryManager)
Definition: CacheRefreshService.java:110

◆ addNewInumServerEntries()

HashMap<CacheCompoundKey, GluuInumMap> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.addNewInumServerEntries ( CacheRefreshConfiguration  cacheRefreshConfiguration,
LdapServerConnection  inumDbServerConnection,
Map< CacheCompoundKey, GluuSimplePerson sourcePersonCacheCompoundKeyMap,
HashMap< CacheCompoundKey, GluuInumMap primaryKeyAttrValueInumMap 
)
inlineprivate
925  {
926  PersistenceEntryManager inumDbPersistenceEntryManager = inumDbServerConnection.getPersistenceEntryManager();
927  String inumbaseDn = inumDbServerConnection.getBaseDns()[0];
928 
929  HashMap<CacheCompoundKey, GluuInumMap> result = new HashMap<CacheCompoundKey, GluuInumMap>();
930 
931  String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
932  for (Entry<CacheCompoundKey, GluuSimplePerson> sourcePersonCacheCompoundKeyEntry : sourcePersonCacheCompoundKeyMap.entrySet()) {
933  CacheCompoundKey cacheCompoundKey = sourcePersonCacheCompoundKeyEntry.getKey();
934  GluuSimplePerson sourcePerson = sourcePersonCacheCompoundKeyEntry.getValue();
935 
936  if (log.isTraceEnabled()) {
937  log.trace("Checking source entry with key: '{}', and DN: {}", cacheCompoundKey, sourcePerson.getDn());
938  }
939 
940  GluuInumMap currentInumMap = primaryKeyAttrValueInumMap.get(cacheCompoundKey);
941  if (currentInumMap == null) {
942  String[][] keyAttributesValues = getKeyAttributesValues(keyAttributesWithoutValues, sourcePerson);
943  currentInumMap = addGluuInumMap(inumbaseDn, inumDbPersistenceEntryManager, keyAttributesWithoutValues, keyAttributesValues);
944  result.put(cacheCompoundKey, currentInumMap);
945  log.debug("Added new inum entry for DN: {}", sourcePerson.getDn());
946  } else {
947  log.trace("Inum entry for DN: '{}' exist", sourcePerson.getDn());
948  }
949  }
950 
951  return result;
952  }
String [][] getKeyAttributesValues(String[] attrs, GluuSimplePerson person)
Definition: CacheRefreshTimer.java:1104
GluuInumMap addGluuInumMap(String inumbBaseDn, PersistenceEntryManager inumDbPersistenceEntryManager, String[] primaryKeyAttrName, String[][] primaryKeyValues)
Definition: CacheRefreshTimer.java:899
Logger log
Definition: CacheRefreshTimer.java:94
String [] getCompoundKeyAttributesWithoutValues(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshTimer.java:1177

◆ applyChangesToInumMap()

ArrayList<GluuInumMap> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.applyChangesToInumMap ( HashMap< String, GluuInumMap inumInumMap,
HashMap< CacheCompoundKey, GluuInumMap addedPrimaryKeyAttrValueInumMap,
List< String >  removedGluuInumMaps 
)
inlineprivate
455  {
456  log.info("There are '{}' entries before updating inum list", inumInumMap.size());
457  for (String removedGluuInumMap : removedGluuInumMaps) {
458  inumInumMap.remove(removedGluuInumMap);
459  }
460  log.info("There are '{}' entries after removal '{}' entries", inumInumMap.size(), removedGluuInumMaps.size());
461 
462  ArrayList<GluuInumMap> currentInumMaps = new ArrayList<GluuInumMap>(inumInumMap.values());
463  currentInumMaps.addAll(addedPrimaryKeyAttrValueInumMap.values());
464  log.info("There are '{}' entries after adding '{}' entries", currentInumMaps.size(), addedPrimaryKeyAttrValueInumMap.size());
465 
466  return currentInumMaps;
467  }
Logger log
Definition: CacheRefreshTimer.java:94

◆ closeLdapServerConnection()

void org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.closeLdapServerConnection ( LdapServerConnection...  ldapServerConnections)
inlineprivate
1082  {
1083  for (LdapServerConnection ldapServerConnection : ldapServerConnections) {
1084  if ((ldapServerConnection != null) && (ldapServerConnection.getPersistenceEntryManager() != null)) {
1085  ldapServerConnection.getPersistenceEntryManager().destroy();
1086  }
1087  }
1088  }

◆ createTwoLettersArray()

String [] org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.createTwoLettersArray ( )
inlineprivate
1090  {
1091  char[] characters = LETTERS_FOR_SEARCH.toCharArray();
1092  int lettersCount = characters.length;
1093 
1094  String[] result = new String[lettersCount * lettersCount];
1095  for (int i = 0; i < lettersCount; i++) {
1096  for (int j = 0; j < lettersCount; j++) {
1097  result[i * lettersCount + j] = "" + characters[i] + characters[j];
1098  }
1099  }
1100 
1101  return result;
1102  }
static final String LETTERS_FOR_SEARCH
Definition: CacheRefreshTimer.java:88

◆ detectChangedEntries()

boolean org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.detectChangedEntries ( CacheRefreshConfiguration  cacheRefreshConfiguration,
GluuAppliance  currentAppliance,
LdapServerConnection []  sourceServerConnections,
LdapServerConnection  inumDbServerConnection,
LdapServerConnection  targetServerConnection,
CacheRefreshUpdateMethod  updateMethod 
)
inlineprivate
316  {
317  boolean isVDSMode = CacheRefreshUpdateMethod.VDS.equals(updateMethod);
318 
319  // Load all entries from Source servers
320  log.info("Attempting to load entries from source server");
321  List<GluuSimplePerson> sourcePersons;
322 
323  if (cacheRefreshConfiguration.isUseSearchLimit()) {
324  sourcePersons = loadSourceServerEntries(cacheRefreshConfiguration, sourceServerConnections);
325  } else {
326  sourcePersons = loadSourceServerEntriesWithoutLimits(cacheRefreshConfiguration, sourceServerConnections);
327  }
328 
329  log.info("Found '{}' entries in source server", sourcePersons.size());
330 
331  Map<CacheCompoundKey, GluuSimplePerson> sourcePersonCacheCompoundKeyMap = getSourcePersonCompoundKeyMap(cacheRefreshConfiguration, sourcePersons);
332  log.info("Found '{}' unique entries in source server", sourcePersonCacheCompoundKeyMap.size());
333 
334  // Load all inum entries
335  List<GluuInumMap> inumMaps = null;
336 
337  // Load all inum entries from local disk cache
338  String inumCachePath = getInumCachePath(cacheRefreshConfiguration);
339  Object loadedObject = objectSerializationService.loadObject(inumCachePath);
340  if (loadedObject != null) {
341  try {
342  inumMaps = (List<GluuInumMap>) loadedObject;
343  log.debug("Found '{}' entries in inum objects disk cache", inumMaps.size());
344  } catch (Exception ex) {
345  log.error("Failed to convert to GluuInumMap list", ex);
346  objectSerializationService.cleanup(inumCachePath);
347  }
348  }
349 
350  if (inumMaps == null) {
351  // Load all inum entries from LDAP
352  inumMaps = loadInumServerEntries(cacheRefreshConfiguration, inumDbServerConnection);
353  log.info("Found '{}' entries in inum server", inumMaps.size());
354  }
355 
356  HashMap<CacheCompoundKey, GluuInumMap> primaryKeyAttrValueInumMap = getPrimaryKeyAttrValueInumMap(inumMaps);
357 
358  // Go through Source entries and create new InumMap entries if needed
359  HashMap<CacheCompoundKey, GluuInumMap> addedPrimaryKeyAttrValueInumMap = addNewInumServerEntries(cacheRefreshConfiguration, inumDbServerConnection,
360  sourcePersonCacheCompoundKeyMap, primaryKeyAttrValueInumMap);
361 
362  HashMap<CacheCompoundKey, GluuInumMap> allPrimaryKeyAttrValueInumMap = getAllInumServerEntries(primaryKeyAttrValueInumMap,
363  addedPrimaryKeyAttrValueInumMap);
364  log.debug("Count actual inum entries '{}' after updating inum server", allPrimaryKeyAttrValueInumMap.size());
365 
366  HashMap<String, Integer> currInumWithEntryHashCodeMap = getSourcePersonsHashCodesMap(inumDbServerConnection,
367  sourcePersonCacheCompoundKeyMap, allPrimaryKeyAttrValueInumMap);
368  log.debug("Count actual source entries '{}' after calculating hash code", currInumWithEntryHashCodeMap.size());
369 
370  // Create snapshots cache folder if needed
371  boolean result = cacheRefreshSnapshotFileService.prepareSnapshotsFolder(cacheRefreshConfiguration);
372  if (!result) {
373  return false;
374  }
375 
376  // Load last snapshot into memory
377  Map<String, Integer> prevInumWithEntryHashCodeMap = cacheRefreshSnapshotFileService.readLastSnapshot(cacheRefreshConfiguration);
378 
379  // Compare 2 snapshot and invoke update if needed
380  Set<String> changedInums = getChangedInums(currInumWithEntryHashCodeMap, prevInumWithEntryHashCodeMap, isVDSMode);
381  log.info("Found '{}' changed entries", changedInums.size());
382 
383  // Load problem list from disk and add to changedInums
384  List<String> problemInums = cacheRefreshSnapshotFileService.readProblemList(cacheRefreshConfiguration);
385  if (problemInums != null) {
386  log.info("Loaded '{}' problem entries from problem file", problemInums.size());
387  // Process inums from problem list too
388  changedInums.addAll(problemInums);
389  }
390 
391  List<String> updatedInums = null;
392  if (isVDSMode) {
393  // Update request to VDS to update entries on target server
394  updatedInums = updateTargetEntriesViaVDS(cacheRefreshConfiguration, targetServerConnection, changedInums);
395  } else {
396  updatedInums = updateTargetEntriesViaCopy(cacheRefreshConfiguration, sourcePersonCacheCompoundKeyMap, allPrimaryKeyAttrValueInumMap, changedInums);
397  }
398 
399  log.info("Updated '{}' entries", updatedInums.size());
400  changedInums.removeAll(updatedInums);
401  log.info("Failed to update '{}' entries", changedInums.size());
402 
403  // Persist snapshot to cache folder
404  result = cacheRefreshSnapshotFileService.createSnapshot(cacheRefreshConfiguration, currInumWithEntryHashCodeMap);
405  if (!result) {
406  return false;
407  }
408 
409  // Retain only specified number of snapshots
410  cacheRefreshSnapshotFileService.retainSnapshots(cacheRefreshConfiguration, cacheRefreshConfiguration.getSnapshotMaxCount());
411 
412  // Save changedInums as problem list to disk
413  currentAppliance.setVdsCacheRefreshProblemCount(String.valueOf(changedInums.size()));
414  cacheRefreshSnapshotFileService.writeProblemList(cacheRefreshConfiguration, changedInums);
415 
416  // Prepare list of persons for removal
417  List<GluuSimplePerson> personsForRemoval = null;
418 
419  boolean keepExternalPerson = cacheRefreshConfiguration.isKeepExternalPerson();
420  log.debug("Keep external persons: '{}'", keepExternalPerson);
421  if (keepExternalPerson) {
422  // Determine entries which need to remove
423  personsForRemoval = getRemovedPersons(currInumWithEntryHashCodeMap, prevInumWithEntryHashCodeMap);
424  } else {
425  // Process entries which don't exist in source server
426 
427  // Load all entries from Target server
428  List<GluuSimplePerson> targetPersons = loadTargetServerEntries(cacheRefreshConfiguration, ldapEntryManager);
429  log.info("Found '{}' entries in target server", targetPersons.size());
430 
431  // Detect entries which need to remove
432  personsForRemoval = processTargetPersons(targetPersons, currInumWithEntryHashCodeMap);
433  }
434  log.debug("Count entries '{}' for removal from target server", personsForRemoval.size());
435 
436  // Remove entries from target server
437  HashMap<String, GluuInumMap> inumInumMap = getInumInumMap(inumMaps);
438  Pair<List<String>, List<String>> removeTargetEntriesResult = removeTargetEntries(inumDbServerConnection, ldapEntryManager, personsForRemoval, inumInumMap);
439  List<String> removedPersonInums = removeTargetEntriesResult.getFirst();
440  List<String> removedGluuInumMaps = removeTargetEntriesResult.getSecond();
441  log.info("Removed '{}' persons from target server", removedPersonInums.size());
442 
443  // Prepare list of inum for serialization
444  ArrayList<GluuInumMap> currentInumMaps = applyChangesToInumMap(inumInumMap, addedPrimaryKeyAttrValueInumMap, removedGluuInumMaps);
445 
446  // Strore all inum entries into local disk cache
447  objectSerializationService.saveObject(inumCachePath, currentInumMaps);
448 
449  currentAppliance.setVdsCacheRefreshLastUpdateCount(String.valueOf(updatedInums.size() + removedPersonInums.size()));
450 
451  return true;
452  }
String getInumCachePath(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshTimer.java:1128
Set< String > getChangedInums(HashMap< String, Integer > currInumWithEntryHashCodeMap, Map< String, Integer > prevInumWithEntryHashCodeMap, boolean includeDeleted)
Definition: CacheRefreshTimer.java:469
CacheRefreshSnapshotFileService cacheRefreshSnapshotFileService
Definition: CacheRefreshTimer.java:121
List< GluuInumMap > loadInumServerEntries(CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection inumDbServerConnection)
Definition: CacheRefreshTimer.java:790
boolean createSnapshot(CacheRefreshConfiguration cacheRefreshConfiguration, Map< String, Integer > inumWithEntryHashCodeMap)
Definition: CacheRefreshSnapshotFileService.java:70
List< GluuSimplePerson > getRemovedPersons(HashMap< String, Integer > currInumWithEntryHashCodeMap, Map< String, Integer > prevInumWithEntryHashCodeMap)
Definition: CacheRefreshTimer.java:500
boolean retainSnapshots(CacheRefreshConfiguration cacheRefreshConfiguration, int count)
Definition: CacheRefreshSnapshotFileService.java:168
List< GluuSimplePerson > processTargetPersons(List< GluuSimplePerson > targetPersons, HashMap< String, Integer > currInumWithEntryHashCodeMap)
Definition: CacheRefreshTimer.java:984
HashMap< CacheCompoundKey, GluuInumMap > getPrimaryKeyAttrValueInumMap(List< GluuInumMap > inumMaps)
Definition: CacheRefreshTimer.java:999
List< GluuSimplePerson > loadSourceServerEntriesWithoutLimits(CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection[] sourceServerConnections)
Definition: CacheRefreshTimer.java:801
List< GluuSimplePerson > loadSourceServerEntries(CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection[] sourceServerConnections)
Definition: CacheRefreshTimer.java:845
ArrayList< GluuInumMap > applyChangesToInumMap(HashMap< String, GluuInumMap > inumInumMap, HashMap< CacheCompoundKey, GluuInumMap > addedPrimaryKeyAttrValueInumMap, List< String > removedGluuInumMaps)
Definition: CacheRefreshTimer.java:454
Map< CacheCompoundKey, GluuSimplePerson > getSourcePersonCompoundKeyMap(CacheRefreshConfiguration cacheRefreshConfiguration, List< GluuSimplePerson > sourcePersons)
Definition: CacheRefreshTimer.java:1021
HashMap< String, GluuInumMap > getInumInumMap(List< GluuInumMap > inumMaps)
Definition: CacheRefreshTimer.java:1011
PersistenceEntryManager ldapEntryManager
Definition: CacheRefreshTimer.java:115
Map< String, Integer > readLastSnapshot(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshSnapshotFileService.java:147
List< String > readProblemList(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshSnapshotFileService.java:188
List< String > updateTargetEntriesViaCopy(CacheRefreshConfiguration cacheRefreshConfiguration, Map< CacheCompoundKey, GluuSimplePerson > sourcePersonCacheCompoundKeyMap, HashMap< CacheCompoundKey, GluuInumMap > primaryKeyAttrValueInumMap, Set< String > changedInums)
Definition: CacheRefreshTimer.java:550
boolean prepareSnapshotsFolder(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshSnapshotFileService.java:54
HashMap< String, Integer > getSourcePersonsHashCodesMap(LdapServerConnection inumDbServerConnection, Map< CacheCompoundKey, GluuSimplePerson > sourcePersonCacheCompoundKeyMap, HashMap< CacheCompoundKey, GluuInumMap > primaryKeyAttrValueInumMap)
Definition: CacheRefreshTimer.java:965
Logger log
Definition: CacheRefreshTimer.java:94
List< GluuSimplePerson > loadTargetServerEntries(CacheRefreshConfiguration cacheRefreshConfiguration, PersistenceEntryManager targetPersistenceEntryManager)
Definition: CacheRefreshTimer.java:892
List< String > updateTargetEntriesViaVDS(CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection targetServerConnection, Set< String > changedInums)
Definition: CacheRefreshTimer.java:531
HashMap< CacheCompoundKey, GluuInumMap > addNewInumServerEntries(CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection inumDbServerConnection, Map< CacheCompoundKey, GluuSimplePerson > sourcePersonCacheCompoundKeyMap, HashMap< CacheCompoundKey, GluuInumMap > primaryKeyAttrValueInumMap)
Definition: CacheRefreshTimer.java:923
Pair< List< String >, List< String > > removeTargetEntries(LdapServerConnection inumDbServerConnection, PersistenceEntryManager targetPersistenceEntryManager, List< GluuSimplePerson > removedPersons, HashMap< String, GluuInumMap > inumInumMap)
Definition: CacheRefreshTimer.java:706
ObjectSerializationService objectSerializationService
Definition: CacheRefreshTimer.java:139
HashMap< CacheCompoundKey, GluuInumMap > getAllInumServerEntries(HashMap< CacheCompoundKey, GluuInumMap > primaryKeyAttrValueInumMap, HashMap< CacheCompoundKey, GluuInumMap > addedPrimaryKeyAttrValueInumMap)
Definition: CacheRefreshTimer.java:954
boolean writeProblemList(CacheRefreshConfiguration cacheRefreshConfiguration, Set< String > changedInums)
Definition: CacheRefreshSnapshotFileService.java:222

◆ getAllInumServerEntries()

HashMap<CacheCompoundKey, GluuInumMap> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.getAllInumServerEntries ( HashMap< CacheCompoundKey, GluuInumMap primaryKeyAttrValueInumMap,
HashMap< CacheCompoundKey, GluuInumMap addedPrimaryKeyAttrValueInumMap 
)
inlineprivate
956  {
957  HashMap<CacheCompoundKey, GluuInumMap> result = new HashMap<CacheCompoundKey, GluuInumMap>();
958 
959  result.putAll(primaryKeyAttrValueInumMap);
960  result.putAll(addedPrimaryKeyAttrValueInumMap);
961 
962  return result;
963  }

◆ getBaseDNs()

String [] org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.getBaseDNs ( GluuLdapConfiguration  ldapConfiguration)
inlineprivate
1216  {
1217  return ldapConfiguration.getBaseDNsStringsList().toArray(new String[0]);
1218  }

◆ getChangedInums()

Set<String> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.getChangedInums ( HashMap< String, Integer >  currInumWithEntryHashCodeMap,
Map< String, Integer >  prevInumWithEntryHashCodeMap,
boolean  includeDeleted 
)
inlineprivate
470  {
471  // Find chaged inums
472  Set<String> changedInums = null;
473  // First time run
474  if (prevInumWithEntryHashCodeMap == null) {
475  changedInums = new HashSet<String>(currInumWithEntryHashCodeMap.keySet());
476  } else {
477  changedInums = new HashSet<String>();
478 
479  // Add all inums which not exist in new snapshot
480  if (includeDeleted) {
481  for (String prevInumKey : prevInumWithEntryHashCodeMap.keySet()) {
482  if (!currInumWithEntryHashCodeMap.containsKey(prevInumKey)) {
483  changedInums.add(prevInumKey);
484  }
485  }
486  }
487 
488  // Add all new inums and changed inums
489  for (Entry<String, Integer> currEntry : currInumWithEntryHashCodeMap.entrySet()) {
490  String currInumKey = currEntry.getKey();
491  Integer prevHashCode = prevInumWithEntryHashCodeMap.get(currInumKey);
492  if ((prevHashCode == null) || ((prevHashCode != null) && !(prevHashCode.equals(currEntry.getValue())))) {
493  changedInums.add(currInumKey);
494  }
495  }
496  }
497  return changedInums;
498  }

◆ getCompoundKeyAttributes()

String [] org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.getCompoundKeyAttributes ( CacheRefreshConfiguration  cacheRefreshConfiguration)
inlineprivate
1169  {
1170  return cacheRefreshConfiguration.getKeyAttributes().toArray(new String[0]);
1171  }

◆ getCompoundKeyAttributesWithoutValues()

String [] org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.getCompoundKeyAttributesWithoutValues ( CacheRefreshConfiguration  cacheRefreshConfiguration)
inlineprivate
1177  {
1178  String[] result = cacheRefreshConfiguration.getKeyAttributes().toArray(new String[0]);
1179  for (int i = 0; i < result.length; i++) {
1180  int index = result[i].indexOf('=');
1181  if (index != -1) {
1182  result[i] = result[i].substring(0, index);
1183  }
1184  }
1185 
1186  return result;
1187  }

◆ getCompoundKeyObjectClasses()

String [] org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.getCompoundKeyObjectClasses ( CacheRefreshConfiguration  cacheRefreshConfiguration)
inlineprivate
1173  {
1174  return cacheRefreshConfiguration.getKeyObjectClasses().toArray(new String[0]);
1175  }

◆ getInumCacheCompoundKeyMap()

HashMap<String, CacheCompoundKey> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.getInumCacheCompoundKeyMap ( HashMap< CacheCompoundKey, GluuInumMap primaryKeyAttrValueInumMap)
inlineprivate
696  {
697  HashMap<String, CacheCompoundKey> result = new HashMap<String, CacheCompoundKey>();
698 
699  for (Entry<CacheCompoundKey, GluuInumMap> primaryKeyAttrValueInumMapEntry : primaryKeyAttrValueInumMap.entrySet()) {
700  result.put(primaryKeyAttrValueInumMapEntry.getValue().getInum(), primaryKeyAttrValueInumMapEntry.getKey());
701  }
702 
703  return result;
704  }

◆ getInumCachePath()

String org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.getInumCachePath ( CacheRefreshConfiguration  cacheRefreshConfiguration)
inlineprivate
1128  {
1129  return FilenameUtils.concat(cacheRefreshConfiguration.getSnapshotFolder(), "inum_cache.dat");
1130  }

◆ getInumInumMap()

HashMap<String, GluuInumMap> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.getInumInumMap ( List< GluuInumMap inumMaps)
inlineprivate
1011  {
1012  HashMap<String, GluuInumMap> result = new HashMap<String, GluuInumMap>();
1013 
1014  for (GluuInumMap inumMap : inumMaps) {
1015  result.put(inumMap.getInum(), inumMap);
1016  }
1017 
1018  return result;
1019  }

◆ getKeyAttributesValues()

String [][] org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.getKeyAttributesValues ( String []  attrs,
GluuSimplePerson  person 
)
inlineprivate
1104  {
1105  String[][] result = new String[attrs.length][];
1106  for (int i = 0; i < attrs.length; i++) {
1107  result[i] = person.getAttributes(attrs[i]);
1108  }
1109 
1110  return result;
1111  }

◆ getMarkInumMapEntryAsRemoved()

GluuInumMap org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.getMarkInumMapEntryAsRemoved ( GluuInumMap  currentInumMap,
String  date 
)
inlineprivate
748  {
749  GluuInumMap clonedInumMap;
750  try {
751  clonedInumMap = (GluuInumMap) BeanUtilsBean2.getInstance().cloneBean(currentInumMap);
752  } catch (Exception ex) {
753  log.error("Failed to prepare GluuInumMap for removal", ex);
754  return null;
755  }
756 
757  String suffix = "-" + date;
758 
759  String[] primaryKeyValues = ArrayHelper.arrayClone(clonedInumMap.getPrimaryKeyValues());
760  String[] secondaryKeyValues = ArrayHelper.arrayClone(clonedInumMap.getSecondaryKeyValues());
761  String[] tertiaryKeyValues = ArrayHelper.arrayClone(clonedInumMap.getTertiaryKeyValues());
762 
763  if (ArrayHelper.isNotEmpty(primaryKeyValues)) {
764  markInumMapEntryKeyValuesAsRemoved(primaryKeyValues, suffix);
765  }
766 
767  if (ArrayHelper.isNotEmpty(secondaryKeyValues)) {
768  markInumMapEntryKeyValuesAsRemoved(secondaryKeyValues, suffix);
769  }
770 
771  if (ArrayHelper.isNotEmpty(tertiaryKeyValues)) {
772  markInumMapEntryKeyValuesAsRemoved(tertiaryKeyValues, suffix);
773  }
774 
775  clonedInumMap.setPrimaryKeyValues(primaryKeyValues);
776  clonedInumMap.setSecondaryKeyValues(secondaryKeyValues);
777  clonedInumMap.setTertiaryKeyValues(tertiaryKeyValues);
778 
779  clonedInumMap.setStatus(GluuStatus.INACTIVE);
780 
781  return clonedInumMap;
782  }
void markInumMapEntryKeyValuesAsRemoved(String[] keyValues, String suffix)
Definition: CacheRefreshTimer.java:784
Logger log
Definition: CacheRefreshTimer.java:94

◆ getPrimaryKeyAttrValueInumMap()

HashMap<CacheCompoundKey, GluuInumMap> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.getPrimaryKeyAttrValueInumMap ( List< GluuInumMap inumMaps)
inlineprivate
999  {
1000  HashMap<CacheCompoundKey, GluuInumMap> result = new HashMap<CacheCompoundKey, GluuInumMap>();
1001 
1002  for (GluuInumMap inumMap : inumMaps) {
1003  result.put(
1004  new CacheCompoundKey(inumMap.getPrimaryKeyValues(), inumMap.getSecondaryKeyValues(), inumMap.getTertiaryKeyValues()),
1005  inumMap);
1006  }
1007 
1008  return result;
1009  }

◆ getRemovedPersons()

List<GluuSimplePerson> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.getRemovedPersons ( HashMap< String, Integer >  currInumWithEntryHashCodeMap,
Map< String, Integer >  prevInumWithEntryHashCodeMap 
)
inlineprivate
501  {
502  // First time run
503  if (prevInumWithEntryHashCodeMap == null) {
504  return new ArrayList<GluuSimplePerson>(0);
505  }
506 
507  // Add all inums which not exist in new snapshot
508  Set<String> deletedInums = new HashSet<String>();
509  for (String prevInumKey : prevInumWithEntryHashCodeMap.keySet()) {
510  if (!currInumWithEntryHashCodeMap.containsKey(prevInumKey)) {
511  deletedInums.add(prevInumKey);
512  }
513  }
514 
515  List<GluuSimplePerson> deletedPersons = new ArrayList<GluuSimplePerson>(deletedInums.size());
516  for (String deletedInum : deletedInums) {
517  GluuSimplePerson person = new GluuSimplePerson();
518  String personDn = personService.getDnForPerson(deletedInum);
519  person.setDn(personDn);
520 
521  List<GluuCustomAttribute> customAttributes = new ArrayList<GluuCustomAttribute>();
522  customAttributes.add(new GluuCustomAttribute(OxTrustConstants.inum, deletedInum));
523  person.setCustomAttributes(customAttributes);
524 
525  deletedPersons.add(person);
526  }
527 
528  return deletedPersons;
529  }
IPersonService personService
Definition: CacheRefreshTimer.java:112
abstract String getDnForPerson(String inum)

◆ getSourceAttributes()

String [] org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.getSourceAttributes ( CacheRefreshConfiguration  cacheRefreshConfiguration)
inlineprivate
1165  {
1166  return cacheRefreshConfiguration.getSourceAttributes().toArray(new String[0]);
1167  }

◆ getSourcePersonCompoundKeyMap()

Map<CacheCompoundKey, GluuSimplePerson> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.getSourcePersonCompoundKeyMap ( CacheRefreshConfiguration  cacheRefreshConfiguration,
List< GluuSimplePerson sourcePersons 
)
inlineprivate
1021  {
1022  Map<CacheCompoundKey, GluuSimplePerson> result = new HashMap<CacheCompoundKey, GluuSimplePerson>();
1023  Set<CacheCompoundKey> duplicateKeys = new HashSet<CacheCompoundKey>();
1024 
1025  String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
1026  for (GluuSimplePerson sourcePerson : sourcePersons) {
1027  String[][] keyAttributesValues = getKeyAttributesValues(keyAttributesWithoutValues, sourcePerson);
1028  CacheCompoundKey cacheCompoundKey = new CacheCompoundKey(keyAttributesValues);
1029 
1030  if (result.containsKey(cacheCompoundKey)) {
1031  duplicateKeys.add(cacheCompoundKey);
1032  }
1033 
1034  result.put(cacheCompoundKey, sourcePerson);
1035  }
1036 
1037  for (CacheCompoundKey duplicateKey : duplicateKeys) {
1038  log.error("Non-deterministic primary key. Skipping user with key: {}", duplicateKey);
1039  result.remove(duplicateKey);
1040  }
1041 
1042  return result;
1043  }
String [][] getKeyAttributesValues(String[] attrs, GluuSimplePerson person)
Definition: CacheRefreshTimer.java:1104
Logger log
Definition: CacheRefreshTimer.java:94
String [] getCompoundKeyAttributesWithoutValues(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshTimer.java:1177

◆ getSourcePersonsHashCodesMap()

HashMap<String, Integer> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.getSourcePersonsHashCodesMap ( LdapServerConnection  inumDbServerConnection,
Map< CacheCompoundKey, GluuSimplePerson sourcePersonCacheCompoundKeyMap,
HashMap< CacheCompoundKey, GluuInumMap primaryKeyAttrValueInumMap 
)
inlineprivate
967  {
968  PersistenceEntryManager inumDbPersistenceEntryManager = inumDbServerConnection.getPersistenceEntryManager();
969 
970  HashMap<String, Integer> result = new HashMap<String, Integer>();
971 
972  for (Entry<CacheCompoundKey, GluuSimplePerson> sourcePersonCacheCompoundKeyEntry : sourcePersonCacheCompoundKeyMap.entrySet()) {
973  CacheCompoundKey cacheCompoundKey = sourcePersonCacheCompoundKeyEntry.getKey();
974  GluuSimplePerson sourcePerson = sourcePersonCacheCompoundKeyEntry.getValue();
975 
976  GluuInumMap currentInumMap = primaryKeyAttrValueInumMap.get(cacheCompoundKey);
977 
978  result.put(currentInumMap.getInum(), inumDbPersistenceEntryManager.getHashCode(sourcePerson));
979  }
980 
981  return result;
982  }

◆ getTargetServerAttributesMapping()

Map<String, String> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.getTargetServerAttributesMapping ( CacheRefreshConfiguration  cacheRefreshConfiguration)
inlineprivate
1189  {
1190  Map<String, String> result = new HashMap<String, String>();
1191  for (CacheRefreshAttributeMapping attributeMapping : cacheRefreshConfiguration.getAttributeMapping()) {
1192  result.put(attributeMapping.getDestination(), attributeMapping.getSource());
1193  }
1194 
1195  return result;
1196  }

◆ getUpdateMethod()

CacheRefreshUpdateMethod org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.getUpdateMethod ( CacheRefreshConfiguration  cacheRefreshConfiguration)
inlineprivate
1156  {
1157  String updateMethod = cacheRefreshConfiguration.getUpdateMethod();
1158  if (StringHelper.isEmpty(updateMethod)) {
1159  return CacheRefreshUpdateMethod.COPY;
1160  }
1161 
1162  return CacheRefreshUpdateMethod.getByValue(cacheRefreshConfiguration.getUpdateMethod());
1163  }

◆ initTimer()

void org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.initTimer ( )
inline
144  {
145  log.info("Initializing Cache Refresh Timer");
146  this.isActive = new AtomicBoolean(false);
147 
148  // Clean up previous Inum cache
149  CacheRefreshConfiguration cacheRefreshConfiguration = configurationFactory.getCacheRefreshConfiguration();
150  if (cacheRefreshConfiguration != null) {
151  String snapshotFolder = cacheRefreshConfiguration.getSnapshotFolder();
152  if (StringHelper.isNotEmpty(snapshotFolder)) {
153  String inumCachePath = getInumCachePath(cacheRefreshConfiguration);
154  objectSerializationService.cleanup(inumCachePath);
155  }
156  }
157 
158  // Schedule to start cache refresh every 1 minute
159  final int delay = 1 * 60;
160  final int interval = DEFAULT_INTERVAL;
161 
162  timerEvent.fire(new TimerEvent(new TimerSchedule(delay, DEFAULT_INTERVAL), new CacheRefreshEvent(),
163  Scheduled.Literal.INSTANCE));
164 
165  this.lastFinishedTime = System.currentTimeMillis();
166  }
String getInumCachePath(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshTimer.java:1128
static final int DEFAULT_INTERVAL
Definition: CacheRefreshTimer.java:91
long lastFinishedTime
Definition: CacheRefreshTimer.java:142
ConfigurationFactory configurationFactory
Definition: CacheRefreshTimer.java:106
AtomicBoolean isActive
Definition: CacheRefreshTimer.java:141
Event< TimerEvent > timerEvent
Definition: CacheRefreshTimer.java:97
Logger log
Definition: CacheRefreshTimer.java:94
ObjectSerializationService objectSerializationService
Definition: CacheRefreshTimer.java:139
CacheRefreshConfiguration getCacheRefreshConfiguration()
Definition: ConfigurationFactory.java:282

◆ isStartCacheRefresh()

boolean org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.isStartCacheRefresh ( CacheRefreshConfiguration  cacheRefreshConfiguration,
GluuAppliance  currentAppliance 
)
inlineprivate
207  {
208  if (!GluuBoolean.ENABLED.equals(currentAppliance.getVdsCacheRefreshEnabled())) {
209  return false;
210  }
211 
212  long poolingInterval = StringHelper.toInteger(currentAppliance.getVdsCacheRefreshPollingInterval()) * 60 * 1000;
213  if (poolingInterval < 0) {
214  return false;
215  }
216 
217  String cacheRefreshServerIpAddress = currentAppliance.getCacheRefreshServerIpAddress();
218  if (StringHelper.isEmpty(cacheRefreshServerIpAddress)) {
219  log.debug("There is no master Cache Refresh server");
220  return false;
221  }
222 
223  // Compare server IP address with cacheRefreshServerIp
224  boolean cacheRefreshServer = false;
225  try {
226  Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
227  for (NetworkInterface networkInterface : Collections.list(nets)) {
228  Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
229  for (InetAddress inetAddress : Collections.list(inetAddresses)) {
230  if (StringHelper.equals(cacheRefreshServerIpAddress, inetAddress.getHostAddress())) {
231  cacheRefreshServer = true;
232  break;
233  }
234  }
235 
236  if (cacheRefreshServer) {
237  break;
238  }
239  }
240  } catch (SocketException ex) {
241  log.error("Failed to enumerate server IP addresses", ex);
242  }
243 
244  if (!cacheRefreshServer) {
245  log.debug("This server isn't master Cache Refresh server");
246  return false;
247  }
248 
249  // Check if cache refresh specific configuration was loaded
250  if (cacheRefreshConfiguration == null) {
251  log.info("Failed to start cache refresh. Can't loading configuration from oxTrustCacheRefresh.properties");
252  return false;
253  }
254 
255  long timeDiffrence = System.currentTimeMillis() - this.lastFinishedTime;
256 
257  return timeDiffrence >= poolingInterval;
258  }
long lastFinishedTime
Definition: CacheRefreshTimer.java:142
Logger log
Definition: CacheRefreshTimer.java:94

◆ loadInumServerEntries()

List<GluuInumMap> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.loadInumServerEntries ( CacheRefreshConfiguration  cacheRefreshConfiguration,
LdapServerConnection  inumDbServerConnection 
)
inlineprivate
790  {
791  PersistenceEntryManager inumDbPersistenceEntryManager = inumDbServerConnection.getPersistenceEntryManager();
792  String inumbaseDn = inumDbServerConnection.getBaseDns()[0];
793 
794  Filter filterObjectClass = Filter.createEqualityFilter(OxConstants.OBJECT_CLASS, OxTrustConstants.objectClassInumMap);
795  Filter filterStatus = Filter.createNOTFilter(Filter.createEqualityFilter(OxTrustConstants.gluuStatus, GluuStatus.INACTIVE.getValue()));
796  Filter filter = Filter.createANDFilter(filterObjectClass, filterStatus);
797 
798  return inumDbPersistenceEntryManager.findEntries(inumbaseDn, GluuInumMap.class, filter, SearchScope.SUB, null, null, 0, 0, cacheRefreshConfiguration.getLdapSearchSizeLimit());
799  }

◆ loadSourceServerEntries()

List<GluuSimplePerson> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.loadSourceServerEntries ( CacheRefreshConfiguration  cacheRefreshConfiguration,
LdapServerConnection []  sourceServerConnections 
)
inlineprivate
845  {
846  Filter customFilter = cacheRefreshService.createFilter(cacheRefreshConfiguration.getCustomLdapFilter());
847  String[] keyAttributes = getCompoundKeyAttributes(cacheRefreshConfiguration);
848  String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
849  String[] keyObjectClasses = getCompoundKeyObjectClasses(cacheRefreshConfiguration);
850  String[] sourceAttributes = getSourceAttributes(cacheRefreshConfiguration);
851 
852  String[] twoLettersArray = createTwoLettersArray();
853  String[] returnAttributes = ArrayHelper.arrayMerge(keyAttributesWithoutValues, sourceAttributes);
854 
855  Set<String> addedDns = new HashSet<String>();
856 
857  List<GluuSimplePerson> sourcePersons = new ArrayList<GluuSimplePerson>();
858  for (LdapServerConnection sourceServerConnection : sourceServerConnections) {
859  String sourceServerName = sourceServerConnection.getSourceServerName();
860 
861  PersistenceEntryManager sourcePersistenceEntryManager = sourceServerConnection.getPersistenceEntryManager();
862  String[] baseDns = sourceServerConnection.getBaseDns();
863  for (String keyAttributeStart : twoLettersArray) {
864  Filter filter = cacheRefreshService.createFilter(keyAttributes, keyObjectClasses, keyAttributeStart, customFilter);
865  if (log.isDebugEnabled()) {
866  log.trace("Using next filter to load entris from source server: {}", filter);
867  }
868 
869  for (String baseDn : baseDns) {
870  List<GluuSimplePerson> currentSourcePersons = sourcePersistenceEntryManager.findEntries(baseDn, GluuSimplePerson.class,
871  filter, SearchScope.SUB, returnAttributes, null, 0, 0, cacheRefreshConfiguration.getLdapSearchSizeLimit());
872 
873  // Add to result and ignore root entry if needed
874  for (GluuSimplePerson currentSourcePerson : currentSourcePersons) {
875  currentSourcePerson.setSourceServerName(sourceServerName);
876  // if (!StringHelper.equalsIgnoreCase(baseDn,
877  // currentSourcePerson.getDn())) {
878  String currentSourcePersonDn = currentSourcePerson.getDn().toLowerCase();
879  if (!addedDns.contains(currentSourcePersonDn)) {
880  sourcePersons.add(currentSourcePerson);
881  addedDns.add(currentSourcePersonDn);
882  }
883  // }
884  }
885  }
886  }
887  }
888 
889  return sourcePersons;
890  }
String [] getSourceAttributes(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshTimer.java:1165
String [] getCompoundKeyObjectClasses(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshTimer.java:1173
String [] createTwoLettersArray()
Definition: CacheRefreshTimer.java:1090
CacheRefreshService cacheRefreshService
Definition: CacheRefreshTimer.java:109
String [] getCompoundKeyAttributes(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshTimer.java:1169
Logger log
Definition: CacheRefreshTimer.java:94
String [] getCompoundKeyAttributesWithoutValues(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshTimer.java:1177
Filter createFilter(String customLdapFilter)
Definition: CacheRefreshService.java:52

◆ loadSourceServerEntriesWithoutLimits()

List<GluuSimplePerson> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.loadSourceServerEntriesWithoutLimits ( CacheRefreshConfiguration  cacheRefreshConfiguration,
LdapServerConnection []  sourceServerConnections 
)
inlineprivate
801  {
802  Filter customFilter = cacheRefreshService.createFilter(cacheRefreshConfiguration.getCustomLdapFilter());
803  String[] keyAttributes = getCompoundKeyAttributes(cacheRefreshConfiguration);
804  String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
805  String[] keyObjectClasses = getCompoundKeyObjectClasses(cacheRefreshConfiguration);
806  String[] sourceAttributes = getSourceAttributes(cacheRefreshConfiguration);
807 
808  String[] returnAttributes = ArrayHelper.arrayMerge(keyAttributesWithoutValues, sourceAttributes);
809 
810  Set<String> addedDns = new HashSet<String>();
811 
812  List<GluuSimplePerson> sourcePersons = new ArrayList<GluuSimplePerson>();
813  for (LdapServerConnection sourceServerConnection : sourceServerConnections) {
814  String sourceServerName = sourceServerConnection.getSourceServerName();
815 
816  PersistenceEntryManager sourcePersistenceEntryManager = sourceServerConnection.getPersistenceEntryManager();
817  String[] baseDns = sourceServerConnection.getBaseDns();
818  Filter filter = cacheRefreshService.createFilter(keyAttributes, keyObjectClasses, "", customFilter);
819  if (log.isTraceEnabled()) {
820  log.trace("Using next filter to load entris from source server: {}", filter);
821  }
822 
823  for (String baseDn : baseDns) {
824  List<GluuSimplePerson> currentSourcePersons = sourcePersistenceEntryManager.findEntries(baseDn, GluuSimplePerson.class,
825  filter, SearchScope.SUB, returnAttributes, null, 0, 0, cacheRefreshConfiguration.getLdapSearchSizeLimit());
826 
827  // Add to result and ignore root entry if needed
828  for (GluuSimplePerson currentSourcePerson : currentSourcePersons) {
829  currentSourcePerson.setSourceServerName(sourceServerName);
830  // if (!StringHelper.equalsIgnoreCase(baseDn,
831  // currentSourcePerson.getDn())) {
832  String currentSourcePersonDn = currentSourcePerson.getDn().toLowerCase();
833  if (!addedDns.contains(currentSourcePersonDn)) {
834  sourcePersons.add(currentSourcePerson);
835  addedDns.add(currentSourcePersonDn);
836  }
837  // }
838  }
839  }
840  }
841 
842  return sourcePersons;
843  }
String [] getSourceAttributes(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshTimer.java:1165
String [] getCompoundKeyObjectClasses(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshTimer.java:1173
CacheRefreshService cacheRefreshService
Definition: CacheRefreshTimer.java:109
String [] getCompoundKeyAttributes(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshTimer.java:1169
Logger log
Definition: CacheRefreshTimer.java:94
String [] getCompoundKeyAttributesWithoutValues(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshTimer.java:1177
Filter createFilter(String customLdapFilter)
Definition: CacheRefreshService.java:52

◆ loadTargetServerEntries()

List<GluuSimplePerson> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.loadTargetServerEntries ( CacheRefreshConfiguration  cacheRefreshConfiguration,
PersistenceEntryManager  targetPersistenceEntryManager 
)
inlineprivate
892  {
893  Filter filter = Filter.createEqualityFilter(OxConstants.OBJECT_CLASS, OxTrustConstants.objectClassPerson);
894 
895  return targetPersistenceEntryManager.findEntries(personService.getDnForPerson(null), GluuSimplePerson.class, filter, SearchScope.SUB,
896  TARGET_PERSON_RETURN_ATTRIBUTES, null, 0, 0, cacheRefreshConfiguration.getLdapSearchSizeLimit());
897  }
IPersonService personService
Definition: CacheRefreshTimer.java:112
abstract String getDnForPerson(String inum)
static final String [] TARGET_PERSON_RETURN_ATTRIBUTES
Definition: CacheRefreshTimer.java:89

◆ markInumMapEntryKeyValuesAsRemoved()

void org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.markInumMapEntryKeyValuesAsRemoved ( String []  keyValues,
String  suffix 
)
inlineprivate
784  {
785  for (int i = 0; i < keyValues.length; i++) {
786  keyValues[i] = keyValues[i] + suffix;
787  }
788  }

◆ prepareLdapServerConnection() [1/2]

LdapServerConnection org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.prepareLdapServerConnection ( CacheRefreshConfiguration  cacheRefreshConfiguration,
GluuLdapConfiguration  ldapConfiguration 
)
inlineprivate
1057  {
1058  return prepareLdapServerConnection(cacheRefreshConfiguration, ldapConfiguration, false);
1059  }
LdapServerConnection prepareLdapServerConnection(CacheRefreshConfiguration cacheRefreshConfiguration, GluuLdapConfiguration ldapConfiguration)
Definition: CacheRefreshTimer.java:1057

◆ prepareLdapServerConnection() [2/2]

LdapServerConnection org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.prepareLdapServerConnection ( CacheRefreshConfiguration  cacheRefreshConfiguration,
GluuLdapConfiguration  ldapConfiguration,
boolean  useLocalConnection 
)
inlineprivate
1061  {
1062  String ldapConfig = ldapConfiguration.getConfigId();
1063 
1064  if (useLocalConnection) {
1065  return new LdapServerConnection(ldapConfig, ldapEntryManager, getBaseDNs(ldapConfiguration));
1066  }
1067 
1068  Properties ldapProperties = toLdapProperties(ldapConfiguration);
1069  Properties ldapDecryptedProperties = encryptionService.decryptProperties(ldapProperties);
1070 
1071  PersistenceEntryManager customPersistenceEntryManager = applicationFactory.getPersistenceEntryManagerFactory().createEntryManager(ldapDecryptedProperties);
1072  log.info("Created Cache Refresh PersistenceEntryManager: {}", customPersistenceEntryManager);
1073 
1074  if (!customPersistenceEntryManager.getOperationService().isConnected()) {
1075  log.error("Failed to connect to LDAP server using configuration {}", ldapConfig);
1076  return null;
1077  }
1078 
1079  return new LdapServerConnection(ldapConfig, customPersistenceEntryManager, getBaseDNs(ldapConfiguration));
1080  }
EncryptionService encryptionService
Definition: CacheRefreshTimer.java:136
String [] getBaseDNs(GluuLdapConfiguration ldapConfiguration)
Definition: CacheRefreshTimer.java:1216
Properties toLdapProperties(GluuLdapConfiguration ldapConfiguration)
Definition: CacheRefreshTimer.java:1198
ApplicationFactory applicationFactory
Definition: CacheRefreshTimer.java:100
PersistenceEntryManagerFactory getPersistenceEntryManagerFactory()
Definition: ApplicationFactory.java:91
PersistenceEntryManager ldapEntryManager
Definition: CacheRefreshTimer.java:115
Properties decryptProperties(Properties connectionProperties)
Definition: EncryptionService.java:50
Logger log
Definition: CacheRefreshTimer.java:94

◆ prepareLdapServerConnections()

LdapServerConnection [] org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.prepareLdapServerConnections ( CacheRefreshConfiguration  cacheRefreshConfiguration,
List< GluuLdapConfiguration >  ldapConfigurations 
)
inlineprivate
1045  {
1046  LdapServerConnection[] ldapServerConnections = new LdapServerConnection[ldapConfigurations.size()];
1047  for (int i = 0; i < ldapConfigurations.size(); i++) {
1048  ldapServerConnections[i] = prepareLdapServerConnection(cacheRefreshConfiguration, ldapConfigurations.get(i));
1049  if (ldapServerConnections[i] == null) {
1050  return null;
1051  }
1052  }
1053 
1054  return ldapServerConnections;
1055  }
LdapServerConnection prepareLdapServerConnection(CacheRefreshConfiguration cacheRefreshConfiguration, GluuLdapConfiguration ldapConfiguration)
Definition: CacheRefreshTimer.java:1057

◆ process()

void org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.process ( @Observes @Scheduled CacheRefreshEvent  cacheRefreshEvent)
inline
169  {
170  if (this.isActive.get()) {
171  log.debug("Another process is active");
172  return;
173  }
174 
175  if (!this.isActive.compareAndSet(false, true)) {
176  log.debug("Failed to start process exclusively");
177  return;
178  }
179 
180  try {
181  processInt();
182  } finally {
183  log.debug("Allowing to run new process exclusively");
184  this.isActive.set(false);
185  }
186  }
AtomicBoolean isActive
Definition: CacheRefreshTimer.java:141
void processInt()
Definition: CacheRefreshTimer.java:188
Logger log
Definition: CacheRefreshTimer.java:94

◆ processImpl()

void org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.processImpl ( CacheRefreshConfiguration  cacheRefreshConfiguration,
GluuAppliance  currentAppliance 
)
inlineprivate
260  {
261  CacheRefreshUpdateMethod updateMethod = getUpdateMethod(cacheRefreshConfiguration);
262 
263  // Prepare and check connections to LDAP servers
264  LdapServerConnection[] sourceServerConnections = prepareLdapServerConnections(cacheRefreshConfiguration, cacheRefreshConfiguration.getSourceConfigs());
265 
266  LdapServerConnection inumDbServerConnection;
267  if (cacheRefreshConfiguration.isDefaultInumServer()) {
268  GluuLdapConfiguration ldapInumConfiguration = new GluuLdapConfiguration();
269  ldapInumConfiguration.setConfigId("local_inum");
270  ldapInumConfiguration.setBaseDNsStringsList(Arrays.asList(new String[] { OxTrustConstants.CACHE_REFRESH_DEFAULT_BASE_DN }));
271 
272  inumDbServerConnection = prepareLdapServerConnection(cacheRefreshConfiguration, ldapInumConfiguration, true);
273  } else {
274  inumDbServerConnection = prepareLdapServerConnection(cacheRefreshConfiguration, cacheRefreshConfiguration.getInumConfig());
275  }
276 
277  boolean isVdsUpdate = CacheRefreshUpdateMethod.VDS.equals(updateMethod);
278  LdapServerConnection targetServerConnection = null;
279  if (isVdsUpdate) {
280  targetServerConnection = prepareLdapServerConnection(cacheRefreshConfiguration, cacheRefreshConfiguration.getTargetConfig());
281  }
282 
283  try {
284  if ((sourceServerConnections == null) || (inumDbServerConnection == null) || (isVdsUpdate && (targetServerConnection == null))) {
285  log.error("Skipping cache refresh due to invalid server configuration");
286  } else {
287  detectChangedEntries(cacheRefreshConfiguration, currentAppliance, sourceServerConnections, inumDbServerConnection, targetServerConnection,
288  updateMethod);
289  }
290  } finally {
291  // Close connections to LDAP servers
292  try {
293  closeLdapServerConnection(sourceServerConnections);
294  } catch (Exception e) {
295  // Nothing can be done
296  }
297  try {
298  closeLdapServerConnection(inumDbServerConnection);
299  } catch (Exception e) {
300  // Nothing can be done
301  }
302  try {
303  if (isVdsUpdate) {
304  closeLdapServerConnection(targetServerConnection);
305  }
306  } catch (Exception e) {
307  // Nothing can be done
308  }
309  }
310 
311  return;
312  }
LdapServerConnection prepareLdapServerConnection(CacheRefreshConfiguration cacheRefreshConfiguration, GluuLdapConfiguration ldapConfiguration)
Definition: CacheRefreshTimer.java:1057
boolean detectChangedEntries(CacheRefreshConfiguration cacheRefreshConfiguration, GluuAppliance currentAppliance, LdapServerConnection[] sourceServerConnections, LdapServerConnection inumDbServerConnection, LdapServerConnection targetServerConnection, CacheRefreshUpdateMethod updateMethod)
Definition: CacheRefreshTimer.java:315
LdapServerConnection [] prepareLdapServerConnections(CacheRefreshConfiguration cacheRefreshConfiguration, List< GluuLdapConfiguration > ldapConfigurations)
Definition: CacheRefreshTimer.java:1045
Logger log
Definition: CacheRefreshTimer.java:94
CacheRefreshUpdateMethod getUpdateMethod(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshTimer.java:1156
void closeLdapServerConnection(LdapServerConnection... ldapServerConnections)
Definition: CacheRefreshTimer.java:1082

◆ processInt()

void org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.processInt ( )
inline
188  {
189  CacheRefreshConfiguration cacheRefreshConfiguration = configurationFactory.getCacheRefreshConfiguration();
190 
191  try {
192  GluuAppliance currentAppliance = applianceService.getAppliance();
193  if (!isStartCacheRefresh(cacheRefreshConfiguration, currentAppliance)) {
194  log.debug("Starting conditions aren't reached");
195  return;
196  }
197 
198  processImpl(cacheRefreshConfiguration, currentAppliance);
199  updateApplianceStatus(currentAppliance, System.currentTimeMillis());
200 
201  this.lastFinishedTime = System.currentTimeMillis();
202  } catch (Throwable ex) {
203  log.error("Exception happened while executing cache refresh synchronization", ex);
204  }
205  }
boolean isStartCacheRefresh(CacheRefreshConfiguration cacheRefreshConfiguration, GluuAppliance currentAppliance)
Definition: CacheRefreshTimer.java:207
GluuAppliance getAppliance(String[] returnAttributes)
Definition: ApplianceService.java:111
long lastFinishedTime
Definition: CacheRefreshTimer.java:142
void processImpl(CacheRefreshConfiguration cacheRefreshConfiguration, GluuAppliance currentAppliance)
Definition: CacheRefreshTimer.java:260
ConfigurationFactory configurationFactory
Definition: CacheRefreshTimer.java:106
void updateApplianceStatus(GluuAppliance currentAppliance, long lastRun)
Definition: CacheRefreshTimer.java:1113
Logger log
Definition: CacheRefreshTimer.java:94
ApplianceService applianceService
Definition: CacheRefreshTimer.java:118
CacheRefreshConfiguration getCacheRefreshConfiguration()
Definition: ConfigurationFactory.java:282

◆ processTargetPersons()

List<GluuSimplePerson> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.processTargetPersons ( List< GluuSimplePerson targetPersons,
HashMap< String, Integer >  currInumWithEntryHashCodeMap 
)
inlineprivate
985  {
986  List<GluuSimplePerson> result = new ArrayList<GluuSimplePerson>();
987 
988  for (GluuSimplePerson targetPerson : targetPersons) {
989  String personInum = targetPerson.getAttribute(OxTrustConstants.inum);
990  if (!currInumWithEntryHashCodeMap.containsKey(personInum)) {
991  log.debug("Person with such DN: '{}' isn't present on source server", targetPerson.getDn());
992  result.add(targetPerson);
993  }
994  }
995 
996  return result;
997  }
Logger log
Definition: CacheRefreshTimer.java:94

◆ removeTargetEntries()

Pair<List<String>, List<String> > org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.removeTargetEntries ( LdapServerConnection  inumDbServerConnection,
PersistenceEntryManager  targetPersistenceEntryManager,
List< GluuSimplePerson removedPersons,
HashMap< String, GluuInumMap inumInumMap 
)
inlineprivate
707  {
708 
709  String runDate = ldapEntryManager.encodeTime(new Date(this.lastFinishedTime));
710 
711  PersistenceEntryManager inumDbPersistenceEntryManager = inumDbServerConnection.getPersistenceEntryManager();
712  List<String> result1 = new ArrayList<String>();
713  List<String> result2 = new ArrayList<String>();
714 
715  for (GluuSimplePerson removedPerson : removedPersons) {
716  String inum = removedPerson.getAttribute(OxTrustConstants.inum);
717 
718  // Update GluuInumMap if it exist
719  GluuInumMap currentInumMap = inumInumMap.get(inum);
720  if (currentInumMap == null) {
721  log.warn("Can't find inum entry of person with DN: {}", removedPerson.getDn());
722  } else {
723  GluuInumMap removedInumMap = getMarkInumMapEntryAsRemoved(currentInumMap, runDate);
724  try {
725  inumDbPersistenceEntryManager.merge(removedInumMap);
726  result2.add(removedInumMap.getInum());
727  } catch (BasePersistenceException ex) {
728  log.error("Failed to update entry with inum '{}' and DN: {}", currentInumMap.getInum(), currentInumMap.getDn(), ex);
729  continue;
730  }
731  }
732 
733  // Remove person from target server
734  try {
735  targetPersistenceEntryManager.removeRecursively(removedPerson.getDn());
736  result1.add(inum);
737  } catch (BasePersistenceException ex) {
738  log.error("Failed to remove person entry with inum '{}' and DN: {}", inum, removedPerson.getDn(), ex);
739  continue;
740  }
741 
742  log.debug("Person with DN: '{}' removed from target server", removedPerson.getDn());
743  }
744 
745  return new Pair<List<String>, List<String>>(result1, result2);
746  }
long lastFinishedTime
Definition: CacheRefreshTimer.java:142
PersistenceEntryManager ldapEntryManager
Definition: CacheRefreshTimer.java:115
GluuInumMap getMarkInumMapEntryAsRemoved(GluuInumMap currentInumMap, String date)
Definition: CacheRefreshTimer.java:748
Logger log
Definition: CacheRefreshTimer.java:94

◆ toIntString()

String org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.toIntString ( Number  number)
inlineprivate
1124  {
1125  return (number == null) ? null : String.valueOf(number.intValue());
1126  }

◆ toLdapProperties()

Properties org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.toLdapProperties ( GluuLdapConfiguration  ldapConfiguration)
inlineprivate
1198  {
1199  Properties ldapProperties = new Properties();
1200  ldapProperties.put("servers", PropertyUtil.simplePropertiesToCommaSeparatedList(ldapConfiguration.getServers()));
1201  ldapProperties.put("maxconnections", Integer.toString(ldapConfiguration.getMaxConnections()));
1202  ldapProperties.put("useSSL", Boolean.toString(ldapConfiguration.isUseSSL()));
1203  ldapProperties.put("bindDN", ldapConfiguration.getBindDN());
1204  ldapProperties.put("bindPassword", ldapConfiguration.getBindPassword());
1205 
1206  // Copy binary attributes list from main LDAP connection
1207  PersistenceOperationService persistenceOperationService = ldapEntryManager.getOperationService();
1208  if (persistenceOperationService instanceof LdapEntryManager) {
1209  ldapProperties.put("binaryAttributes", PropertyUtil.stringsToCommaSeparatedList(
1210  ((LdapEntryManager) ldapEntryManager).getOperationService().getConnectionProvider().getBinaryAttributes()));
1211  }
1212 
1213  return ldapProperties;
1214  }
PersistenceEntryManager ldapEntryManager
Definition: CacheRefreshTimer.java:115

◆ updateApplianceStatus()

void org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.updateApplianceStatus ( GluuAppliance  currentAppliance,
long  lastRun 
)
inlineprivate
1113  {
1114  GluuAppliance appliance = applianceService.getAppliance();
1115 
1116  Date currentDateTime = new Date();
1117  appliance.setVdsCacheRefreshLastUpdate(currentDateTime);
1118  appliance.setVdsCacheRefreshLastUpdateCount(currentAppliance.getVdsCacheRefreshLastUpdateCount());
1119  appliance.setVdsCacheRefreshProblemCount(currentAppliance.getVdsCacheRefreshProblemCount());
1120 
1121  applianceService.updateAppliance(appliance);
1122  }
void updateAppliance(GluuAppliance appliance)
Definition: ApplianceService.java:75
GluuAppliance getAppliance(String[] returnAttributes)
Definition: ApplianceService.java:111
ApplianceService applianceService
Definition: CacheRefreshTimer.java:118

◆ updateTargetEntriesViaCopy()

List<String> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.updateTargetEntriesViaCopy ( CacheRefreshConfiguration  cacheRefreshConfiguration,
Map< CacheCompoundKey, GluuSimplePerson sourcePersonCacheCompoundKeyMap,
HashMap< CacheCompoundKey, GluuInumMap primaryKeyAttrValueInumMap,
Set< String >  changedInums 
)
inlineprivate
551  {
552  HashMap<String, CacheCompoundKey> inumCacheCompoundKeyMap = getInumCacheCompoundKeyMap(primaryKeyAttrValueInumMap);
553  Map<String, String> targetServerAttributesMapping = getTargetServerAttributesMapping(cacheRefreshConfiguration);
554  String[] customObjectClasses = appConfiguration.getPersonObjectClassTypes();
555 
556  List<String> result = new ArrayList<String>();
557 
558  if (!validateTargetServerSchema(cacheRefreshConfiguration, targetServerAttributesMapping, customObjectClasses)) {
559  return result;
560  }
561 
562  for (String targetInum : changedInums) {
563  CacheCompoundKey compoundKey = inumCacheCompoundKeyMap.get(targetInum);
564  if (compoundKey == null) {
565  continue;
566  }
567 
568  GluuSimplePerson sourcePerson = sourcePersonCacheCompoundKeyMap.get(compoundKey);
569  if (sourcePerson == null) {
570  continue;
571  }
572 
573  if (updateTargetEntryViaCopy(sourcePerson, targetInum, customObjectClasses, targetServerAttributesMapping)) {
574  result.add(targetInum);
575  }
576  }
577 
578  return result;
579  }
Map< String, String > getTargetServerAttributesMapping(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshTimer.java:1189
HashMap< String, CacheCompoundKey > getInumCacheCompoundKeyMap(HashMap< CacheCompoundKey, GluuInumMap > primaryKeyAttrValueInumMap)
Definition: CacheRefreshTimer.java:696
AppConfiguration appConfiguration
Definition: CacheRefreshTimer.java:133
boolean validateTargetServerSchema(CacheRefreshConfiguration cacheRefreshConfiguration, Map< String, String > targetServerAttributesMapping, String[] customObjectClasses)
Definition: CacheRefreshTimer.java:581
boolean updateTargetEntryViaCopy(GluuSimplePerson sourcePerson, String targetInum, String[] targetCustomObjectClasses, Map< String, String > targetServerAttributesMapping)
Definition: CacheRefreshTimer.java:645

◆ updateTargetEntriesViaVDS()

List<String> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.updateTargetEntriesViaVDS ( CacheRefreshConfiguration  cacheRefreshConfiguration,
LdapServerConnection  targetServerConnection,
Set< String >  changedInums 
)
inlineprivate
531  {
532  List<String> result = new ArrayList<String>();
533 
534  PersistenceEntryManager targetPersistenceEntryManager = targetServerConnection.getPersistenceEntryManager();
536  for (String changedInum : changedInums) {
537  String baseDn = "action=synchronizecache," + personService.getDnForPerson(changedInum);
538  try {
539  targetPersistenceEntryManager.findEntries(baseDn, GluuDummyEntry.class, filter, SearchScope.SUB, null, null, 0, 0, cacheRefreshConfiguration.getLdapSearchSizeLimit());
540  result.add(changedInum);
541  log.debug("Updated entry with inum {}", changedInum);
542  } catch (BasePersistenceException ex) {
543  log.error("Failed to update entry with inum '{}' using baseDN {}", changedInum, baseDn, ex);
544  }
545  }
546 
547  return result;
548  }
IPersonService personService
Definition: CacheRefreshTimer.java:112
CacheRefreshService cacheRefreshService
Definition: CacheRefreshTimer.java:109
abstract String getDnForPerson(String inum)
Logger log
Definition: CacheRefreshTimer.java:94
Filter createObjectClassPresenceFilter()
Definition: CacheRefreshService.java:98

◆ updateTargetEntryViaCopy()

boolean org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.updateTargetEntryViaCopy ( GluuSimplePerson  sourcePerson,
String  targetInum,
String []  targetCustomObjectClasses,
Map< String, String >  targetServerAttributesMapping 
)
inlineprivate
646  {
647  String targetPersonDn = personService.getDnForPerson(targetInum);
648  GluuCustomPerson targetPerson = null;
649  boolean updatePerson;
650  if (personService.contains(targetPersonDn)) {
651  try {
652  targetPerson = personService.findPersonByDn(targetPersonDn);
653  log.debug("Found person by inum '{}'", targetInum);
654  } catch (EntryPersistenceException ex) {
655  log.error("Failed to find person '{}'", targetInum, ex);
656  return false;
657  }
658  updatePerson = true;
659  } else {
660  targetPerson = new GluuCustomPerson();
661  targetPerson.setDn(targetPersonDn);
662  targetPerson.setInum(targetInum);
663  targetPerson.setStatus(GluuStatus.ACTIVE);
664  updatePerson = false;
665  }
666  targetPerson.setCustomObjectClasses(targetCustomObjectClasses);
667 
668  targetPerson.setSourceServerName(sourcePerson.getSourceServerName());
669  targetPerson.setSourceServerUserDn(sourcePerson.getDn());
670 
671  cacheRefreshService.setTargetEntryAttributes(sourcePerson, targetServerAttributesMapping, targetPerson);
672 
673  // Execute interceptor script
674  boolean executionResult = externalCacheRefreshService.executeExternalUpdateUserMethods(targetPerson);
675  if (!executionResult) {
676  log.error("Failed to execute Cache Refresh scripts for person '{}'", targetInum);
677  return false;
678  }
679 
680  try {
681  if (updatePerson) {
682  personService.updatePerson(targetPerson);
683  log.debug("Updated person '{}'", targetInum);
684  } else {
685  personService.addPerson(targetPerson);
686  log.debug("Added new person '{}'", targetInum);
687  }
688  } catch (Exception ex) {
689  log.error("Failed to '{}' person '{}'", updatePerson ? "update" : "add", targetInum, ex);
690  return false;
691  }
692 
693  return true;
694  }
IPersonService personService
Definition: CacheRefreshTimer.java:112
CacheRefreshService cacheRefreshService
Definition: CacheRefreshTimer.java:109
abstract String getDnForPerson(String inum)
abstract void updatePerson(GluuCustomPerson person)
void setTargetEntryAttributes(GluuSimplePerson sourcePerson, Map< String, String > targetServerAttributesMapping, GluuCustomPerson targetPerson)
Definition: CacheRefreshService.java:135
abstract GluuCustomPerson findPersonByDn(String dn, String... returnAttributes)
boolean executeExternalUpdateUserMethods(GluuCustomPerson user)
Definition: ExternalCacheRefreshService.java:50
abstract boolean contains(String dn)
ExternalCacheRefreshService externalCacheRefreshService
Definition: CacheRefreshTimer.java:124
abstract void addPerson(GluuCustomPerson person)
Logger log
Definition: CacheRefreshTimer.java:94

◆ validateTargetServerSchema() [1/2]

boolean org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.validateTargetServerSchema ( CacheRefreshConfiguration  cacheRefreshConfiguration,
Map< String, String >  targetServerAttributesMapping,
String []  customObjectClasses 
)
inlineprivate
581  {
582  // Get list of return attributes
583  String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
584  String[] sourceAttributes = getSourceAttributes(cacheRefreshConfiguration);
585  String[] returnAttributes = ArrayHelper.arrayMerge(keyAttributesWithoutValues, sourceAttributes);
586 
587  GluuSimplePerson sourcePerson = new GluuSimplePerson();
588  for (String returnAttribute : returnAttributes) {
589  sourcePerson.setAttribute(returnAttribute, "Test");
590  }
591 
592  String targetInum = inumService.generateInums(OxTrustConstants.INUM_TYPE_PEOPLE_SLUG, false);
593  String targetPersonDn = personService.getDnForPerson(targetInum);
594 
595  GluuCustomPerson targetPerson = new GluuCustomPerson();
596  targetPerson.setDn(targetPersonDn);
597  targetPerson.setInum(targetInum);
598  targetPerson.setStatus(GluuStatus.ACTIVE);
599  targetPerson.setCustomObjectClasses(customObjectClasses);
600 
601  // Update list of return attributes according mapping
602  cacheRefreshService.setTargetEntryAttributes(sourcePerson, targetServerAttributesMapping, targetPerson);
603 
604  // Execute interceptor script
606  boolean executionResult = externalCacheRefreshService.executeExternalUpdateUserMethods(targetPerson);
607  if (!executionResult) {
608  log.error("Failed to execute Cache Refresh scripts for person '{}'", targetInum);
609  return false;
610  }
611 
612  // Validate target server attributes
613  List<GluuCustomAttribute> customAttributes = targetPerson.getCustomAttributes();
614 
615  List<String> targetAttributes = new ArrayList<String>(customAttributes.size());
616  for (GluuCustomAttribute customAttribute : customAttributes) {
617  targetAttributes.add(customAttribute.getName());
618  }
619 
620  List<String> targetObjectClasses = Arrays.asList(ldapEntryManager.getObjectClasses(targetPerson, GluuCustomPerson.class));
621 
622  return validateTargetServerSchema(targetObjectClasses, targetAttributes);
623  }
IPersonService personService
Definition: CacheRefreshTimer.java:112
String [] getSourceAttributes(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshTimer.java:1165
InumService inumService
Definition: CacheRefreshTimer.java:130
CacheRefreshService cacheRefreshService
Definition: CacheRefreshTimer.java:109
abstract String getDnForPerson(String inum)
void setTargetEntryAttributes(GluuSimplePerson sourcePerson, Map< String, String > targetServerAttributesMapping, GluuCustomPerson targetPerson)
Definition: CacheRefreshService.java:135
String generateInums(String type)
Definition: InumService.java:177
boolean executeExternalUpdateUserMethods(GluuCustomPerson user)
Definition: ExternalCacheRefreshService.java:50
PersistenceEntryManager ldapEntryManager
Definition: CacheRefreshTimer.java:115
boolean validateTargetServerSchema(CacheRefreshConfiguration cacheRefreshConfiguration, Map< String, String > targetServerAttributesMapping, String[] customObjectClasses)
Definition: CacheRefreshTimer.java:581
ExternalCacheRefreshService externalCacheRefreshService
Definition: CacheRefreshTimer.java:124
Logger log
Definition: CacheRefreshTimer.java:94
String [] getCompoundKeyAttributesWithoutValues(CacheRefreshConfiguration cacheRefreshConfiguration)
Definition: CacheRefreshTimer.java:1177

◆ validateTargetServerSchema() [2/2]

boolean org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.validateTargetServerSchema ( List< String >  targetObjectClasses,
List< String >  targetAttributes 
)
inlineprivate
625  {
626  Set<String> objectClassesAttributesSet = schemaService.getObjectClassesAttributes(schemaService.getSchema(),
627  targetObjectClasses.toArray(new String[0]));
628 
629  Set<String> targetAttributesSet = new LinkedHashSet<String>();
630  for (String attrbute : targetAttributes) {
631  targetAttributesSet.add(StringHelper.toLowerCase(attrbute));
632  }
633 
634  targetAttributesSet.removeAll(objectClassesAttributesSet);
635 
636  if (targetAttributesSet.size() == 0) {
637  return true;
638  }
639 
640  log.error("Skipping target entries update. Destination server schema doesn't has next attributes: '{}'", targetAttributesSet);
641 
642  return false;
643  }
SchemaService schemaService
Definition: CacheRefreshTimer.java:127
Logger log
Definition: CacheRefreshTimer.java:94

メンバ詳解

◆ appConfiguration

AppConfiguration org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.appConfiguration
private

◆ applianceService

ApplianceService org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.applianceService
private

◆ applicationFactory

ApplicationFactory org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.applicationFactory
protected

◆ attributeService

AttributeService org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.attributeService
protected

◆ cacheRefreshService

CacheRefreshService org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.cacheRefreshService
private

◆ cacheRefreshSnapshotFileService

CacheRefreshSnapshotFileService org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.cacheRefreshSnapshotFileService
private

◆ configurationFactory

ConfigurationFactory org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.configurationFactory
private

◆ DEFAULT_INTERVAL

final int org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.DEFAULT_INTERVAL = 60
staticprivate

◆ encryptionService

EncryptionService org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.encryptionService
private

◆ externalCacheRefreshService

ExternalCacheRefreshService org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.externalCacheRefreshService
private

◆ inumService

InumService org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.inumService
private

◆ isActive

AtomicBoolean org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.isActive
private

◆ lastFinishedTime

long org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.lastFinishedTime
private

◆ ldapEntryManager

PersistenceEntryManager org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.ldapEntryManager
private

◆ LETTERS_FOR_SEARCH

final String org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.LETTERS_FOR_SEARCH = "abcdefghijklmnopqrstuvwxyz1234567890."
staticprivate

◆ log

Logger org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.log
private

◆ objectSerializationService

ObjectSerializationService org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.objectSerializationService
private

◆ personService

IPersonService org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.personService
private

◆ schemaService

SchemaService org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.schemaService
private

◆ TARGET_PERSON_RETURN_ATTRIBUTES

final String [] org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.TARGET_PERSON_RETURN_ATTRIBUTES = { OxTrustConstants.inum }
staticprivate

◆ timerEvent

Event<TimerEvent> org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.timerEvent
private

このクラス詳解は次のファイルから抽出されました: