use of org.gluu.persist.exception.mapping.EntryPersistenceException in project oxCore by GluuFederation.
the class LdapEntryManager method find.
@Override
protected List<AttributeData> find(String dn, String... ldapReturnAttributes) {
try {
SearchResultEntry entry = this.ldapOperationService.lookup(dn, ldapReturnAttributes);
List<AttributeData> result = getAttributeDataList(entry);
if (result != null) {
return result;
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entry: %s", dn), ex);
}
throw new EntryPersistenceException(String.format("Failed to find entry: %s", dn));
}
use of org.gluu.persist.exception.mapping.EntryPersistenceException in project oxCore by GluuFederation.
the class LdapEntryManager method contains.
@Override
protected boolean contains(String baseDN, Filter filter, String[] objectClasses, String[] ldapReturnAttributes) {
if (StringHelper.isEmptyString(baseDN)) {
throw new MappingException("Base DN to check contain entries is null");
}
// Create filter
Filter searchFilter;
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
SearchResult searchResult = null;
try {
searchResult = this.ldapOperationService.search(baseDN, toLdapFilter(searchFilter), 1, 1, null, ldapReturnAttributes);
if ((searchResult == null) || !ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find entry with baseDN: %s, filter: %s", baseDN, searchFilter));
}
} catch (SearchException ex) {
if (!(ResultCode.NO_SUCH_OBJECT_INT_VALUE == ex.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find entry with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
}
}
return (searchResult != null) && (searchResult.getEntryCount() > 0);
}
use of org.gluu.persist.exception.mapping.EntryPersistenceException in project oxCore by GluuFederation.
the class LdapEntryManager method getLDIF.
@Override
public List<String[]> getLDIF(String dn, String[] attributes) {
SearchResult searchResult;
try {
searchResult = this.ldapOperationService.search(dn, toLdapFilter(Filter.create("objectclass=*")), toLdapSearchScope(SearchScope.BASE), -1, 0, null, attributes);
if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s", dn));
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", dn, null), ex);
}
List<String[]> result = new ArrayList<String[]>();
if (searchResult.getEntryCount() == 0) {
return result;
}
for (SearchResultEntry searchResultEntry : searchResult.getSearchEntries()) {
result.add(searchResultEntry.toLDIF());
}
return result;
}
use of org.gluu.persist.exception.mapping.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 '{}'", targetInum, ex);
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 '{}'", updatePerson ? "update" : "add", targetInum, ex);
return false;
}
return true;
}
use of org.gluu.persist.exception.mapping.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", attributeName, ex);
}
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;
}
Aggregations