use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException 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 '{}'", ex, targetInum);
return false;
}
updatePerson = true;
} else {
targetPerson = new GluuCustomPerson();
targetPerson.setDn(targetPersonDn);
targetPerson.setInum(targetInum);
targetPerson.setStatus(GluuStatus.ACTIVE);
updatePerson = false;
}
targetPerson.setCustomObjectClasses(targetCustomObjectClasses);
targetPerson.setSourceServerName(sourcePerson.getSourceServerName());
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 '{}'", ex, updatePerson ? "update" : "add", targetInum);
return false;
}
return true;
}
use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class ImportPersonConfiguration method prepareAttributes.
private List<GluuAttribute> prepareAttributes() throws Exception {
List<GluuAttribute> result = new ArrayList<GluuAttribute>();
List<ImportPerson> mappings = configurationFactory.getImportPersonConfig().getMappings();
Iterator<ImportPerson> it = mappings.iterator();
while (it.hasNext()) {
ImportPerson importPerson = (ImportPerson) it.next();
String attributeName = importPerson.getLdapName();
boolean required = importPerson.getRequired();
if (StringHelper.isNotEmpty(attributeName)) {
GluuAttribute attr = null;
try {
attr = attributeService.getAttributeByName(attributeName);
} catch (EntryPersistenceException ex) {
log.error("Failed to load attribute '{}' definition from LDAP", ex, attributeName);
}
if (attr == null) {
log.warn("Failed to find attribute '{}' definition in LDAP", attributeName);
attr = createAttributeFromConfig(importPerson);
if (attr == null) {
log.error("Failed to find attribute '{}' definition in '{}'", attributeName, GLUU_IMPORT_PERSON_PROPERTIES_FILE);
continue;
}
} else {
attr.setRequred(required);
}
result.add(attr);
}
//}
}
return result;
}
use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class Scim2UserService method validUsernameByInum.
private GluuCustomPerson validUsernameByInum(User user, String id) throws DuplicateEntryException {
GluuCustomPerson gluuPerson = personService.getPersonByInum(id);
if (gluuPerson == null) {
throw new EntryPersistenceException("Scim2UserService.updateUser(): " + "Resource " + id + " not found");
} else {
// Validate if attempting to update userName of a different id
if (user.getUserName() != null) {
GluuCustomPerson personToFind = new GluuCustomPerson();
personToFind.setUid(user.getUserName());
List<GluuCustomPerson> foundPersons = personService.findPersons(personToFind, 2);
if (foundPersons != null && foundPersons.size() > 0) {
for (GluuCustomPerson foundPerson : foundPersons) {
if (foundPerson != null && !foundPerson.getInum().equalsIgnoreCase(gluuPerson.getInum())) {
throw new DuplicateEntryException("Cannot update userName of a different id: " + user.getUserName());
}
}
}
}
}
return gluuPerson;
}
use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class Scim2UserService method deleteUser.
public void deleteUser(String id) throws Exception {
GluuCustomPerson gluuPerson = personService.getPersonByInum(id);
if (gluuPerson == null) {
throw new EntryPersistenceException("Scim2UserService.deleteUser(): " + "Resource " + id + " not found");
} else {
// For custom script: delete user
if (externalScimService.isEnabled()) {
externalScimService.executeScimDeleteUserMethods(gluuPerson);
}
log.info("person.getMemberOf().size() : " + gluuPerson.getMemberOf().size());
if (gluuPerson.getMemberOf() != null) {
if (gluuPerson.getMemberOf().size() > 0) {
String dn = personService.getDnForPerson(id);
log.info("DN : " + dn);
serviceUtil.deleteUserFromGroup(gluuPerson, dn);
}
}
memberService.removePerson(gluuPerson);
}
}
use of org.gluu.site.ldap.persistence.exception.EntryPersistenceException in project oxTrust by GluuFederation.
the class Scim2UserService method updateUser.
public User updateUser(String id, User user) throws Exception {
GluuCustomPerson gluuPerson = personService.getPersonByInum(id);
if (gluuPerson == null) {
throw new EntryPersistenceException("Scim2UserService.updateUser(): " + "Resource " + id + " not found");
} else {
// Validate if attempting to update userName of a different id
if (user.getUserName() != null) {
GluuCustomPerson personToFind = new GluuCustomPerson();
personToFind.setUid(user.getUserName());
List<GluuCustomPerson> foundPersons = personService.findPersons(personToFind, 2);
if (foundPersons != null && foundPersons.size() > 0) {
for (GluuCustomPerson foundPerson : foundPersons) {
if (foundPerson != null && !foundPerson.getInum().equalsIgnoreCase(gluuPerson.getInum())) {
throw new DuplicateEntryException("Cannot update userName of a different id: " + user.getUserName());
}
}
}
}
}
GluuCustomPerson updatedGluuPerson = copyUtils2.copy(user, gluuPerson, true);
if (user.getGroups().size() > 0) {
serviceUtil.groupMembersAdder(updatedGluuPerson, personService.getDnForPerson(id));
}
log.info(" Setting meta: update user ");
// Date should be in UTC format
DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
Date dateLastModified = DateTime.now().toDate();
updatedGluuPerson.setAttribute("oxTrustMetaLastModified", dateTimeFormatter.print(dateLastModified.getTime()));
if (updatedGluuPerson.getAttribute("oxTrustMetaLocation") == null || (updatedGluuPerson.getAttribute("oxTrustMetaLocation") != null && updatedGluuPerson.getAttribute("oxTrustMetaLocation").isEmpty())) {
String relativeLocation = "/scim/v2/Users/" + id;
updatedGluuPerson.setAttribute("oxTrustMetaLocation", relativeLocation);
}
// Sync email, forward ("oxTrustEmail" -> "mail")
updatedGluuPerson = serviceUtil.syncEmailForward(updatedGluuPerson, true);
// For custom script: update user
if (externalScimService.isEnabled()) {
externalScimService.executeScimUpdateUserMethods(updatedGluuPerson);
}
personService.updatePerson(updatedGluuPerson);
log.debug(" person updated ");
User updatedUser = copyUtils2.copy(updatedGluuPerson, null);
return updatedUser;
}
Aggregations