public ExprNode generateQuery(ExprNode filter,
            Collection<String> attributes, String attributeValue) {

        // Build LDAP query for objects having at least one attribute and with
        // the given search filter
        AndNode searchFilter = new AndNode();
        searchFilter.addNode(filter);

        // If no attributes provided, we're done.
        if (attributes.size() < 1)
            return searchFilter;

        // Include all attributes within OR clause
        OrNode attributeFilter = new OrNode();

        // If value is defined, check each attribute for that value.
        if (attributeValue != null) {
            attributes.forEach(attribute ->
                attributeFilter.addNode(new EqualityNode(attribute,
                        attributeValue))
            );
        }
        
        // If no value is defined, just check for presence of attribute.
        else {
            attributes.forEach(attribute ->
                attributeFilter.addNode(new PresenceNode(attribute))
            );            
        }

        searchFilter.addNode(attributeFilter);

        logger.trace("Sending LDAP filter: \"{}\"", searchFilter.toString());
        
        return searchFilter;

    }
Generates a properly-escaped LDAP query which finds all objects which
match the given LDAP filter and which have at least one of the given
attributes set to the specified value.

@param filter
    The LDAP filter to apply to reduce the results of the query in
    addition to testing the values of the given attributes.

@param attributes
    A collection of all attributes to test for equivalence to the given
    value, in order of decreasing priority.

@param attributeValue
    The value that the resulting LDAP query should search for within the
    attributes of objects within the LDAP directory. If null, the
    resulting LDAP query will search for the presence of at least one of
    the given attributes on each object, regardless of the value of
    those attributes.

@return
    An LDAP query which will search for arbitrary LDAP objects having at
    least one of the given attributes set to the specified value.
extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/ObjectQueryService.java