Github user mike-jumper commented on a diff in the pull request:

    https://github.com/apache/guacamole-client/pull/204#discussion_r161587484
  
    --- Diff: 
extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/connection/ConnectionService.java
 ---
    @@ -113,56 +123,65 @@
                 // looking for direct membership in the guacConfigGroup
                 // and possibly any groups the user is a member of that are
                 // referred to in the seeAlso attribute of the guacConfigGroup.
    -            LDAPSearchResults results = ldapConnection.search(
    -                configurationBaseDN,
    -                LDAPConnection.SCOPE_SUB,
    -                connectionSearchFilter,
    -                null,
    -                false,
    -                confService.getLDAPSearchConstraints()
    -            );
    +            SearchRequest request = new SearchRequestImpl();
    +            request.setBase(configurationBaseDN);
    +            request.setDerefAliases(confService.getDereferenceAliases());
    +            request.setScope(SearchScope.SUBTREE);
    +            request.setFilter(connectionSearchFilter);
    +            request.setSizeLimit(confService.getMaxResults());
    +            request.setTimeLimit(confService.getOperationTimeout());
    +            request.setTypesOnly(false);
    +
    +            if(confService.getFollowReferrals())
    +                request.followReferrals();
    +
    +            SearchCursor results = ldapConnection.search(request);
     
                 // Build token filter containing credential tokens
                 TokenFilter tokenFilter = new TokenFilter();
                 StandardTokens.addStandardTokens(tokenFilter, user);
     
                 // Produce connections for each readable configuration
                 Map<String, Connection> connections = new HashMap<String, 
Connection>();
    -            while (results.hasMore()) {
    -
    -                try {
    -
    -                    LDAPEntry entry = results.next();
    -
    -                    // Get common name (CN)
    -                    LDAPAttribute cn = entry.getAttribute("cn");
    -                    if (cn == null) {
    -                        logger.warn("guacConfigGroup is missing a cn.");
    -                        continue;
    -                    }
    +            while (results.next()) {
    +
    +                // Get the entry
    +                Response response = results.get();
    +                Entry entry;
    +                if (response instanceof SearchResultEntry)
    +                    entry = ((SearchResultEntry)results).getEntry();
    +                else
    +                    continue;
    +
    +                // Get common name (CN)
    +                Attribute cn = entry.get("cn");
    +                if (cn == null) {
    +                    logger.warn("guacConfigGroup is missing a cn.");
    +                    continue;
    +                }
     
    -                    // Get associated protocol
    -                    LDAPAttribute protocol = 
entry.getAttribute("guacConfigProtocol");
    -                    if (protocol == null) {
    -                        logger.warn("guacConfigGroup \"{}\" is missing the 
"
    -                                  + "required \"guacConfigProtocol\" 
attribute.",
    -                                cn.getStringValue());
    -                        continue;
    -                    }
    +                // Get associated protocol
    +                Attribute protocol = entry.get("guacConfigProtocol");
    +                if (protocol == null) {
    +                    logger.warn("guacConfigGroup \"{}\" is missing the "
    +                              + "required \"guacConfigProtocol\" 
attribute.",
    +                            cn.getString());
    +                    continue;
    +                }
     
    -                    // Set protocol
    -                    GuacamoleConfiguration config = new 
GuacamoleConfiguration();
    -                    config.setProtocol(protocol.getStringValue());
    +                // Set protocol
    +                GuacamoleConfiguration config = new 
GuacamoleConfiguration();
    +                config.setProtocol(protocol.getString());
     
    -                    // Get parameters, if any
    -                    LDAPAttribute parameterAttribute = 
entry.getAttribute("guacConfigParameter");
    -                    if (parameterAttribute != null) {
    +                // Get parameters, if any
    +                Attribute parameterAttribute = 
entry.get("guacConfigParameter");
    +                if (parameterAttribute != null) {
     
    -                        // For each parameter
    -                        Enumeration<?> parameters = 
parameterAttribute.getStringValues();
    -                        while (parameters.hasMoreElements()) {
    +                    // For each parameter
    +                    Iterator parameters = parameterAttribute.iterator();
    --- End diff --
    
    By the way, for anything implementing `Iterable`, you can use a special 
`for` syntax to iterate through its contents. In this case, with 
`Iterable<Value<?>>`, you can:
    
        for (Value<?> value : parameterAttribute) {
            ...
        }
    
    There's generally no need to obtain the iterator itself unless you're going 
to be altering the contents of the iterated object through invoking 
`iterator.remove()`.


---

Reply via email to