Search in sources :

Example 1 with Value

use of org.apache.directory.api.ldap.model.entry.Value in project midpoint by Evolveum.

the class AbstractLdapTest method assertAttributeNotContains.

protected void assertAttributeNotContains(Entry entry, String attrName, String expectedValue, MatchingRule<String> matchingRule) throws LdapInvalidAttributeValueException, SchemaException {
    String dn = entry.getDn().toString();
    Attribute ldapAttribute = entry.get(attrName);
    if (ldapAttribute == null) {
        return;
    } else {
        Iterator<Value<?>> iterator = ldapAttribute.iterator();
        while (iterator.hasNext()) {
            Value<?> value = iterator.next();
            if (matchingRule == null) {
                if (expectedValue.equals(value.getString())) {
                    AssertJUnit.fail("Attribute " + attrName + " in " + dn + " contains value " + expectedValue + ", but it should not have it");
                }
            } else {
                if (matchingRule.match(expectedValue, value.getString())) {
                    AssertJUnit.fail("Attribute " + attrName + " in " + dn + " contains value " + expectedValue + ", but it should not have it");
                }
            }
        }
    }
}
Also used : Attribute(org.apache.directory.api.ldap.model.entry.Attribute) Value(org.apache.directory.api.ldap.model.entry.Value)

Example 2 with Value

use of org.apache.directory.api.ldap.model.entry.Value in project midpoint by Evolveum.

the class AbstractLdapTest method assertAttributeContains.

protected void assertAttributeContains(Entry entry, String attrName, String expectedValue, MatchingRule<String> matchingRule) throws LdapInvalidAttributeValueException, SchemaException {
    String dn = entry.getDn().toString();
    Attribute ldapAttribute = entry.get(attrName);
    if (ldapAttribute == null) {
        if (expectedValue == null) {
            return;
        } else {
            AssertJUnit.fail("No attribute " + attrName + " in " + dn + ", expected: " + expectedValue);
        }
    } else {
        List<String> vals = new ArrayList<>();
        Iterator<Value<?>> iterator = ldapAttribute.iterator();
        while (iterator.hasNext()) {
            Value<?> value = iterator.next();
            if (matchingRule == null) {
                if (expectedValue.equals(value.getString())) {
                    return;
                }
            } else {
                if (matchingRule.match(expectedValue, value.getString())) {
                    return;
                }
            }
            vals.add(value.getString());
        }
        AssertJUnit.fail("Wrong attribute " + attrName + " in " + dn + " expected to contain value " + expectedValue + " but it has values " + vals);
    }
}
Also used : Attribute(org.apache.directory.api.ldap.model.entry.Attribute) ArrayList(java.util.ArrayList) Value(org.apache.directory.api.ldap.model.entry.Value)

Example 3 with Value

use of org.apache.directory.api.ldap.model.entry.Value 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) HashMap(java.util.HashMap) ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) 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)

Aggregations

Attribute (org.apache.directory.api.ldap.model.entry.Attribute)3 Value (org.apache.directory.api.ldap.model.entry.Value)3 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NoSuchElementException (java.util.NoSuchElementException)1 LoginException (javax.security.auth.login.LoginException)1 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)1 Entry (org.apache.directory.api.ldap.model.entry.Entry)1 LdapAuthenticationException (org.apache.directory.api.ldap.model.exception.LdapAuthenticationException)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)1 SearchResultEntry (org.apache.directory.api.ldap.model.message.SearchResultEntry)1 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)1 DebugTimer (org.apache.jackrabbit.oak.commons.DebugTimer)1 ExternalIdentityException (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException)1 ExternalIdentityRef (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef)1