use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class PersonService method findPersonsByUids.
/* (non-Javadoc)
* @see org.gluu.oxtrust.ldap.service.IPersonService#findPersonsByUids(java.util.List, java.lang.String[])
*/
@Override
public List<GluuCustomPerson> findPersonsByUids(List<String> uids, String[] returnAttributes) throws Exception {
List<Filter> uidFilters = new ArrayList<Filter>();
for (String uid : uids) {
uidFilters.add(Filter.createEqualityFilter(OxConstants.UID, uid));
}
Filter filter = Filter.createORFilter(uidFilters);
List<GluuCustomPerson> result = ldapEntryManager.findEntries(getDnForPerson(null), GluuCustomPerson.class, filter, returnAttributes);
return result;
}
use of org.gluu.oxtrust.model.GluuCustomPerson 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);
}
use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class CacheRefreshTimer method updateTargetEntryViaCopy.
private boolean updateTargetEntryViaCopy(GluuSimplePerson sourcePerson, String targetInum, String[] targetCustomObjectClasses, Map<String, String> targetServerAttributesMapping) {
String targetPersonDn = personService.getDnForPerson(targetInum);
GluuCustomPerson targetPerson = null;
boolean updatePerson;
if (personService.contains(targetPersonDn)) {
try {
targetPerson = personService.findPersonByDn(targetPersonDn);
log.debug("Found person by inum '{}'", targetInum);
} catch (EntryPersistenceException ex) {
log.error("Failed to find person '{}'", targetInum, ex);
return false;
}
updatePerson = true;
} else {
targetPerson = new GluuCustomPerson();
targetPerson.setDn(targetPersonDn);
targetPerson.setInum(targetInum);
targetPerson.setStatus(appConfiguration.getSupportedUserStatus().get(0));
updatePerson = false;
}
targetPerson.setCustomObjectClasses(targetCustomObjectClasses);
targetPerson.setSourceServerName(sourcePerson.getSourceServerName());
targetPerson.setSourceServerUserDn(sourcePerson.getDn());
cacheRefreshService.setTargetEntryAttributes(sourcePerson, targetServerAttributesMapping, targetPerson);
// Execute interceptor script
boolean executionResult = externalCacheRefreshService.executeExternalUpdateUserMethods(targetPerson);
if (!executionResult) {
log.error("Failed to execute Cache Refresh scripts for person '{}'", targetInum);
return false;
}
try {
if (updatePerson) {
personService.updatePerson(targetPerson);
log.debug("Updated person '{}'", targetInum);
} else {
personService.addPerson(targetPerson);
log.debug("Added new person '{}'", targetInum);
}
} catch (Exception ex) {
log.error("Failed to '{}' person '{}'", updatePerson ? "update" : "add", targetInum, ex);
return false;
}
return true;
}
use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class PersonService method getPersonByAttribute.
/*
* (non-Javadoc)
*
* @see
* org.gluu.oxtrust.ldap.service.IPersonService#getPersonByAttribute(java.lang.
* String, java.lang.String)
*/
@Override
public GluuCustomPerson getPersonByAttribute(String attribute, String value) throws Exception {
GluuCustomPerson person = new GluuCustomPerson();
person.setBaseDn(getDnForPerson(null));
person.setAttribute(attribute, value);
List<GluuCustomPerson> persons = persistenceEntryManager.findEntries(person);
if ((persons != null) && (persons.size() > 0)) {
return persons.get(0);
}
return null;
}
use of org.gluu.oxtrust.model.GluuCustomPerson in project oxTrust by GluuFederation.
the class PersonService method addPerson.
/*
* (non-Javadoc)
*
* @see
* org.gluu.oxtrust.ldap.service.IPersonService#addPerson(org.gluu.oxtrust.model
* .GluuCustomPerson)
*/
// TODO: Review this methods. We need to check if uid is unique in outside
// method
@Override
public void addPerson(GluuCustomPerson person) throws Exception {
try {
List<GluuCustomPerson> persons = getPersonsByUid(person.getUid());
if (persons == null || persons.size() == 0) {
person.setCreationDate(new Date());
persistenceEntryManager.persist(person);
} else {
throw new DuplicateEntryException("Duplicate UID value: " + person.getUid());
}
} catch (Exception e) {
if (e.getCause().getMessage().contains("unique attribute conflict was detected for attribute mail")) {
throw new DuplicateEmailException("Email Already Registered");
} else {
throw new Exception("Duplicate UID value: " + person.getUid());
}
}
}
Aggregations