Skip to content

Commit

Permalink
GUACAMOLE-1239: Remove per-extension configuration for case-sensitivi…
Browse files Browse the repository at this point in the history
…ty, retaining only global configuration.
  • Loading branch information
necouchman committed Oct 31, 2024
1 parent 240dcd9 commit ddd0996
Show file tree
Hide file tree
Showing 31 changed files with 37 additions and 469 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,5 @@ public String getHttpAuthHeader() throws GuacamoleException {
"REMOTE_USER"
);
}

/**
* Returns true if the usernames provided to the header authentication
* module should be treated as case-sensitive, or false if usernames
* should be treated as case-insensitive. This will default to the global
* Guacamole configuration for case-sensitivity, which defaults to true, but
* can be overridden for this extension, if desired.
*
* @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(
HTTPHeaderGuacamoleProperties.HTTP_AUTH_CASE_SENSITIVE_USERNAMES,
environment.getCaseSensitiveUsernames()
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.apache.guacamole.auth.header;

import org.apache.guacamole.properties.BooleanGuacamoleProperty;
import org.apache.guacamole.properties.StringGuacamoleProperty;


Expand All @@ -44,17 +43,5 @@ private HTTPHeaderGuacamoleProperties() {}
public String getName() { return "http-auth-header"; }

};

/**
* A property used to configure whether or not usernames within the header
* module should be treated as case-sensitive.
*/
public static final BooleanGuacamoleProperty HTTP_AUTH_CASE_SENSITIVE_USERNAMES =
new BooleanGuacamoleProperty() {

@Override
public String getName() { return "http-auth-case-sensitive-usernames"; }

};

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,23 @@
package org.apache.guacamole.auth.header.user;

import com.google.inject.Inject;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.auth.header.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 HTTP header implementation of AuthenticatedUser, associating a
* username and particular set of credentials with the HTTP authentication
* provider.
*/
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;

/**
* Service for retrieving header configuration information.
*/
@Inject
private ConfigurationService confService;

/**
* The credentials provided when this user was authenticated.
Expand All @@ -72,19 +57,6 @@ public void init(String username, Credentials credentials) {
this.credentials = credentials;
setIdentifier(username.toLowerCase());
}

@Override
public boolean isCaseSensitive() {
try {
return confService.getCaseSensitiveUsernames();
}
catch (GuacamoleException e) {
LOGGER.error("Error when trying to retrieve header configuration: {}."
+ " Usernames comparison will be case-sensitive.", e);
LOGGER.debug("Exception caught when retrieving header configuration.", e);
return true;
}
}

@Override
public AuthenticationProvider getAuthenticationProvider() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,16 +442,5 @@ public boolean enforceAccessWindowsForActiveSessions() throws GuacamoleException
true
);
}

@Override
public boolean getCaseSensitiveUsernames() throws GuacamoleException {

// Return the configured value for the property, or the global value.
return getProperty(
MySQLGuacamoleProperties.MYSQL_CASE_SENSITIVE_USERNAMES,
super.getCaseSensitiveUsernames()
);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -303,18 +303,4 @@ private MySQLGuacamoleProperties() {}

};

/**
* A property used to configure whether or not usernames within the MySQL
* JDBC module should be treated as case-sensitive. Be aware that MySQL's
* default database collations do not do case-sensitive comparisons, so in
* many cases they will effectively be case-insensitive.
*/
public static final BooleanGuacamoleProperty MYSQL_CASE_SENSITIVE_USERNAMES =
new BooleanGuacamoleProperty() {

@Override
public String getName() { return "mysql-case-sensitive-usernames"; }

};

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.io.File;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.auth.jdbc.JDBCEnvironment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.guacamole.auth.jdbc.security.PasswordPolicy;
import org.apache.ibatis.session.SqlSession;

Expand All @@ -33,11 +31,6 @@
*/
public class PostgreSQLEnvironment extends JDBCEnvironment {

/**
* Logger for this class.
*/
private static final Logger logger = LoggerFactory.getLogger(PostgreSQLEnvironment.class);

/**
* The default host to connect to, if POSTGRESQL_HOSTNAME is not specified.
*/
Expand Down Expand Up @@ -398,20 +391,5 @@ public boolean enforceAccessWindowsForActiveSessions() throws GuacamoleException
PostgreSQLGuacamoleProperties.POSTGRESQL_ENFORCE_ACCESS_WINDOWS_FOR_ACTIVE_SESSIONS,
true);
}

@Override
public boolean getCaseSensitiveUsernames() throws GuacamoleException {

// By default, PostgreSQL does perform case-sensitive string comparisons.
// Even though usernames are generally not case-sensitive across
// most authenticaiton systems, we've elected to maintain case-
// sensitivity in this module in order to avoid surprising anyone who
// may be relying upon it.
return getProperty(
PostgreSQLGuacamoleProperties.POSTGRESQL_CASE_SENSITIVE_USERNAMES,
super.getCaseSensitiveUsernames()
);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -328,19 +328,5 @@ public boolean trustAllServerCertificates() throws GuacamoleException {
SQLServerGuacamoleProperties.SQLSERVER_TRUST_ALL_SERVER_CERTIFICATES,
false);
}

@Override
public boolean getCaseSensitiveUsernames() throws GuacamoleException {

// Get the configured or default value of the property.
boolean caseSensitiveUsernames = getProperty(
SQLServerGuacamoleProperties.SQLSERVER_CASE_SENSITIVE_USERNAMES,
super.getCaseSensitiveUsernames()
);

// Return as configured
return caseSensitiveUsernames;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -257,20 +257,5 @@ private SQLServerGuacamoleProperties() {}
public String getName() { return "sqlserver-trust-all-server-certificates"; }

};

/**
* A property used to configure whether or not usernames within the SQL
* Server JDBC module should be treated as case-sensitive. While Guacamole
* will treat usernames as case-sensitive by default, SQL Server's default
* database collations do not do case-sensitive string comparisons, so in
* many cases this will effectively result in case-insensitive usernames.
*/
public static final BooleanGuacamoleProperty SQLSERVER_CASE_SENSITIVE_USERNAMES =
new BooleanGuacamoleProperty() {

@Override
public String getName() { return "sqlserver-case-sensitive-usernames" ; }

};

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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;

Expand All @@ -39,20 +38,6 @@ 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.
Expand All @@ -79,25 +64,6 @@ public String getName() {
}

};

/**
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
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;
Expand All @@ -46,13 +44,6 @@ public class AuthenticatedUser extends AbstractAuthenticatedUser {
*/
@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.
Expand Down Expand Up @@ -82,19 +73,6 @@ public void init(Credentials credentials, UserData userData) {
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,5 @@ public String getMemberAttribute() throws GuacamoleException {
public MemberAttributeType getMemberAttributeType() throws GuacamoleException {
return config.getMemberAttributeType();
}

@Override
public boolean getCaseSensitiveUsernames() throws GuacamoleException {
return config.getCaseSensitiveUsernames();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.apache.guacamole.auth.ldap.conf;

import com.google.inject.Inject;
import java.util.Collections;
import java.util.List;
import org.apache.directory.api.ldap.model.filter.ExprNode;
Expand All @@ -28,20 +27,13 @@
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleServerException;
import org.apache.guacamole.environment.Environment;

/**
* LDAPConfiguration implementation that returns the default values for all
* configuration parameters. For any configuration parameters that are
* required (such as {@link #getUserBaseDN()}), an exception is thrown.
*/
public class DefaultLDAPConfiguration implements LDAPConfiguration {

/**
* The environment in which Guacamole is running.
*/
@Inject
private Environment environment;

@Override
public String appliesTo(String username) {
Expand Down Expand Up @@ -158,10 +150,5 @@ public MemberAttributeType getMemberAttributeType()
throws GuacamoleException {
return MemberAttributeType.DN;
}

@Override
public boolean getCaseSensitiveUsernames() throws GuacamoleException {
return environment.getCaseSensitiveUsernames();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -233,19 +233,5 @@ public MemberAttributeType getMemberAttributeType()
DEFAULT.getMemberAttributeType()
);
}

@Override
public boolean getCaseSensitiveUsernames() throws GuacamoleException {

// Most LDAP directories do not factor in case when comparing usernames,
// however, in order to avoid surprising anyone who may rely on this
// behavior in Guacamole, this is currently defaulted the overall
// Guacamole configuration (default of true), but can be over-ridden
// for the LDAP extension specifically, if desired.
return environment.getProperty(
LDAPGuacamoleProperties.LDAP_CASE_SENSITIVE_USERNAMES,
environment.getCaseSensitiveUsernames()
);
}

}
Loading

0 comments on commit ddd0996

Please sign in to comment.