Github user necouchman commented on a diff in the pull request:

    https://github.com/apache/guacamole-client/pull/204#discussion_r161546250
  
    --- 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 --
    
    Yeah, I think the API does not implement any method that allows for 
retrieving all of the string values at one time, so instead you have to get the 
iterator and got through and retrieve each value.  Let me know if you see 
something that makes you think there's an alternate way to do this.


---

Reply via email to