Search in sources :

Example 1 with LDAPAttribute

use of org.structr.ldap.entity.LDAPAttribute in project structr by structr.

the class StructrLDAPWrapper method evaluateSubstringNode.

private boolean evaluateSubstringNode(final LDAPNode node, final SubstringNode substringNode) throws FrameworkException, LdapInvalidAttributeValueException {
    final Attribute attribute = new DefaultAttribute(substringNode.getAttributeType());
    final String oid = attribute.getId();
    final String initialPart = substringNode.getInitial();
    final String finalPart = substringNode.getFinal();
    final List<String> any = new LinkedList<>();
    final List<String> fromNode = substringNode.getAny();
    // add fragments from substring node (if present)
    if (fromNode != null) {
        any.addAll(fromNode);
    }
    final Pattern pattern = SubstringNode.getRegex(initialPart, any.toArray(new String[0]), finalPart);
    for (final LDAPAttribute attr : node.getAttributes()) {
        if (oid.equals(attr.getOid())) {
            for (final LDAPValue value : attr.getValues()) {
                final String stringValue = value.getStringValue().toLowerCase();
                final Matcher matcher = pattern.matcher(stringValue);
                if (matcher.matches()) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Pattern(java.util.regex.Pattern) LDAPAttribute(org.structr.ldap.entity.LDAPAttribute) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) NodeAttribute(org.structr.core.graph.NodeAttribute) LDAPAttribute(org.structr.ldap.entity.LDAPAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) Matcher(java.util.regex.Matcher) LDAPValue(org.structr.ldap.entity.LDAPValue) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) LinkedList(java.util.LinkedList)

Example 2 with LDAPAttribute

use of org.structr.ldap.entity.LDAPAttribute in project structr by structr.

the class StructrLDAPWrapper method getAttribute.

public Attribute getAttribute(final LDAPAttribute src) throws LdapInvalidAttributeValueException {
    final AttributeType type = schemaManager.getAttributeType(src.getOid());
    final Attribute attribute = new DefaultAttribute(type);
    final String name = src.getUserProvidedId();
    if (name != null) {
        attribute.setUpId(name);
    }
    for (final LDAPValue value : src.getValues()) {
        attribute.add(value.getStringValue());
    }
    return attribute;
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) NodeAttribute(org.structr.core.graph.NodeAttribute) LDAPAttribute(org.structr.ldap.entity.LDAPAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) LDAPValue(org.structr.ldap.entity.LDAPValue) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute)

Aggregations

Attribute (org.apache.directory.api.ldap.model.entry.Attribute)2 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)2 NodeAttribute (org.structr.core.graph.NodeAttribute)2 LDAPAttribute (org.structr.ldap.entity.LDAPAttribute)2 LDAPValue (org.structr.ldap.entity.LDAPValue)2 LinkedList (java.util.LinkedList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)1