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;
}
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));
}
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);
}
}
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);
}
}
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);
}
}
Aggregations