Search in sources :

Example 6 with EntryPersistenceException

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));
}
Also used : EntryPersistenceException(org.gluu.persist.exception.mapping.EntryPersistenceException) AttributeData(org.gluu.persist.model.AttributeData) SearchException(org.gluu.persist.exception.operation.SearchException) AuthenticationException(org.gluu.persist.exception.operation.AuthenticationException) MappingException(org.gluu.persist.exception.mapping.MappingException) SearchScopeException(org.gluu.persist.exception.operation.SearchScopeException) ParseException(java.text.ParseException) EntryPersistenceException(org.gluu.persist.exception.mapping.EntryPersistenceException) ConnectionException(org.gluu.persist.exception.operation.ConnectionException) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 7 with EntryPersistenceException

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);
}
Also used : Filter(org.gluu.search.filter.Filter) EntryPersistenceException(org.gluu.persist.exception.mapping.EntryPersistenceException) SearchException(org.gluu.persist.exception.operation.SearchException) SearchResult(com.unboundid.ldap.sdk.SearchResult) MappingException(org.gluu.persist.exception.mapping.MappingException)

Example 8 with EntryPersistenceException

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;
}
Also used : ArrayList(java.util.ArrayList) EntryPersistenceException(org.gluu.persist.exception.mapping.EntryPersistenceException) SearchResult(com.unboundid.ldap.sdk.SearchResult) SearchException(org.gluu.persist.exception.operation.SearchException) AuthenticationException(org.gluu.persist.exception.operation.AuthenticationException) MappingException(org.gluu.persist.exception.mapping.MappingException) SearchScopeException(org.gluu.persist.exception.operation.SearchScopeException) ParseException(java.text.ParseException) EntryPersistenceException(org.gluu.persist.exception.mapping.EntryPersistenceException) ConnectionException(org.gluu.persist.exception.operation.ConnectionException) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 9 with EntryPersistenceException

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;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) EntryPersistenceException(org.gluu.persist.exception.mapping.EntryPersistenceException) EntryPersistenceException(org.gluu.persist.exception.mapping.EntryPersistenceException) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) SocketException(java.net.SocketException)

Example 10 with EntryPersistenceException

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;
}
Also used : ArrayList(java.util.ArrayList) EntryPersistenceException(org.gluu.persist.exception.mapping.EntryPersistenceException) ImportPerson(org.xdi.config.oxtrust.ImportPerson) GluuAttribute(org.xdi.model.GluuAttribute)

Aggregations

EntryPersistenceException (org.gluu.persist.exception.mapping.EntryPersistenceException)19 SearchException (org.gluu.persist.exception.operation.SearchException)11 MappingException (org.gluu.persist.exception.mapping.MappingException)10 ParseException (java.text.ParseException)9 AuthenticationException (org.gluu.persist.exception.operation.AuthenticationException)9 ConnectionException (org.gluu.persist.exception.operation.ConnectionException)9 SearchScopeException (org.gluu.persist.exception.operation.SearchScopeException)9 ArrayList (java.util.ArrayList)8 SearchResult (com.unboundid.ldap.sdk.SearchResult)7 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)7 Filter (org.gluu.search.filter.Filter)7 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)3 AttributeData (org.gluu.persist.model.AttributeData)3 PropertyAnnotation (org.gluu.persist.model.PropertyAnnotation)3 List (java.util.List)2 GluuGroup (org.gluu.oxtrust.model.GluuGroup)2 Parameters (org.testng.annotations.Parameters)2 Attribute (com.unboundid.ldap.sdk.Attribute)1 Modification (com.unboundid.ldap.sdk.Modification)1 SocketException (java.net.SocketException)1