Skip to content

Commit

Permalink
GUACAMOLE-1239: Make sure case sensitivity warnings are only displaye…
Browse files Browse the repository at this point in the history
…d at startup.
  • Loading branch information
necouchman committed Oct 11, 2024
1 parent b2f74a6 commit 3d86026
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,19 @@
import org.apache.guacamole.auth.mysql.conf.MySQLEnvironment;
import org.apache.guacamole.auth.mysql.conf.MySQLSSLMode;
import org.mybatis.guice.datasource.helper.JdbcHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Guice module which configures MySQL-specific injections.
*/
public class MySQLAuthenticationProviderModule implements Module {

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

/**
* MyBatis-specific configuration properties.
*/
Expand Down Expand Up @@ -121,6 +128,15 @@ public MySQLAuthenticationProviderModule(MySQLEnvironment environment)
TimeZone serverTz = environment.getServerTimeZone();
if (serverTz != null)
driverProperties.setProperty("serverTimezone", serverTz.getID());

// Check for case-sensitivity and warn admin
if (environment.getCaseSensitiveUsernames())
LOGGER.warn("The MySQL module is currently configured to support "
+ "case-sensitive username comparisons, however, the default "
+ "collations for MySQL databases do not support "
+ "case-sensitive string comparisons. If you want usernames "
+ "within Guacamole to be treated as case-sensitive, further "
+ "database configuration may be required.");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,23 +446,12 @@ public boolean enforceAccessWindowsForActiveSessions() throws GuacamoleException
@Override
public boolean getCaseSensitiveUsernames() throws GuacamoleException {

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

// If property has been set to true, warn the admin.
if (caseSensitiveUsernames)
logger.warn("You have enabled case-sensitive usernames; however, "
+ "MySQL's default collations do not support case-sensitive "
+ "string comparisons. If you really want case-sensitive "
+ "usernames you will need to configure your database "
+ "appropriately.");

// Return the configured setting.
return caseSensitiveUsernames;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,19 @@
import org.apache.guacamole.auth.sqlserver.conf.SQLServerDriver;
import org.apache.guacamole.auth.sqlserver.conf.SQLServerEnvironment;
import org.mybatis.guice.datasource.helper.JdbcHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Guice module which configures SQLServer-specific injections.
*/
public class SQLServerAuthenticationProviderModule implements Module {

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

/**
* MyBatis-specific configuration properties.
*/
Expand Down Expand Up @@ -88,6 +95,15 @@ public SQLServerAuthenticationProviderModule(SQLServerEnvironment environment)

// Capture which driver to use for the connection.
this.sqlServerDriver = environment.getSQLServerDriver();

// Check for case-sensitivity and warn admin.
if (environment.getCaseSensitiveUsernames())
LOGGER.warn("The SQL Server module is currently configured to support "
+ "case-sensitive username comparisons, however, the default "
+ "collations for SQL Server databases do not support "
+ "case-sensitive string comparisons. If you want usernames "
+ "within Guacamole to be treated as case-sensitive, further "
+ "database configuration may be required.");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,6 @@ public boolean getCaseSensitiveUsernames() throws GuacamoleException {
super.getCaseSensitiveUsernames()
);

// If property has been set to true, warn the admin.
if (caseSensitiveUsernames)
logger.warn("You have configured this extension for case-sensitive "
+ "username comparisons, however, the default collations "
+ "for SQL Server databases do not support case-sensitive "
+ "string comparisons. Further database configuration may "
+ "be required in order for case-sensitive username "
+ "comparisons to function correctly.");

// Return as configured
return caseSensitiveUsernames;

Expand Down

0 comments on commit 3d86026

Please sign in to comment.