Search in sources :

Example 41 with LDAPException

use of com.unboundid.ldap.sdk.LDAPException in project oxAuth by GluuFederation.

the class InumGenerator method contains.

public boolean contains(String inum, IdType type) {
    final String baseDn = baseDn(type);
    try {
        final Filter filter = Filter.create(String.format("inum=%s", inum));
        final List<LdapDummyEntry> entries = ldapEntryManager.findEntries(baseDn, LdapDummyEntry.class, filter);
        return entries != null && !entries.isEmpty();
    } catch (LDAPException e) {
        log.error(e.getMessage(), e);
    }
    return false;
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) Filter(com.unboundid.ldap.sdk.Filter) LdapDummyEntry(org.xdi.ldap.model.LdapDummyEntry)

Example 42 with LDAPException

use of com.unboundid.ldap.sdk.LDAPException in project oxAuth by GluuFederation.

the class LdapUtils method createAnyFilterFromDnList.

/**
     * Creates any filter to load all objects represented by this dn list.
     *
     * @param p_filterAttributeName filter attribute name
     * @param p_dnList              dn list
     * @return filter
     */
public static Filter createAnyFilterFromDnList(String p_filterAttributeName, List<String> p_dnList) {
    try {
        if (p_dnList != null && !p_dnList.isEmpty()) {
            final StringBuilder sb = new StringBuilder("(|");
            for (String dn : p_dnList) {
                final DN dnObj = new DN(dn);
                final RDN rdn = dnObj.getRDN();
                if (rdn.getAttributeNames()[0].equals(p_filterAttributeName)) {
                    final String[] values = rdn.getAttributeValues();
                    if (values != null && values.length == 1) {
                        sb.append("(");
                        sb.append(p_filterAttributeName).append("=");
                        sb.append(values[0]);
                        sb.append(")");
                    }
                }
            }
            sb.append(")");
            final String filterAsString = sb.toString();
            log.trace("dnList: " + p_dnList + ", ldapFilter: " + filterAsString);
            return Filter.create(filterAsString);
        }
    } catch (LDAPException e) {
        log.trace(e.getMessage(), e);
    }
    return null;
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) RDN(com.unboundid.ldap.sdk.RDN) DN(com.unboundid.ldap.sdk.DN) RDN(com.unboundid.ldap.sdk.RDN)

Example 43 with LDAPException

use of com.unboundid.ldap.sdk.LDAPException in project oxTrust by GluuFederation.

the class LdifService method validateLdifFile.

public ResultCode validateLdifFile(InputStream is, String dn) throws LDAPException {
    ResultCode result = ResultCode.UNAVAILABLE;
    try {
        LdifDataUtility ldifDataUtility = LdifDataUtility.instance();
        LDIFReader validateLdifReader = new LDIFReader(is);
        result = ldifDataUtility.validateLDIF(validateLdifReader, dn);
        validateLdifReader.close();
    } catch (Exception ex) {
        log.error("Failed to validate ldif file: ", ex);
    }
    return result;
}
Also used : LDIFReader(com.unboundid.ldif.LDIFReader) LdifDataUtility(org.gluu.persist.ldap.impl.LdifDataUtility) ResultCode(com.unboundid.ldap.sdk.ResultCode) IOException(java.io.IOException) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Example 44 with LDAPException

use of com.unboundid.ldap.sdk.LDAPException in project oxTrust by GluuFederation.

the class LdifService method importLdifFileInLdap.

public ResultCode importLdifFileInLdap(InputStream is) throws LDAPException {
    ResultCode result = ResultCode.UNAVAILABLE;
    LDAPConnection connection = ldapEntryManager.getOperationService().getConnection();
    try {
        LdifDataUtility ldifDataUtility = LdifDataUtility.instance();
        LDIFReader importLdifReader = new LDIFReader(is);
        result = ldifDataUtility.importLdifFile(connection, importLdifReader);
        importLdifReader.close();
    } catch (Exception ex) {
        log.error("Failed to import ldif file: ", ex);
    } finally {
        ldapEntryManager.getOperationService().releaseConnection(connection);
    }
    return result;
}
Also used : LDIFReader(com.unboundid.ldif.LDIFReader) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) LdifDataUtility(org.gluu.persist.ldap.impl.LdifDataUtility) ResultCode(com.unboundid.ldap.sdk.ResultCode) IOException(java.io.IOException) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Example 45 with LDAPException

use of com.unboundid.ldap.sdk.LDAPException in project oxCore by GluuFederation.

the class LdifDataUtility method checkIfSerrverHasEntryFromLDIFFile.

/**
 * Check if DS has at least one DN simular to specified in ldif file.
 *
 * @param connection
 *            Connection to LDAP server
 * @param ldifFileName
 *            LDIF file
 * @return true if server contains at least one DN simular to specified in ldif
 *         file.
 */
public boolean checkIfSerrverHasEntryFromLDIFFile(LDAPConnection connection, String ldifFileName) {
    // Set up the LDIF reader that will be used to read the changes to apply
    LDIFReader ldifReader = createLdifReader(ldifFileName);
    if (ldifReader == null) {
        return true;
    }
    // Check all ldif entries
    while (true) {
        // Read the next change to process.
        Entry entry = null;
        try {
            entry = ldifReader.readEntry();
        } catch (LDIFException le) {
            LOG.error("Malformed ldif record", le);
            if (!le.mayContinueReading()) {
                return true;
            }
        } catch (IOException ioe) {
            LOG.error("I/O error encountered while reading a change record", ioe);
            return true;
        }
        // changes to be processed.
        if (entry == null) {
            break;
        }
        // Search entry in the server.
        try {
            SearchResult sr = connection.search(entry.getDN(), SearchScope.BASE, "objectClass=*");
            if ((sr != null) && (sr.getEntryCount() > 0)) {
                return true;
            }
        } catch (LDAPException le) {
            if (le.getResultCode() != ResultCode.NO_SUCH_OBJECT) {
                LOG.error("Failed to search ldif record", le);
                return true;
            }
        }
    }
    disposeLdifReader(ldifReader);
    return false;
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDIFReader(com.unboundid.ldif.LDIFReader) LDIFException(com.unboundid.ldif.LDIFException) SearchResult(com.unboundid.ldap.sdk.SearchResult) IOException(java.io.IOException)

Aggregations

LDAPException (com.unboundid.ldap.sdk.LDAPException)59 SearchResult (com.unboundid.ldap.sdk.SearchResult)15 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)13 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)11 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)11 IOException (java.io.IOException)11 ResultCode (com.unboundid.ldap.sdk.ResultCode)9 LDIFReader (com.unboundid.ldif.LDIFReader)8 GeneralSecurityException (java.security.GeneralSecurityException)8 DN (com.unboundid.ldap.sdk.DN)6 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)5 Entry (com.unboundid.ldap.sdk.Entry)5 Filter (com.unboundid.ldap.sdk.Filter)5 LDAPConnectionPool (com.unboundid.ldap.sdk.LDAPConnectionPool)5 ArrayList (java.util.ArrayList)5 LdifDataUtility (org.gluu.persist.ldap.impl.LdifDataUtility)5 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)4 InMemoryDirectoryServerConfig (com.unboundid.ldap.listener.InMemoryDirectoryServerConfig)4 BindResult (com.unboundid.ldap.sdk.BindResult)4 SimpleBindRequest (com.unboundid.ldap.sdk.SimpleBindRequest)4