mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUACAMOLE-101: Merge support for arbitrary filtering of LDAP users.
This commit is contained in:
@@ -270,7 +270,26 @@ 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=*)"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -164,4 +164,14 @@ public class LDAPGuacamoleProperties {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A search filter to apply to user LDAP queries.
|
||||||
|
*/
|
||||||
|
public static final StringGuacamoleProperty LDAP_USER_SEARCH_FILTER = new StringGuacamoleProperty() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() { return "ldap-user-search-filter"; }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -85,11 +85,20 @@ public class UserService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
// Build a filter using the configured or default user search filter
|
||||||
|
// to find all user objects in the LDAP tree
|
||||||
|
StringBuilder userSearchFilter = new StringBuilder();
|
||||||
|
userSearchFilter.append("(&");
|
||||||
|
userSearchFilter.append(confService.getUserSearchFilter());
|
||||||
|
userSearchFilter.append("(");
|
||||||
|
userSearchFilter.append(escapingService.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()
|
||||||
@@ -188,8 +197,10 @@ public class UserService {
|
|||||||
List<String> usernameAttributes = confService.getUsernameAttributes();
|
List<String> usernameAttributes = confService.getUsernameAttributes();
|
||||||
|
|
||||||
// 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
|
// and with the configured or default search filter
|
||||||
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)
|
||||||
|
Reference in New Issue
Block a user