Search in sources :

Example 96 with LdapConnection

use of org.apache.directory.ldap.client.api.LdapConnection in project activemq-artemis by apache.

the class CachedLDAPAuthorizationModuleOpenLDAPTest method getLdapConnection.

@Override
protected LdapConnection getLdapConnection() throws LdapException, IOException {
    LdapConnection connection = new LdapNetworkConnection(LDAP_HOST, LDAP_PORT);
    connection.bind(new Dn(LDAP_USER), LDAP_PASS);
    return connection;
}
Also used : Dn(org.apache.directory.shared.ldap.model.name.Dn) LdapNetworkConnection(org.apache.directory.ldap.client.api.LdapNetworkConnection) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 97 with LdapConnection

use of org.apache.directory.ldap.client.api.LdapConnection in project jackrabbit-oak by apache.

the class UnboundLookupConnectionValidatorTest method testValidateThrowsException.

@Test
public void testValidateThrowsException() throws Exception {
    LdapConnection connection = Mockito.mock(LdapConnection.class);
    doThrow(LdapException.class).when(connection).lookup(Dn.ROOT_DSE, SchemaConstants.NO_ATTRIBUTE);
    assertFalse(validator.validate(connection));
}
Also used : LdapConnection(org.apache.directory.ldap.client.api.LdapConnection) Test(org.junit.Test)

Example 98 with LdapConnection

use of org.apache.directory.ldap.client.api.LdapConnection in project jackrabbit-oak by apache.

the class LdapIdentityProvider method getDeclaredMemberRefs.

/**
 * Collects the declared (direct) members of a group
 * @param ref the reference to the group
 * @return map of identity refers
 * @throws ExternalIdentityException if an error occurs
 */
Map<String, ExternalIdentityRef> getDeclaredMemberRefs(ExternalIdentityRef ref) throws ExternalIdentityException {
    if (!isMyRef(ref)) {
        return Collections.emptyMap();
    }
    LdapConnection connection = null;
    try {
        Map<String, ExternalIdentityRef> members = new HashMap<String, ExternalIdentityRef>();
        DebugTimer timer = new DebugTimer();
        connection = connect();
        timer.mark("connect");
        Entry entry = connection.lookup(ref.getId());
        timer.mark("lookup");
        Attribute attr = entry.get(config.getGroupMemberAttribute());
        if (attr == null) {
            log.warn("LDAP group does not have configured attribute: {}", config.getGroupMemberAttribute());
        } else {
            for (Value value : attr) {
                ExternalIdentityRef memberRef = new ExternalIdentityRef(value.getString(), this.getName());
                members.put(memberRef.getId(), memberRef);
            }
        }
        timer.mark("iterate");
        if (log.isDebugEnabled()) {
            log.debug("members lookup of {} found {} members. {}", ref.getId(), members.size(), timer.getString());
        }
        return members;
    } catch (Exception e) {
        String msg = "Error during ldap group members lookup.";
        log.error(msg, e);
        throw new ExternalIdentityException(msg, e);
    } finally {
        disconnect(connection);
    }
}
Also used : DebugTimer(org.apache.jackrabbit.oak.commons.DebugTimer) Entry(org.apache.directory.api.ldap.model.entry.Entry) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry) ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) HashMap(java.util.HashMap) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) Value(org.apache.directory.api.ldap.model.entry.Value) ExternalIdentityException(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException) LoginException(javax.security.auth.login.LoginException) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) ExternalIdentityException(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 99 with LdapConnection

use of org.apache.directory.ldap.client.api.LdapConnection in project jackrabbit-oak by apache.

the class LdapIdentityProvider method getUser.

@Override
public ExternalUser getUser(@Nonnull String userId) throws ExternalIdentityException {
    DebugTimer timer = new DebugTimer();
    LdapConnection connection = connect();
    timer.mark("connect");
    try {
        Entry entry = getEntry(connection, config.getUserConfig(), userId, config.getCustomAttributes());
        timer.mark("lookup");
        if (log.isDebugEnabled()) {
            log.debug("getUser({}) {}", userId, timer.getString());
        }
        if (entry != null) {
            return createUser(entry, userId);
        } else {
            return null;
        }
    } catch (LdapException | CursorException e) {
        throw lookupFailedException(e, timer);
    } finally {
        disconnect(connection);
    }
}
Also used : DebugTimer(org.apache.jackrabbit.oak.commons.DebugTimer) Entry(org.apache.directory.api.ldap.model.entry.Entry) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 100 with LdapConnection

use of org.apache.directory.ldap.client.api.LdapConnection in project airavata by apache.

the class IULdapSSHAccountProvisioner method withLdapConnection.

private <R> R withLdapConnection(Function<LdapConnection, R> function) {
    try (LdapConnection connection = new LdapNetworkConnection(ldapHost, ldapPort, true)) {
        connection.bind(ldapUsername, ldapPassword);
        R result = function.apply(connection);
        connection.unBind();
        return result;
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (LdapException e) {
        throw new RuntimeException(e);
    }
}
Also used : LdapNetworkConnection(org.apache.directory.ldap.client.api.LdapNetworkConnection) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Aggregations

LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)180 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)166 ArrayList (java.util.ArrayList)90 FinderException (org.apache.directory.fortress.core.FinderException)73 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)65 Entry (org.apache.directory.api.ldap.model.entry.Entry)52 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)49 Modification (org.apache.directory.api.ldap.model.entry.Modification)43 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)41 UpdateException (org.apache.directory.fortress.core.UpdateException)41 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)37 LdapNoSuchObjectException (org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException)20 CreateException (org.apache.directory.fortress.core.CreateException)17 RemoveException (org.apache.directory.fortress.core.RemoveException)17 IOException (java.io.IOException)14 LdapNetworkConnection (org.apache.directory.ldap.client.api.LdapNetworkConnection)14 Permission (org.apache.directory.fortress.core.model.Permission)9 Dn (org.apache.directory.api.ldap.model.name.Dn)7 EntryCursor (org.apache.directory.api.ldap.model.cursor.EntryCursor)6 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)6