GUAC-830: Add new concurrency properties. Warn of deprecation and suggest alternatives in the logs.

This commit is contained in:
Michael Jumper
2015-08-23 13:15:32 -07:00
parent 5aa871afcd
commit 9b27a27441
4 changed files with 244 additions and 31 deletions

View File

@@ -34,6 +34,8 @@ import org.glyptodon.guacamole.auth.jdbc.tunnel.ConfigurableGuacamoleTunnelServi
import org.glyptodon.guacamole.auth.jdbc.user.UserContextService;
import org.glyptodon.guacamole.environment.Environment;
import org.glyptodon.guacamole.environment.LocalEnvironment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Provides a MySQL based implementation of the AuthenticationProvider
@@ -44,6 +46,11 @@ import org.glyptodon.guacamole.environment.LocalEnvironment;
*/
public class MySQLAuthenticationProvider implements AuthenticationProvider {
/**
* Logger for this class.
*/
private static final Logger logger = LoggerFactory.getLogger(MySQLAuthenticationProvider.class);
/**
* Injector which will manage the object graph of this authentication
* provider.
@@ -75,28 +82,75 @@ public class MySQLAuthenticationProvider implements AuthenticationProvider {
int connectionGroupDefaultMaxConnectionsPerUser;
// Read legacy concurrency-related properties
boolean disallowSimultaneous = environment.getProperty(MySQLGuacamoleProperties.MYSQL_DISALLOW_SIMULTANEOUS_CONNECTIONS, false);
boolean disallowDuplicate = environment.getProperty(MySQLGuacamoleProperties.MYSQL_DISALLOW_DUPLICATE_CONNECTIONS, true);
// Legacy properties to not affect max connections per group
connectionGroupDefaultMaxConnections = 0;
Boolean disallowSimultaneous = environment.getProperty(MySQLGuacamoleProperties.MYSQL_DISALLOW_SIMULTANEOUS_CONNECTIONS);
Boolean disallowDuplicate = environment.getProperty(MySQLGuacamoleProperties.MYSQL_DISALLOW_DUPLICATE_CONNECTIONS);
// Legacy "simultaneous" property dictates only the maximum number of
// connections per connection
if (disallowSimultaneous)
connectionDefaultMaxConnections = 1;
else
connectionDefaultMaxConnections = 0;
if (disallowSimultaneous != null) {
// Translate legacy property
if (disallowSimultaneous) {
connectionDefaultMaxConnections = 1;
connectionGroupDefaultMaxConnections = 0;
}
else {
connectionDefaultMaxConnections = 0;
connectionGroupDefaultMaxConnections = 0;
}
// Warn of deprecation
logger.warn("The \"{}\" property is deprecated. Use \"{}\" and \"{}\" instead.",
MySQLGuacamoleProperties.MYSQL_DISALLOW_SIMULTANEOUS_CONNECTIONS.getName(),
MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_CONNECTIONS.getName(),
MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_GROUP_CONNECTIONS.getName());
// Inform of new equivalent
logger.info("To achieve the same result of setting \"{}\" to \"{}\", set \"{}\" to \"{}\" and \"{}\" to \"{}\".",
MySQLGuacamoleProperties.MYSQL_DISALLOW_SIMULTANEOUS_CONNECTIONS.getName(), disallowSimultaneous,
MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_CONNECTIONS.getName(), connectionDefaultMaxConnections,
MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_GROUP_CONNECTIONS.getName(), connectionGroupDefaultMaxConnections);
}
// If legacy property is not specified, use new property
else {
connectionDefaultMaxConnections = environment.getProperty(MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_CONNECTIONS, 0);
connectionGroupDefaultMaxConnections = environment.getProperty(MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_GROUP_CONNECTIONS, 0);
}
// Legacy "duplicate" property dictates whether connections and groups
// may be used concurrently only by different users
if (disallowDuplicate) {
connectionDefaultMaxConnectionsPerUser = 1;
connectionGroupDefaultMaxConnectionsPerUser = 1;
if (disallowDuplicate != null) {
// Translate legacy property
if (disallowDuplicate) {
connectionDefaultMaxConnectionsPerUser = 1;
connectionGroupDefaultMaxConnectionsPerUser = 1;
}
else {
connectionDefaultMaxConnectionsPerUser = 0;
connectionGroupDefaultMaxConnectionsPerUser = 0;
}
// Warn of deprecation
logger.warn("The \"{}\" property is deprecated. Use \"{}\" and \"{}\" instead.",
MySQLGuacamoleProperties.MYSQL_DISALLOW_DUPLICATE_CONNECTIONS.getName(),
MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_CONNECTIONS_PER_USER.getName(),
MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_GROUP_CONNECTIONS.getName());
// Inform of new equivalent
logger.info("To achieve the same result of setting \"{}\" to \"{}\", set \"{}\" to \"{}\" and \"{}\" to \"{}\".",
MySQLGuacamoleProperties.MYSQL_DISALLOW_DUPLICATE_CONNECTIONS.getName(), disallowDuplicate,
MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_CONNECTIONS_PER_USER.getName(), connectionDefaultMaxConnectionsPerUser,
MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER.getName(), connectionGroupDefaultMaxConnectionsPerUser);
}
// If legacy property is not specified, use new property
else {
connectionDefaultMaxConnectionsPerUser = 0;
connectionGroupDefaultMaxConnectionsPerUser = 0;
connectionDefaultMaxConnectionsPerUser = environment.getProperty(MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_CONNECTIONS_PER_USER, 1);
connectionGroupDefaultMaxConnectionsPerUser = environment.getProperty(MySQLGuacamoleProperties.MYSQL_DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER, 1);
}
// Return service configured for specified default limits

View File

@@ -107,5 +107,57 @@ public class MySQLGuacamoleProperties {
};
/**
* The maximum number of concurrent connections to allow to any one
* connection. Zero denotes unlimited.
*/
public static final IntegerGuacamoleProperty
MYSQL_DEFAULT_MAX_CONNECTIONS =
new IntegerGuacamoleProperty() {
@Override
public String getName() { return "mysql-default-max-connections"; }
};
/**
* The maximum number of concurrent connections to allow to any one
* connection group. Zero denotes unlimited.
*/
public static final IntegerGuacamoleProperty
MYSQL_DEFAULT_MAX_GROUP_CONNECTIONS =
new IntegerGuacamoleProperty() {
@Override
public String getName() { return "mysql-default-max-group-connections"; }
};
/**
* The maximum number of concurrent connections to allow to any one
* connection by an individual user. Zero denotes unlimited.
*/
public static final IntegerGuacamoleProperty
MYSQL_DEFAULT_MAX_CONNECTIONS_PER_USER =
new IntegerGuacamoleProperty() {
@Override
public String getName() { return "mysql-default-max-connections-per-user"; }
};
/**
* The maximum number of concurrent connections to allow to any one
* connection group by an individual user. Zero denotes
* unlimited.
*/
public static final IntegerGuacamoleProperty
MYSQL_DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER =
new IntegerGuacamoleProperty() {
@Override
public String getName() { return "mysql-default-max-group-connections-per-user"; }
};
}

View File

@@ -34,6 +34,8 @@ import org.glyptodon.guacamole.auth.jdbc.tunnel.GuacamoleTunnelService;
import org.glyptodon.guacamole.auth.jdbc.user.UserContextService;
import org.glyptodon.guacamole.environment.Environment;
import org.glyptodon.guacamole.environment.LocalEnvironment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Provides a PostgreSQL-based implementation of the AuthenticationProvider
@@ -44,6 +46,11 @@ import org.glyptodon.guacamole.environment.LocalEnvironment;
*/
public class PostgreSQLAuthenticationProvider implements AuthenticationProvider {
/**
* Logger for this class.
*/
private static final Logger logger = LoggerFactory.getLogger(PostgreSQLAuthenticationProvider.class);
/**
* Injector which will manage the object graph of this authentication
* provider.
@@ -75,28 +82,75 @@ public class PostgreSQLAuthenticationProvider implements AuthenticationProvider
int connectionGroupDefaultMaxConnectionsPerUser;
// Read legacy concurrency-related properties
boolean disallowSimultaneous = environment.getProperty(PostgreSQLGuacamoleProperties.POSTGRESQL_DISALLOW_SIMULTANEOUS_CONNECTIONS, false);
boolean disallowDuplicate = environment.getProperty(PostgreSQLGuacamoleProperties.POSTGRESQL_DISALLOW_DUPLICATE_CONNECTIONS, true);
// Legacy properties to not affect max connections per group
connectionGroupDefaultMaxConnections = 0;
Boolean disallowSimultaneous = environment.getProperty(PostgreSQLGuacamoleProperties.POSTGRESQL_DISALLOW_SIMULTANEOUS_CONNECTIONS);
Boolean disallowDuplicate = environment.getProperty(PostgreSQLGuacamoleProperties.POSTGRESQL_DISALLOW_DUPLICATE_CONNECTIONS);
// Legacy "simultaneous" property dictates only the maximum number of
// connections per connection
if (disallowSimultaneous)
connectionDefaultMaxConnections = 1;
else
connectionDefaultMaxConnections = 0;
if (disallowSimultaneous != null) {
// Translate legacy property
if (disallowSimultaneous) {
connectionDefaultMaxConnections = 1;
connectionGroupDefaultMaxConnections = 0;
}
else {
connectionDefaultMaxConnections = 0;
connectionGroupDefaultMaxConnections = 0;
}
// Warn of deprecation
logger.warn("The \"{}\" property is deprecated. Use \"{}\" and \"{}\" instead.",
PostgreSQLGuacamoleProperties.POSTGRESQL_DISALLOW_SIMULTANEOUS_CONNECTIONS.getName(),
PostgreSQLGuacamoleProperties.POSTGRESQL_DEFAULT_MAX_CONNECTIONS.getName(),
PostgreSQLGuacamoleProperties.POSTGRESQL_DEFAULT_MAX_GROUP_CONNECTIONS.getName());
// Inform of new equivalent
logger.info("To achieve the same result of setting \"{}\" to \"{}\", set \"{}\" to \"{}\" and \"{}\" to \"{}\".",
PostgreSQLGuacamoleProperties.POSTGRESQL_DISALLOW_SIMULTANEOUS_CONNECTIONS.getName(), disallowSimultaneous,
PostgreSQLGuacamoleProperties.POSTGRESQL_DEFAULT_MAX_CONNECTIONS.getName(), connectionDefaultMaxConnections,
PostgreSQLGuacamoleProperties.POSTGRESQL_DEFAULT_MAX_GROUP_CONNECTIONS.getName(), connectionGroupDefaultMaxConnections);
}
// If legacy property is not specified, use new property
else {
connectionDefaultMaxConnections = environment.getProperty(PostgreSQLGuacamoleProperties.POSTGRESQL_DEFAULT_MAX_CONNECTIONS, 0);
connectionGroupDefaultMaxConnections = environment.getProperty(PostgreSQLGuacamoleProperties.POSTGRESQL_DEFAULT_MAX_GROUP_CONNECTIONS, 0);
}
// Legacy "duplicate" property dictates whether connections and groups
// may be used concurrently only by different users
if (disallowDuplicate) {
connectionDefaultMaxConnectionsPerUser = 1;
connectionGroupDefaultMaxConnectionsPerUser = 1;
if (disallowDuplicate != null) {
// Translate legacy property
if (disallowDuplicate) {
connectionDefaultMaxConnectionsPerUser = 1;
connectionGroupDefaultMaxConnectionsPerUser = 1;
}
else {
connectionDefaultMaxConnectionsPerUser = 0;
connectionGroupDefaultMaxConnectionsPerUser = 0;
}
// Warn of deprecation
logger.warn("The \"{}\" property is deprecated. Use \"{}\" and \"{}\" instead.",
PostgreSQLGuacamoleProperties.POSTGRESQL_DISALLOW_DUPLICATE_CONNECTIONS.getName(),
PostgreSQLGuacamoleProperties.POSTGRESQL_DEFAULT_MAX_CONNECTIONS_PER_USER.getName(),
PostgreSQLGuacamoleProperties.POSTGRESQL_DEFAULT_MAX_GROUP_CONNECTIONS.getName());
// Inform of new equivalent
logger.info("To achieve the same result of setting \"{}\" to \"{}\", set \"{}\" to \"{}\" and \"{}\" to \"{}\".",
PostgreSQLGuacamoleProperties.POSTGRESQL_DISALLOW_DUPLICATE_CONNECTIONS.getName(), disallowDuplicate,
PostgreSQLGuacamoleProperties.POSTGRESQL_DEFAULT_MAX_CONNECTIONS_PER_USER.getName(), connectionDefaultMaxConnectionsPerUser,
PostgreSQLGuacamoleProperties.POSTGRESQL_DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER.getName(), connectionGroupDefaultMaxConnectionsPerUser);
}
// If legacy property is not specified, use new property
else {
connectionDefaultMaxConnectionsPerUser = 0;
connectionGroupDefaultMaxConnectionsPerUser = 0;
connectionDefaultMaxConnectionsPerUser = environment.getProperty(PostgreSQLGuacamoleProperties.POSTGRESQL_DEFAULT_MAX_CONNECTIONS_PER_USER, 1);
connectionGroupDefaultMaxConnectionsPerUser = environment.getProperty(PostgreSQLGuacamoleProperties.POSTGRESQL_DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER, 1);
}
// Return service configured for specified default limits

View File

@@ -124,4 +124,57 @@ public class PostgreSQLGuacamoleProperties {
};
/**
* The maximum number of concurrent connections to allow to any one
* connection. Zero denotes unlimited.
*/
public static final IntegerGuacamoleProperty
POSTGRESQL_DEFAULT_MAX_CONNECTIONS =
new IntegerGuacamoleProperty() {
@Override
public String getName() { return "postgresql-default-max-connections"; }
};
/**
* The maximum number of concurrent connections to allow to any one
* connection group. Zero denotes unlimited.
*/
public static final IntegerGuacamoleProperty
POSTGRESQL_DEFAULT_MAX_GROUP_CONNECTIONS =
new IntegerGuacamoleProperty() {
@Override
public String getName() { return "postgresql-default-max-group-connections"; }
};
/**
* The maximum number of concurrent connections to allow to any one
* connection by an individual user. Zero denotes unlimited.
*/
public static final IntegerGuacamoleProperty
POSTGRESQL_DEFAULT_MAX_CONNECTIONS_PER_USER =
new IntegerGuacamoleProperty() {
@Override
public String getName() { return "postgresql-default-max-connections-per-user"; }
};
/**
* The maximum number of concurrent connections to allow to any one
* connection group by an individual user. Zero denotes
* unlimited.
*/
public static final IntegerGuacamoleProperty
POSTGRESQL_DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER =
new IntegerGuacamoleProperty() {
@Override
public String getName() { return "postgresql-default-max-group-connections-per-user"; }
};
}