From 622f0852e2b0ffc7f9e9b6b6d75db0230dc263bc Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 21 Aug 2015 12:57:03 -0700 Subject: [PATCH] GUAC-830: Add concurrency limitations to connection and connection group model objects. --- .../auth/jdbc/connection/ConnectionModel.java | 68 +++++++++++++++++- .../connectiongroup/ConnectionGroupModel.java | 70 ++++++++++++++++++- .../ConfigurableGuacamoleTunnelService.java | 29 ++++++-- 3 files changed, 160 insertions(+), 7 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connection/ConnectionModel.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connection/ConnectionModel.java index 5b3552fe9..f272f43c1 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connection/ConnectionModel.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connection/ConnectionModel.java @@ -41,7 +41,21 @@ public class ConnectionModel extends GroupedObjectModel { * The name of the protocol to use when connecting to this connection. */ private String protocol; - + + /** + * The maximum number of connections that can be established to this + * connection concurrently, zero if no restriction applies, or null if the + * default restrictions should be applied. + */ + private Integer maxConnections; + + /** + * The maximum number of connections that can be established to this + * connection concurrently by any one user, zero if no restriction applies, + * or null if the default restrictions should be applied. + */ + private Integer maxConnectionsPerUser; + /** * Creates a new, empty connection. */ @@ -89,6 +103,58 @@ public class ConnectionModel extends GroupedObjectModel { this.protocol = protocol; } + /** + * Returns the maximum number of connections that can be established to + * this connection concurrently. + * + * @return + * The maximum number of connections that can be established to this + * connection concurrently, zero if no restriction applies, or null if + * the default restrictions should be applied. + */ + public Integer getMaxConnections() { + return maxConnections; + } + + /** + * Sets the maximum number of connections that can be established to this + * connection concurrently. + * + * @param maxConnections + * The maximum number of connections that can be established to this + * connection concurrently, zero if no restriction applies, or null if + * the default restrictions should be applied. + */ + public void setMaxConnections(Integer maxConnections) { + this.maxConnections = maxConnections; + } + + /** + * Returns the maximum number of connections that can be established to + * this connection concurrently by any one user. + * + * @return + * The maximum number of connections that can be established to this + * connection concurrently by any one user, zero if no restriction + * applies, or null if the default restrictions should be applied. + */ + public Integer getMaxConnectionsPerUser() { + return maxConnectionsPerUser; + } + + /** + * Sets the maximum number of connections that can be established to this + * connection concurrently by any one user. + * + * @param maxConnectionsPerUser + * The maximum number of connections that can be established to this + * connection concurrently by any one user, zero if no restriction + * applies, or null if the default restrictions should be applied. + */ + public void setMaxConnectionsPerUser(Integer maxConnectionsPerUser) { + this.maxConnectionsPerUser = maxConnectionsPerUser; + } + @Override public String getIdentifier() { diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connectiongroup/ConnectionGroupModel.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connectiongroup/ConnectionGroupModel.java index def543ffc..161f133ed 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connectiongroup/ConnectionGroupModel.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/connectiongroup/ConnectionGroupModel.java @@ -42,7 +42,21 @@ public class ConnectionGroupModel extends GroupedObjectModel { * The type of this connection group, such as organizational or balancing. */ private ConnectionGroup.Type type; - + + /** + * The maximum number of connections that can be established to this + * connection group concurrently, zero if no restriction applies, or + * null if the default restrictions should be applied. + */ + private Integer maxConnections; + + /** + * The maximum number of connections that can be established to this + * connection group concurrently by any one user, zero if no restriction + * applies, or null if the default restrictions should be applied. + */ + private Integer maxConnectionsPerUser; + /** * Creates a new, empty connection group. */ @@ -91,6 +105,60 @@ public class ConnectionGroupModel extends GroupedObjectModel { this.type = type; } + /** + * Returns the maximum number of connections that can be established to + * this connection group concurrently. + * + * @return + * The maximum number of connections that can be established to this + * connection group concurrently, zero if no restriction applies, or + * null if the default restrictions should be applied. + */ + public Integer getMaxConnections() { + return maxConnections; + } + + /** + * Sets the maximum number of connections that can be established to this + * connection group concurrently. + * + * @param maxConnections + * The maximum number of connections that can be established to this + * connection group concurrently, zero if no restriction applies, or + * null if the default restrictions should be applied. + */ + public void setMaxConnections(Integer maxConnections) { + this.maxConnections = maxConnections; + } + + /** + * Returns the maximum number of connections that can be established to + * this connection group concurrently by any one user. + * + * @return + * The maximum number of connections that can be established to this + * connection group concurrently by any one user, zero if no + * restriction applies, or null if the default restrictions should be + * applied. + */ + public Integer getMaxConnectionsPerUser() { + return maxConnectionsPerUser; + } + + /** + * Sets the maximum number of connections that can be established to this + * connection group concurrently by any one user. + * + * @param maxConnectionsPerUser + * The maximum number of connections that can be established to this + * connection group concurrently by any one user, zero if no + * restriction applies, or null if the default restrictions should be + * applied. + */ + public void setMaxConnectionsPerUser(Integer maxConnectionsPerUser) { + this.maxConnectionsPerUser = maxConnectionsPerUser; + } + @Override public String getIdentifier() { diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/tunnel/ConfigurableGuacamoleTunnelService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/tunnel/ConfigurableGuacamoleTunnelService.java index a3f5b6d0e..37e29d183 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/tunnel/ConfigurableGuacamoleTunnelService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/tunnel/ConfigurableGuacamoleTunnelService.java @@ -200,14 +200,23 @@ public class ConfigurableGuacamoleTunnelService // Return the first unreserved connection for (ModeledConnection connection : sortedConnections) { + // Determine per-user limits on this connection + Integer connectionMaxConnectionsPerUser = connection.getModel().getMaxConnectionsPerUser(); + if (connectionMaxConnectionsPerUser == null) + connectionMaxConnectionsPerUser = connectionDefaultMaxConnectionsPerUser; + + // Determine overall limits on this connection + Integer connectionMaxConnections = connection.getModel().getMaxConnections(); + if (connectionMaxConnections == null) + connectionMaxConnections = connectionDefaultMaxConnections; + // Attempt to aquire connection according to per-user limits Seat seat = new Seat(username, connection.getIdentifier()); - if (tryAdd(activeSeats, seat, - connectionDefaultMaxConnectionsPerUser)) { + if (tryAdd(activeSeats, seat, connectionMaxConnectionsPerUser)) { // Attempt to aquire connection according to overall limits if (tryAdd(activeConnections, connection.getIdentifier(), - connectionDefaultMaxConnections)) + connectionMaxConnections)) return connection; // Acquire failed - retry with next connection @@ -243,14 +252,24 @@ public class ConfigurableGuacamoleTunnelService // Get username String username = user.getUser().getIdentifier(); + // Determine per-user limits on this connection group + Integer connectionGroupMaxConnectionsPerUser = connectionGroup.getModel().getMaxConnectionsPerUser(); + if (connectionGroupMaxConnectionsPerUser == null) + connectionGroupMaxConnectionsPerUser = connectionGroupDefaultMaxConnectionsPerUser; + + // Determine overall limits on this connection group + Integer connectionGroupMaxConnections = connectionGroup.getModel().getMaxConnections(); + if (connectionGroupMaxConnections == null) + connectionGroupMaxConnections = connectionGroupDefaultMaxConnections; + // Attempt to aquire connection group according to per-user limits Seat seat = new Seat(username, connectionGroup.getIdentifier()); if (tryAdd(activeGroupSeats, seat, - connectionGroupDefaultMaxConnectionsPerUser)) { + connectionGroupMaxConnectionsPerUser)) { // Attempt to aquire connection group according to overall limits if (tryAdd(activeGroups, connectionGroup.getIdentifier(), - connectionGroupDefaultMaxConnections)) + connectionGroupMaxConnections)) return; // Acquire failed