Search in sources :

Example 11 with LDAPException

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

the class LdifService method exportLDIFFile.

public void exportLDIFFile(List<String> checkedItems, OutputStream output) throws LDAPException {
    List<SearchResultEntry> result = null;
    LDAPConnection connection = ldapEntryManager.getOperationService().getConnection();
    try {
        LdifDataUtility ldifDataUtility = LdifDataUtility.instance();
        result = ldifDataUtility.getAttributeResultEntryLDIF(connection, checkedItems, attributeService.getDnForAttribute(null));
    } catch (Exception ex) {
        log.error("Failed to export ldif file: ", ex);
    } finally {
        ldapEntryManager.getOperationService().releaseConnection(connection);
    }
    if (result != null && result.size() > 0) {
        // Write all of the matching entries to LDIF.
        LDIFWriter ldifWriter;
        try {
            ldifWriter = new LDIFWriter(output);
            for (SearchResultEntry entry : result) {
                ldifWriter.writeEntry(entry);
            }
            ldifWriter.close();
        } catch (IOException e) {
            throw new BaseMappingException("Error writing to file, try again", e);
        }
    }
}
Also used : BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) LDIFWriter(com.unboundid.ldif.LDIFWriter) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) IOException(java.io.IOException) LdifDataUtility(org.gluu.persist.ldap.impl.LdifDataUtility) IOException(java.io.IOException) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) LDAPException(com.unboundid.ldap.sdk.LDAPException) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 12 with LDAPException

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

the class LdapConnectionProvider method createSSLConnectionPoolWithPreviousProtocols.

private LDAPConnectionPool createSSLConnectionPoolWithPreviousProtocols(SSLUtil sslUtil, BindRequest bindRequest, LDAPConnectionOptions connectionOptions, int maxConnections) throws LDAPException {
    for (int i = 1; i < SSL_PROTOCOLS.length; i++) {
        String protocol = SSL_PROTOCOLS[i];
        try {
            FailoverServerSet failoverSet = new FailoverServerSet(this.addresses, this.ports, sslUtil.createSSLSocketFactory(protocol), connectionOptions);
            LDAPConnectionPool connectionPool = new LDAPConnectionPool(failoverSet, bindRequest, maxConnections);
            LOG.info("Server supports: '" + protocol + "'");
            return connectionPool;
        } catch (GeneralSecurityException ex) {
            LOG.debug("Server not supports: '" + protocol + "'", ex);
        } catch (LDAPException ex) {
            // Error when LDAP server not supports specified encryption
            if (ex.getResultCode() != ResultCode.SERVER_DOWN) {
                throw ex;
            }
            LOG.debug("Server not supports: '" + protocol + "'", ex);
        }
    }
    return null;
}
Also used : LDAPConnectionPool(com.unboundid.ldap.sdk.LDAPConnectionPool) LDAPException(com.unboundid.ldap.sdk.LDAPException) GeneralSecurityException(java.security.GeneralSecurityException) FailoverServerSet(com.unboundid.ldap.sdk.FailoverServerSet)

Example 13 with LDAPException

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

the class LdapOperationsServiceImpl method scrollSimplePagedResultsControl.

private ASN1OctetString scrollSimplePagedResultsControl(LDAPConnection ldapConnection, String dn, Filter filter, SearchScope scope, Control[] controls, int startIndex) throws LDAPException, InvalidSimplePageControlException {
    SearchRequest searchRequest = new SearchRequest(dn, scope, filter, "dn");
    int currentStartIndex = startIndex;
    ASN1OctetString cookie = null;
    do {
        int pageSize = Math.min(currentStartIndex, 100);
        searchRequest.setControls(new Control[] { new SimplePagedResultsControl(pageSize, cookie, true) });
        setControls(searchRequest, controls);
        SearchResult searchResult = ldapConnection.search(searchRequest);
        currentStartIndex -= searchResult.getEntryCount();
        try {
            SimplePagedResultsControl c = SimplePagedResultsControl.get(searchResult);
            if (c != null) {
                cookie = c.getCookie();
            }
        } catch (LDAPException ex) {
            LOG.error("Error while accessing cookie", ex);
            throw new InvalidSimplePageControlException(ex.getResultCode(), "Error while accessing cookie");
        }
    } while ((cookie != null) && (cookie.getValueLength() > 0) && (currentStartIndex > 0));
    return cookie;
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) SearchRequest(com.unboundid.ldap.sdk.SearchRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) SearchResult(com.unboundid.ldap.sdk.SearchResult) SimplePagedResultsControl(com.unboundid.ldap.sdk.controls.SimplePagedResultsControl) InvalidSimplePageControlException(org.gluu.persist.ldap.exception.InvalidSimplePageControlException)

Example 14 with LDAPException

use of com.unboundid.ldap.sdk.LDAPException in project admin-console-beta by connexta.

the class TestLdapServer method startListening.

public TestLdapServer startListening(String ldifPath) {
    try {
        realServer = new InMemoryDirectoryServer(serverConfig);
        realServer.startListening();
    } catch (LDAPException e) {
        fail(e.getMessage());
    }
    loadLdifFile(ldifPath);
    return this;
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer)

Example 15 with LDAPException

use of com.unboundid.ldap.sdk.LDAPException in project admin-console-beta by connexta.

the class TestLdapServer method getInstance.

public static TestLdapServer getInstance() {
    TestLdapServer object = new TestLdapServer();
    try {
        InMemoryListenerConfig ldapConfig = InMemoryListenerConfig.createLDAPConfig(getBaseDistinguishedName(), null, getLdapPort(), object.getServerSSLContext().getSocketFactory());
        InMemoryListenerConfig ldapsConfig = InMemoryListenerConfig.createLDAPSConfig("ldaps", getLdapSecurePort(), object.getServerSSLContext().getServerSocketFactory());
        object.serverConfig = new InMemoryDirectoryServerConfig(getBaseDistinguishedName());
        object.serverConfig.setListenerConfigs(ldapConfig, ldapsConfig);
    } catch (LDAPException e) {
        fail(e.getMessage());
    }
    return object;
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) InMemoryDirectoryServerConfig(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig) InMemoryListenerConfig(com.unboundid.ldap.listener.InMemoryListenerConfig)

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