GUACAMOLE-1239: Make identifier comparison case-insensitive.

This commit is contained in:
Virtually Nick
2023-07-18 17:26:40 -04:00
parent 073d1d476e
commit 4d5101574a
43 changed files with 853 additions and 12 deletions

View File

@@ -24,6 +24,7 @@ import java.util.Collection;
import java.util.Collections;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.environment.Environment;
import org.apache.guacamole.properties.BooleanGuacamoleProperty;
import org.apache.guacamole.properties.ByteArrayProperty;
import org.apache.guacamole.properties.StringGuacamoleProperty;
@@ -39,6 +40,20 @@ public class ConfigurationService {
@Inject
private Environment environment;
/**
* A property used to configure whether or not usernames within the JSON
* module should be treated as case-sensitive.
*/
private static final BooleanGuacamoleProperty JSON_CASE_SENSITIVE_USERNAMES =
new BooleanGuacamoleProperty() {
@Override
public String getName() {
return "json-case-sensitive-usernames";
}
};
/**
* The encryption key to use for all decryption and signature verification.
*/
@@ -64,6 +79,25 @@ public class ConfigurationService {
}
};
/**
* Returns true if the usernames provided to the JSON authentication
* module should be treated as case-sensitive, or false if usernames
* should be treated as case-insensitive. The default will be taken from
* the global Guacamole configuration, which defaults to true, but
* can be overridden for this extension.
*
* @return
* true if usernames should be treated as case-sensitive, otherwise
* false.
*
* @throws GuacamoleException
* If guacamole.properties cannot be parsed.
*/
public boolean getCaseSensitiveUsernames() throws GuacamoleException {
return environment.getProperty(JSON_CASE_SENSITIVE_USERNAMES,
environment.getCaseSensitiveUsernames());
}
/**
* Returns the symmetric key which will be used to encrypt and sign all

View File

@@ -20,9 +20,13 @@
package org.apache.guacamole.auth.json.user;
import com.google.inject.Inject;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.auth.json.ConfigurationService;
import org.apache.guacamole.net.auth.AbstractAuthenticatedUser;
import org.apache.guacamole.net.auth.AuthenticationProvider;
import org.apache.guacamole.net.auth.Credentials;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* An implementation of AuthenticatedUser specific to the
@@ -31,12 +35,24 @@ import org.apache.guacamole.net.auth.Credentials;
*/
public class AuthenticatedUser extends AbstractAuthenticatedUser {
/**
* Logger for this class.
*/
private static final Logger LOGGER = LoggerFactory.getLogger(AuthenticatedUser.class);
/**
* Reference to the authentication provider associated with this
* authenticated user.
*/
@Inject
private AuthenticationProvider authProvider;
/**
* Reference to the configuration service associated with this
* authentication provider.
*/
@Inject
private ConfigurationService confService;
/**
* The credentials provided when this user was authenticated.
@@ -66,6 +82,19 @@ public class AuthenticatedUser extends AbstractAuthenticatedUser {
this.userData = userData;
setIdentifier(userData.getUsername());
}
@Override
public boolean isCaseSensitive() {
try {
return confService.getCaseSensitiveUsernames();
}
catch (GuacamoleException e) {
LOGGER.error("Error when attempting to get the JSON configuration: {}. "
+ "Username comparisons will be case-sensitive.", e.getMessage());
LOGGER.debug("Exception caught while retrieving JSON configuration.", e);
return true;
}
}
@Override
public AuthenticationProvider getAuthenticationProvider() {