diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLAuthenticationProviderModule.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLAuthenticationProviderModule.java index 331707c38..03339a3f8 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLAuthenticationProviderModule.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLAuthenticationProviderModule.java @@ -69,6 +69,7 @@ public class PostgreSQLAuthenticationProviderModule implements Module { myBatisProperties.setProperty("JDBC.autoCommit", "false"); myBatisProperties.setProperty("mybatis.pooled.pingEnabled", "true"); myBatisProperties.setProperty("mybatis.pooled.pingQuery", "SELECT 1"); + myBatisProperties.setProperty("mybatis.configuration.defaultStatementTimeout", environment.getPostgreSQLDefaultStatementTimeout()); // Use UTF-8 in database driverProperties.setProperty("characterEncoding", "UTF-8"); diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/conf/PostgreSQLEnvironment.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/conf/PostgreSQLEnvironment.java index e81e6949e..8142d9c04 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/conf/PostgreSQLEnvironment.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/conf/PostgreSQLEnvironment.java @@ -48,6 +48,14 @@ public class PostgreSQLEnvironment extends JDBCEnvironment { */ private static final int DEFAULT_PORT = 5432; + /** + * The default defaultStatementTimeout (in seconds), + * if POSTGRESQL_DEFAULT_STATEMENT_TIMEOUT is not specified. + * Default to null (no timeout) + * https://mybatis.org/mybatis-3/configuration.html + */ + private static final String DEFAULT_DEFAULT_STATEMENT_TIMEOUT = "null"; + /** * Whether a database user account is required by default for authentication * to succeed. @@ -249,6 +257,23 @@ public class PostgreSQLEnvironment extends JDBCEnvironment { public String getPostgreSQLPassword() throws GuacamoleException { return getRequiredProperty(PostgreSQLGuacamoleProperties.POSTGRESQL_PASSWORD); } + + /** + * Returns the defaultStatementTimeout set for PostgreSQL connections. + * If unspecified, this will be the default "null" (no timeout) + * + * @return + * The statement timeout (in seconds) + * + * @throws GuacamoleException + * If an error occurs while retrieving the property value. + */ + public String getPostgreSQLDefaultStatementTimeout() throws GuacamoleException { + return getProperty( + PostgreSQLGuacamoleProperties.POSTGRESQL_DEFAULT_STATEMENT_TIMEOUT, + DEFAULT_DEFAULT_STATEMENT_TIMEOUT + ); + } @Override public boolean isRecursiveQuerySupported(SqlSession session) { diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/conf/PostgreSQLGuacamoleProperties.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/conf/PostgreSQLGuacamoleProperties.java index d2ae2532c..3295d7775 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/conf/PostgreSQLGuacamoleProperties.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/conf/PostgreSQLGuacamoleProperties.java @@ -94,6 +94,18 @@ public class PostgreSQLGuacamoleProperties { }; + /** + * Sets the number of seconds the driver will wait for + * a response from the database. + */ + public static final StringGuacamoleProperty + POSTGRESQL_DEFAULT_STATEMENT_TIMEOUT = new StringGuacamoleProperty(){ + + @Override + public String getName() { return "postgresql-default-statement-timeout"; } + + }; + /** * Whether a user account within the database is required for authentication * to succeed, even if the user has been authenticated via another diff --git a/guacamole-docker/bin/start.sh b/guacamole-docker/bin/start.sh index 62f9496dd..d661d1a23 100755 --- a/guacamole-docker/bin/start.sh +++ b/guacamole-docker/bin/start.sh @@ -354,6 +354,10 @@ END "postgresql-default-max-group-connections-per-user" \ "$POSTGRES_DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER" + set_optional_property \ + "postgresql-default-statement-timeout" \ + "$POSTGRES_DEFAULT_STATEMENT_TIMEOUT" + set_optional_property \ "postgresql-user-required" \ "$POSTGRES_USER_REQUIRED"