GUACAMOLE-102: Change LDAP searches to use global LDAPSearchConstraints instead of instantiating their own each time.

This commit is contained in:
Nick Couchman
2017-03-19 21:09:00 -04:00
parent d1635ce28c
commit b816836e49
2 changed files with 4 additions and 21 deletions

View File

@@ -24,7 +24,6 @@ import com.novell.ldap.LDAPAttribute;
import com.novell.ldap.LDAPConnection; import com.novell.ldap.LDAPConnection;
import com.novell.ldap.LDAPEntry; import com.novell.ldap.LDAPEntry;
import com.novell.ldap.LDAPException; import com.novell.ldap.LDAPException;
import com.novell.ldap.LDAPSearchConstraints;
import com.novell.ldap.LDAPSearchResults; import com.novell.ldap.LDAPSearchResults;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
@@ -109,10 +108,6 @@ public class ConnectionService {
// current user // current user
String connectionSearchFilter = getConnectionSearchFilter(userDN, ldapConnection); String connectionSearchFilter = getConnectionSearchFilter(userDN, ldapConnection);
// Set Search Constraints
LDAPSearchConstraints constraints = new LDAPSearchConstraints();
constraints.setDereference(confService.getDereferenceAliases());
// Find all Guacamole connections for the given user by // Find all Guacamole connections for the given user by
// looking for direct membership in the guacConfigGroup // looking for direct membership in the guacConfigGroup
// and possibly any groups the user is a member of that are // and possibly any groups the user is a member of that are
@@ -123,7 +118,7 @@ public class ConnectionService {
connectionSearchFilter, connectionSearchFilter,
null, null,
false, false,
constraints confService.getLDAPSearchConstraints()
); );
// Build token filter containing credential tokens // Build token filter containing credential tokens
@@ -240,10 +235,6 @@ public class ConnectionService {
String groupBaseDN = confService.getGroupBaseDN(); String groupBaseDN = confService.getGroupBaseDN();
if (groupBaseDN != null) { if (groupBaseDN != null) {
// Set up LDAP constraints
LDAPSearchConstraints constraints = new LDAPSearchConstraints();
constraints.setDereference(confService.getDereferenceAliases());
// Get all groups the user is a member of starting at the groupBaseDN, excluding guacConfigGroups // Get all groups the user is a member of starting at the groupBaseDN, excluding guacConfigGroups
LDAPSearchResults userRoleGroupResults = ldapConnection.search( LDAPSearchResults userRoleGroupResults = ldapConnection.search(
groupBaseDN, groupBaseDN,
@@ -251,7 +242,7 @@ public class ConnectionService {
"(&(!(objectClass=guacConfigGroup))(member=" + escapingService.escapeLDAPSearchFilter(userDN) + "))", "(&(!(objectClass=guacConfigGroup))(member=" + escapingService.escapeLDAPSearchFilter(userDN) + "))",
null, null,
false, false,
constraints confService.getLDAPSearchConstraints()
); );
// Append the additional user groups to the LDAP filter // Append the additional user groups to the LDAP filter

View File

@@ -25,7 +25,6 @@ import com.novell.ldap.LDAPConnection;
import com.novell.ldap.LDAPEntry; import com.novell.ldap.LDAPEntry;
import com.novell.ldap.LDAPException; import com.novell.ldap.LDAPException;
import com.novell.ldap.LDAPSearchResults; import com.novell.ldap.LDAPSearchResults;
import com.novell.ldap.LDAPSearchConstraints;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -85,10 +84,6 @@ public class UserService {
String usernameAttribute) throws GuacamoleException { String usernameAttribute) throws GuacamoleException {
try { try {
// Set search limits
LDAPSearchConstraints constraints = new LDAPSearchConstraints();
constraints.setMaxResults(confService.getMaxResults());
constraints.setDereference(confService.getDereferenceAliases());
// Find all Guacamole users underneath base DN // Find all Guacamole users underneath base DN
LDAPSearchResults results = ldapConnection.search( LDAPSearchResults results = ldapConnection.search(
@@ -97,7 +92,7 @@ public class UserService {
"(&(objectClass=*)(" + escapingService.escapeLDAPSearchFilter(usernameAttribute) + "=*))", "(&(objectClass=*)(" + escapingService.escapeLDAPSearchFilter(usernameAttribute) + "=*))",
null, null,
false, false,
constraints confService.getLDAPSearchConstraints()
); );
// Read all visible users // Read all visible users
@@ -248,9 +243,6 @@ public class UserService {
List<String> userDNs = new ArrayList<String>(); List<String> userDNs = new ArrayList<String>();
LDAPSearchConstraints constraints = new LDAPSearchConstraints();
constraints.setDereference(confService.getDereferenceAliases());
// Find all Guacamole users underneath base DN and matching the // Find all Guacamole users underneath base DN and matching the
// specified username // specified username
LDAPSearchResults results = ldapConnection.search( LDAPSearchResults results = ldapConnection.search(
@@ -259,7 +251,7 @@ public class UserService {
generateLDAPQuery(username), generateLDAPQuery(username),
null, null,
false, false,
constraints confService.getLDAPSearchConstraints()
); );
// Add all DNs for found users // Add all DNs for found users