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