use of org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson 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 (BaseMappingException ex) {
log.error("Failed to update entry with inum '{}' and DN: {}", currentInumMap.getInum(), currentInumMap.getDn(), ex);
continue;
}
}
// Remove person from target server
try {
targetLdapEntryManager.removeRecursively(removedPerson.getDn());
result1.add(inum);
} catch (BaseMappingException ex) {
log.error("Failed to remove person entry with inum '{}' and DN: {}", inum, removedPerson.getDn(), ex);
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.oxtrust.ldap.cache.model.GluuSimplePerson in project oxTrust by GluuFederation.
the class ConfigureCacheRefreshAction method validateInterceptorScript.
public void validateInterceptorScript() {
String result = update();
if (!OxTrustConstants.RESULT_SUCCESS.equals(result)) {
return;
}
// Reinit dialog
init();
this.showInterceptorValidationDialog = true;
boolean loadedScripts = externalCacheRefreshService.getCustomScriptConfigurations().size() > 0;
if (!loadedScripts) {
String message = "Can't load Cache Refresh scripts. Using default script";
log.error(message);
this.interceptorValidationMessage = message;
return;
}
// Prepare data for dummy entry
String targetInum = inumService.generateInums(OxTrustConstants.INUM_TYPE_PEOPLE_SLUG, false);
String targetPersonDn = personService.getDnForPerson(targetInum);
String[] targetCustomObjectClasses = appConfiguration.getPersonObjectClassTypes();
// Collect all attributes
String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
String[] sourceAttributes = getSourceAttributes(cacheRefreshConfiguration);
// Merge all attributes into one set
Set<String> allAttributes = new HashSet<String>();
for (String attribute : keyAttributesWithoutValues) {
allAttributes.add(attribute);
}
for (String attribute : sourceAttributes) {
allAttributes.add(attribute);
}
// Prepare source person entry with default attributes values
GluuSimplePerson sourcePerson = new GluuSimplePerson();
List<GluuCustomAttribute> customAttributes = sourcePerson.getCustomAttributes();
for (String attribute : allAttributes) {
customAttributes.add(new GluuCustomAttribute(attribute, "Test value"));
}
// Prepare target person
GluuCustomPerson targetPerson = new GluuCustomPerson();
targetPerson.setDn(targetPersonDn);
targetPerson.setInum(targetInum);
targetPerson.setStatus(appConfiguration.getSupportedUserStatus().get(0));
targetPerson.setCustomObjectClasses(targetCustomObjectClasses);
// Execute mapping according to configuration
Map<String, String> targetServerAttributesMapping = getTargetServerAttributesMapping(cacheRefreshConfiguration);
cacheRefreshService.setTargetEntryAttributes(sourcePerson, targetServerAttributesMapping, targetPerson);
// Execute interceptor script
boolean executionResult = externalCacheRefreshService.executeExternalUpdateUserMethods(targetPerson);
if (!executionResult) {
String message = "Can't execute Cache Refresh scripts.";
log.error(message);
this.interceptorValidationMessage = message;
return;
}
log.info("Script has been executed successfully.\n\nSample source entry is:\n'{}'.\n\nSample result entry is:\n'{}'", getGluuSimplePersonAttributesWithValues(sourcePerson), getGluuCustomPersonAttributesWithValues(targetPerson));
this.interceptorValidationMessage = String.format("Script has been executed successfully.\n\nSample source entry is:\n%s.\n\nSample result entry is:\n%s", getGluuSimplePersonAttributesWithValues(sourcePerson), getGluuCustomPersonAttributesWithValues(targetPerson));
}
use of org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson in project oxTrust by GluuFederation.
the class CacheRefreshTimer method removeTargetEntries.
private Pair<List<String>, List<String>> removeTargetEntries(LdapServerConnection inumDbServerConnection, PersistenceEntryManager targetPersistenceEntryManager, List<GluuSimplePerson> removedPersons, HashMap<String, GluuInumMap> inumInumMap) {
Date runDate = new Date(this.lastFinishedTime);
PersistenceEntryManager inumDbPersistenceEntryManager = inumDbServerConnection.getPersistenceEntryManager();
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, ldapEntryManager.encodeTime(removedPerson.getDn(), runDate));
try {
inumDbPersistenceEntryManager.merge(removedInumMap);
result2.add(removedInumMap.getInum());
} catch (BasePersistenceException ex) {
log.error("Failed to update entry with inum '{}' and DN: {}", currentInumMap.getInum(), currentInumMap.getDn(), ex);
continue;
}
}
// Remove person from target server
try {
targetPersistenceEntryManager.removeRecursively(removedPerson.getDn());
result1.add(inum);
} catch (BasePersistenceException ex) {
log.error("Failed to remove person entry with inum '{}' and DN: {}", inum, removedPerson.getDn(), ex);
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.oxtrust.ldap.cache.model.GluuSimplePerson 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) {
PersistenceEntryManager inumDbPersistenceEntryManager = inumDbServerConnection.getPersistenceEntryManager();
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, inumDbPersistenceEntryManager, 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.oxtrust.ldap.cache.model.GluuSimplePerson in project oxTrust by GluuFederation.
the class CacheRefreshTimer method validateTargetServerSchema.
private boolean validateTargetServerSchema(CacheRefreshConfiguration cacheRefreshConfiguration, Map<String, String> targetServerAttributesMapping, String[] customObjectClasses) {
// Get list of return attributes
String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
String[] sourceAttributes = getSourceAttributes(cacheRefreshConfiguration);
String[] returnAttributes = ArrayHelper.arrayMerge(keyAttributesWithoutValues, sourceAttributes);
GluuSimplePerson sourcePerson = new GluuSimplePerson();
for (String returnAttribute : returnAttributes) {
sourcePerson.setAttribute(returnAttribute, "Test");
}
String targetInum = inumService.generateInums(OxTrustConstants.INUM_TYPE_PEOPLE_SLUG, false);
String targetPersonDn = personService.getDnForPerson(targetInum);
GluuCustomPerson targetPerson = new GluuCustomPerson();
targetPerson.setDn(targetPersonDn);
targetPerson.setInum(targetInum);
targetPerson.setStatus(appConfiguration.getSupportedUserStatus().get(0));
targetPerson.setCustomObjectClasses(customObjectClasses);
// Update list of return attributes according mapping
cacheRefreshService.setTargetEntryAttributes(sourcePerson, targetServerAttributesMapping, targetPerson);
// Execute interceptor script
externalCacheRefreshService.executeExternalUpdateUserMethods(targetPerson);
boolean executionResult = externalCacheRefreshService.executeExternalUpdateUserMethods(targetPerson);
if (!executionResult) {
log.error("Failed to execute Cache Refresh scripts for person '{}'", targetInum);
return false;
}
// Validate target server attributes
List<GluuCustomAttribute> customAttributes = targetPerson.getCustomAttributes();
List<String> targetAttributes = new ArrayList<String>(customAttributes.size());
for (GluuCustomAttribute customAttribute : customAttributes) {
targetAttributes.add(customAttribute.getName());
}
List<String> targetObjectClasses = Arrays.asList(ldapEntryManager.getObjectClasses(targetPerson, GluuCustomPerson.class));
return validateTargetServerSchema(targetObjectClasses, targetAttributes);
}
Aggregations