diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLAuthenticationProviderModule.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLAuthenticationProviderModule.java index 92bc541cb..d1fc93d40 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLAuthenticationProviderModule.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLAuthenticationProviderModule.java @@ -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 diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/conf/MySQLEnvironment.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/conf/MySQLEnvironment.java index f45231937..31f04e559 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/conf/MySQLEnvironment.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/conf/MySQLEnvironment.java @@ -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); + } + } diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/conf/MySQLGuacamoleProperties.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/conf/MySQLGuacamoleProperties.java index 8318b8951..925f82a72 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/conf/MySQLGuacamoleProperties.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/conf/MySQLGuacamoleProperties.java @@ -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"; } }; diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/properties/TimeZoneGuacamoleProperty.java b/guacamole-ext/src/main/java/org/apache/guacamole/properties/TimeZoneGuacamoleProperty.java new file mode 100644 index 000000000..78770213a --- /dev/null +++ b/guacamole-ext/src/main/java/org/apache/guacamole/properties/TimeZoneGuacamoleProperty.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.guacamole.properties; + +import java.util.TimeZone; +import org.apache.guacamole.GuacamoleException; + +/** + * A GuacamoleProperty whose value is a TimeZone. + */ +public abstract class TimeZoneGuacamoleProperty + implements GuacamoleProperty { + + @Override + public TimeZone parseValue(String value) throws GuacamoleException { + + // Nothing in, nothing out + if (value == null || value.isEmpty()) + return null; + + // Attempt to return the TimeZone of the provided string value. + return TimeZone.getTimeZone(value); + + } + +}