Search in sources :

Example 11 with LDAPConnection

use of com.unboundid.ldap.sdk.LDAPConnection in project keywhiz by square.

the class LdapConnectionFactory method getLDAPConnection.

public LDAPConnection getLDAPConnection(String userDN, String password) throws LDAPException, GeneralSecurityException {
    TrustStoreTrustManager trust = new TrustStoreTrustManager(trustStorePath, trustStorePassword.toCharArray(), trustStoreType, false);
    LDAPConnectionOptions options = new LDAPConnectionOptions();
    options.setSSLSocketVerifier(new HostNameSSLSocketVerifier(false));
    SSLUtil sslUtil = new SSLUtil(trust);
    SocketFactory factory = new EndpointIdentificationSocketFactory(sslUtil.createSSLSocketFactory("TLSv1.2"));
    LDAPConnection ldapConnection = new LDAPConnection(factory, options);
    // Connect, retrieve the DN of the user (if any)
    ldapConnection.connect(server, port);
    ldapConnection.bind(userDN, password);
    return ldapConnection;
}
Also used : LDAPConnectionOptions(com.unboundid.ldap.sdk.LDAPConnectionOptions) SSLUtil(com.unboundid.util.ssl.SSLUtil) HostNameSSLSocketVerifier(com.unboundid.util.ssl.HostNameSSLSocketVerifier) TrustStoreTrustManager(com.unboundid.util.ssl.TrustStoreTrustManager) SocketFactory(javax.net.SocketFactory) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection)

Example 12 with LDAPConnection

use of com.unboundid.ldap.sdk.LDAPConnection in project zm-mailbox by Zimbra.

the class UBIDLdapContext method getConnection.

private LDAPConnection getConnection(LDAPConnectionPool pool) throws LdapException {
    try {
        // TODO: this is for backward compatibility with the legacy code - remvoe or enhance
        // TODO: should have a timer for each connection pool
        long start = 0;
        if (isZimbraLdap) {
            start = ZimbraPerf.STOPWATCH_LDAP_DC.start();
        }
        LDAPConnection connection = UBIDLdapOperation.GET_CONNECTION.execute(this, pool);
        if (isZimbraLdap) {
            ZimbraPerf.STOPWATCH_LDAP_DC.stop(start);
        }
        LdapConnectionPool.debugCheckOut(pool, connection);
        return connection;
    } catch (LDAPException e) {
        throw mapToLdapException("unable to get connection", e);
    }
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection)

Example 13 with LDAPConnection

use of com.unboundid.ldap.sdk.LDAPConnection in project cas by apereo.

the class LdapContinuousIntegrationSpnegoKnownClientSystemsFilterActionTests method bootstrap.

@BeforeClass
public static void bootstrap() throws Exception {
    final LDAPConnection c = new LDAPConnection("localhost", 10389, "cn=Directory Manager", "password");
    LdapIntegrationTestsOperations.populateDefaultEntries(c, "ou=people,dc=example,dc=org");
}
Also used : LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) BeforeClass(org.junit.BeforeClass)

Example 14 with LDAPConnection

use of com.unboundid.ldap.sdk.LDAPConnection 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 15 with LDAPConnection

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

the class LdapEntryManager method loadLdifFileContent.

public boolean loadLdifFileContent(String ldifFileContent) {
    LDAPConnection connection = null;
    try {
        connection = ldapOperationService.getConnection();
        ResultCode result = LdifDataUtility.instance().importLdifFileContent(connection, ldifFileContent);
        return ResultCode.SUCCESS.equals(result);
    } catch (Exception ex) {
        LOG.error("Failed to load ldif file", ex);
        return false;
    } finally {
        if (connection != null) {
            ldapOperationService.releaseConnection(connection);
        }
    }
}
Also used : LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) ResultCode(com.unboundid.ldap.sdk.ResultCode) 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)

Aggregations

LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)17 LDAPException (com.unboundid.ldap.sdk.LDAPException)8 SearchResult (com.unboundid.ldap.sdk.SearchResult)4 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)3 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)3 IOException (java.io.IOException)3 BindResult (com.unboundid.ldap.sdk.BindResult)2 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)2 ResultCode (com.unboundid.ldap.sdk.ResultCode)2 StartTLSExtendedRequest (com.unboundid.ldap.sdk.extensions.StartTLSExtendedRequest)2 SSLUtil (com.unboundid.util.ssl.SSLUtil)2 GeneralSecurityException (java.security.GeneralSecurityException)2 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)2 MappingException (org.gluu.persist.exception.mapping.MappingException)2 ConnectionException (org.gluu.persist.exception.operation.ConnectionException)2 SearchException (org.gluu.persist.exception.operation.SearchException)2 LdifDataUtility (org.gluu.persist.ldap.impl.LdifDataUtility)2 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)1 LDAPConnectionOptions (com.unboundid.ldap.sdk.LDAPConnectionOptions)1 LDAPSearchException (com.unboundid.ldap.sdk.LDAPSearchException)1