GUACAMOLE-760: Add support for configuring server timezone.

This commit is contained in:
Virtually Nick
2019-12-26 22:35:34 -05:00
parent 0091bb1aea
commit 0ec9bec4c8
4 changed files with 75 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ import com.google.inject.Module;
import com.google.inject.name.Names;
import java.io.File;
import java.util.Properties;
import java.util.TimeZone;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.auth.mysql.conf.MySQLDriver;
import org.apache.guacamole.auth.mysql.conf.MySQLEnvironment;
@@ -115,6 +116,11 @@ public class MySQLAuthenticationProviderModule implements Module {
// Get the MySQL-compatible driver to use.
mysqlDriver = environment.getMySQLDriver();
// If timezone is present, set it.
TimeZone serverTz = environment.getServerTimeZone();
if (serverTz != null)
driverProperties.setProperty("serverTimezone", serverTz.getID());
}
@Override

View File

@@ -23,6 +23,7 @@ import java.io.File;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.TimeZone;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.auth.jdbc.JDBCEnvironment;
import org.slf4j.Logger;
@@ -393,4 +394,18 @@ public class MySQLEnvironment extends JDBCEnvironment {
false);
}
/**
* Return the server timezone if configured in guacamole.properties, or
* null if the configuration option is not present.
*
* @return
* The server timezone as configured in guacamole.properties.
*
* @throws GuacamoleException
* If an error occurs retrieving the configuration value.
*/
public TimeZone getServerTimeZone() throws GuacamoleException {
return getProperty(MySQLGuacamoleProperties.SERVER_TIMEZONE);
}
}

View File

@@ -24,6 +24,7 @@ import org.apache.guacamole.properties.EnumGuacamoleProperty;
import org.apache.guacamole.properties.FileGuacamoleProperty;
import org.apache.guacamole.properties.IntegerGuacamoleProperty;
import org.apache.guacamole.properties.StringGuacamoleProperty;
import org.apache.guacamole.properties.TimeZoneGuacamoleProperty;
/**
* Properties used by the MySQL Authentication plugin.
@@ -251,6 +252,16 @@ public class MySQLGuacamoleProperties {
@Override
public String getName() { return "mysql-auto-create-accounts"; }
};
/**
* The time zone of the MySQL database server.
*/
public static final TimeZoneGuacamoleProperty SERVER_TIMEZONE =
new TimeZoneGuacamoleProperty() {
@Override
public String getName() { return "mysql-server-timezone"; }
};