GUACAMOLE-101: Impelement properties for controller user and connection search filters.

This commit is contained in:
Nick Couchman
2017-03-20 22:15:14 -04:00
parent 8a0a6e3152
commit 2aec452aa5
4 changed files with 74 additions and 4 deletions

View File

@@ -270,7 +270,46 @@ public class ConfigurationService {
constraints.setDereference(getDereferenceAliases().DEREF_VALUE); constraints.setDereference(getDereferenceAliases().DEREF_VALUE);
return constraints; return constraints;
}
/**
* Returns the search filter that should be used when querying the
* LDAP server for Guacamole users. If no filter is specified,
* a default of objectClass=* is returned.
*
* @return
* The search filter that should be used when querying the
* LDAP server for users that are valid in Guacamole, or
* objectClass=* if not specified.
*
* @throws GuacamoleException
* If guacamole.properties cannot be parsed.
*/
public String getUserSearchFilter() throws GuacamoleException {
return environment.getProperty(
LDAPGuacamoleProperties.LDAP_USER_SEARCH_FILTER,
"(objectClass=*)"
);
}
/**
* Returns the search filter that should be used when querying the
* LDAP server for Guacamole connections. If no filter is specified,
* null is returned.
*
* @return
* The search filter that should be used when querying the
* LDAP server for connections for Guacamole, or
* null if no filter is specified.
*
* @throws GuacamoleException
* If guacamole.properties cannot be parsed.
*/
public String getConnectionSearchFilter() throws GuacamoleException {
return environment.getProperty(
LDAPGuacamoleProperties.LDAP_CONNECTION_SEARCH_FILTER,
"(objectClass=guacConfigGroup)"
);
} }
} }

View File

@@ -164,4 +164,24 @@ public class LDAPGuacamoleProperties {
}; };
/**
* A search filter to apply to the user LDAP query.
*/
public static final StringGuacamoleProperty LDAP_USER_SEARCH_FILTER = new StringGuacamoleProperty() {
@Override
public String getName() { return "ldap-user-search-filter"; }
};
/**
* A search filter to apply to the connection LDAP query.
*/
public static final StringGuacamoleProperty LDAP_CONNECTION_SEARCH_FILTER = new StringGuacamoleProperty() {
@Override
public String getName() { return "ldap-connection-search-filter"; }
};
} }

View File

@@ -227,7 +227,9 @@ public class ConnectionService {
StringBuilder connectionSearchFilter = new StringBuilder(); StringBuilder connectionSearchFilter = new StringBuilder();
// Add the prefix to the search filter, prefix filter searches for guacConfigGroups with the userDN as the member attribute value // Add the prefix to the search filter, prefix filter searches for guacConfigGroups with the userDN as the member attribute value
connectionSearchFilter.append("(&(objectClass=guacConfigGroup)(|(member="); connectionSearchFilter.append("(&");
connectionSearchFilter.append(confService.getConnectionSearchFilter());
connectionSearchFilter.append("(|(member=");
connectionSearchFilter.append(escapingService.escapeLDAPSearchFilter(userDN)); connectionSearchFilter.append(escapingService.escapeLDAPSearchFilter(userDN));
connectionSearchFilter.append(")"); connectionSearchFilter.append(")");
@@ -239,7 +241,7 @@ public class ConnectionService {
LDAPSearchResults userRoleGroupResults = ldapConnection.search( LDAPSearchResults userRoleGroupResults = ldapConnection.search(
groupBaseDN, groupBaseDN,
LDAPConnection.SCOPE_SUB, LDAPConnection.SCOPE_SUB,
"(&(!(objectClass=guacConfigGroup))(member=" + escapingService.escapeLDAPSearchFilter(userDN) + "))", "(&(!" + confService.getConnectionSearchFilter() + ")(member=" + escapingService.escapeLDAPSearchFilter(userDN) + "))",
null, null,
false, false,
confService.getLDAPSearchConstraints() confService.getLDAPSearchConstraints()

View File

@@ -85,11 +85,18 @@ public class UserService {
try { try {
StringBuilder userSearchFilter = new StringBuilder();
userSearchFilter.append("(&");
userSearchFilter.append(confService.getUserSearchFilter());
userSearchFilter.append("(" + escapeService.escapeLDAPSearchFilter(usernameAttribute) + "=*)");
userSearchFilter.append(")");
// Find all Guacamole users underneath base DN // Find all Guacamole users underneath base DN
LDAPSearchResults results = ldapConnection.search( LDAPSearchResults results = ldapConnection.search(
confService.getUserBaseDN(), confService.getUserBaseDN(),
LDAPConnection.SCOPE_SUB, LDAPConnection.SCOPE_SUB,
"(&(objectClass=*)(" + escapingService.escapeLDAPSearchFilter(usernameAttribute) + "=*))", userSearchFilter.toString(),
null, null,
false, false,
confService.getLDAPSearchConstraints() confService.getLDAPSearchConstraints()
@@ -189,7 +196,9 @@ public class UserService {
// Build LDAP query for users having at least one username attribute // Build LDAP query for users having at least one username attribute
// with the specified username as its value // with the specified username as its value
StringBuilder ldapQuery = new StringBuilder("(&(objectClass=*)"); StringBuilder ldapQuery = new StringBuilder();
ldapQuery.append("(&");
ldapQuery.append(confService.getUserSearchFilter());
// Include all attributes within OR clause if there are more than one // Include all attributes within OR clause if there are more than one
if (usernameAttributes.size() > 1) if (usernameAttributes.size() > 1)