GUAC-1373: Partly refactored JDBC property loading.

This commit is contained in:
James Muehlner
2015-11-11 22:52:53 -08:00
committed by Michael Jumper
parent db2a00dcb8
commit 920ce67bee
8 changed files with 449 additions and 216 deletions

View File

@@ -62,7 +62,6 @@ import org.glyptodon.guacamole.auth.jdbc.activeconnection.ActiveConnectionPermis
import org.glyptodon.guacamole.auth.jdbc.activeconnection.ActiveConnectionPermissionSet;
import org.glyptodon.guacamole.auth.jdbc.activeconnection.ActiveConnectionService;
import org.glyptodon.guacamole.auth.jdbc.activeconnection.TrackedActiveConnection;
import org.glyptodon.guacamole.environment.Environment;
import org.glyptodon.guacamole.net.auth.AuthenticationProvider;
import org.mybatis.guice.MyBatisModule;
import org.mybatis.guice.datasource.builtin.PooledDataSourceProvider;
@@ -80,12 +79,7 @@ public class JDBCAuthenticationProviderModule extends MyBatisModule {
/**
* The environment of the Guacamole server.
*/
private final Environment environment;
/**
* The service to use to provide GuacamoleTunnels for each connection.
*/
private final GuacamoleTunnelService tunnelService;
private final JDBCEnvironment environment;
/**
* The AuthenticationProvider which is using this module to configure
@@ -104,16 +98,11 @@ public class JDBCAuthenticationProviderModule extends MyBatisModule {
*
* @param environment
* The environment to use to configure injected classes.
*
* @param tunnelService
* The tunnel service to use to provide tunnels sockets for connections.
*/
public JDBCAuthenticationProviderModule(AuthenticationProvider authProvider,
Environment environment,
GuacamoleTunnelService tunnelService) {
JDBCEnvironment environment) {
this.authProvider = authProvider;
this.environment = environment;
this.tunnelService = tunnelService;
}
@Override
@@ -140,7 +129,7 @@ public class JDBCAuthenticationProviderModule extends MyBatisModule {
bind(ActiveConnectionDirectory.class);
bind(ActiveConnectionPermissionSet.class);
bind(AuthenticationProvider.class).toInstance(authProvider);
bind(Environment.class).toInstance(environment);
bind(JDBCEnvironment.class).toInstance(environment);
bind(ConnectionDirectory.class);
bind(ConnectionGroupDirectory.class);
bind(ConnectionGroupPermissionSet.class);
@@ -169,9 +158,6 @@ public class JDBCAuthenticationProviderModule extends MyBatisModule {
bind(UserPermissionService.class);
bind(UserService.class);
// Bind provided tunnel service
bind(GuacamoleTunnelService.class).toInstance(tunnelService);
}
}

View File

@@ -0,0 +1,106 @@
/*
* Copyright (C) 2015 Glyptodon LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.glyptodon.guacamole.auth.jdbc;
import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.environment.LocalEnvironment;
/**
* A JDBC-specific implementation of Environment that defines generic properties
* intended for use within JDBC based authentication providers.
*
* @author James Muehlner
*/
public abstract class JDBCEnvironment extends LocalEnvironment {
/**
* Constructs a new JDBCEnvironment using an underlying LocalEnviroment to
* read properties from the file system.
*
* @throws GuacamoleException
* If an error occurs while setting up the underlying LocalEnvironment.
*/
public JDBCEnvironment() throws GuacamoleException {
super();
}
/**
* Returns the default maximum number of concurrent connections to allow to
* any one connection, unless specified differently on an individual
* connection. Zero denotes unlimited.
*
* @return
* The default maximum allowable number of concurrent connections
* to any connection.
*
* @throws GuacamoleException
* If an error occurs while retrieving the property.
*/
public abstract int getDefaultMaxConnections() throws GuacamoleException;
/**
* Returns the default maximum number of concurrent connections to allow to
* any one connection group, unless specified differently on an individual
* connection group. Zero denotes unlimited.
*
* @return
* The default maximum allowable number of concurrent connections
* to any connection group.
*
* @throws GuacamoleException
* If an error occurs while retrieving the property.
*/
public abstract int getDefaultMaxGroupConnections()
throws GuacamoleException;
/**
* Returns the default maximum number of concurrent connections to allow to
* any one connection by an individual user, unless specified differently on
* an individual connection. Zero denotes unlimited.
*
* @return
* The default maximum allowable number of concurrent connections to
* any connection by an individual user.
*
* @throws GuacamoleException
* If an error occurs while retrieving the property.
*/
public abstract int getDefaultMaxConnectionsPerUser()
throws GuacamoleException;
/**
* Returns the default maximum number of concurrent connections to allow to
* any one connection group by an individual user, unless specified
* differently on an individual connection group. Zero denotes unlimited.
*
* @return
* The default maximum allowable number of concurrent connections to
* any connection group by an individual user.
*
* @throws GuacamoleException
* If an error occurs while retrieving the property.
*/
public abstract int getDefaultMaxGroupConnectionsPerUser()
throws GuacamoleException;
}

View File

@@ -45,6 +45,7 @@ import org.glyptodon.guacamole.auth.jdbc.connection.ParameterModel;
import org.glyptodon.guacamole.auth.jdbc.user.UserModel;
import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.GuacamoleSecurityException;
import org.glyptodon.guacamole.auth.jdbc.JDBCEnvironment;
import org.glyptodon.guacamole.auth.jdbc.connection.ConnectionMapper;
import org.glyptodon.guacamole.environment.Environment;
import org.glyptodon.guacamole.net.GuacamoleSocket;
@@ -72,7 +73,7 @@ public abstract class AbstractGuacamoleTunnelService implements GuacamoleTunnelS
* The environment of the Guacamole server.
*/
@Inject
private Environment environment;
private JDBCEnvironment environment;
/**
* Mapper for accessing connections.

View File

@@ -23,6 +23,7 @@
package org.glyptodon.guacamole.auth.jdbc.tunnel;
import com.google.common.collect.ConcurrentHashMultiset;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.Arrays;
import java.util.Comparator;
@@ -32,6 +33,7 @@ import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
import org.glyptodon.guacamole.auth.jdbc.connection.ModeledConnection;
import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.GuacamoleResourceConflictException;
import org.glyptodon.guacamole.auth.jdbc.JDBCEnvironment;
import org.glyptodon.guacamole.auth.jdbc.connectiongroup.ModeledConnectionGroup;
@@ -46,6 +48,11 @@ import org.glyptodon.guacamole.auth.jdbc.connectiongroup.ModeledConnectionGroup;
@Singleton
public class ConfigurableGuacamoleTunnelService
extends AbstractGuacamoleTunnelService {
/**
* The configuration for the current JDBC environment.
*/
@Inject JDBCEnvironment jdbcEnvironment;
/**
* Set of all currently-active user/connection pairs (seats).
@@ -67,66 +74,6 @@ public class ConfigurableGuacamoleTunnelService
*/
private final ConcurrentHashMultiset<String> activeGroups = ConcurrentHashMultiset.<String>create();
/**
* The maximum number of connections allowed per connection by default, or
* zero if no default limit applies.
*/
private final int connectionDefaultMaxConnections;
/**
* The maximum number of connections a user may have to any one connection
* by default, or zero if no default limit applies.
*/
private final int connectionDefaultMaxConnectionsPerUser;
/**
* The maximum number of connections allowed per connection group by
* default, or zero if no default limit applies.
*/
private final int connectionGroupDefaultMaxConnections;
/**
* The maximum number of connections a user may have to any one connection
* group by default, or zero if no default limit applies.
*/
private final int connectionGroupDefaultMaxConnectionsPerUser;
/**
* Creates a new ConfigurableGuacamoleTunnelService which applies the given
* limitations when new connections are acquired.
*
* @param connectionDefaultMaxConnections
* The maximum number of connections allowed per connection by default,
* or zero if no default limit applies.
*
* @param connectionDefaultMaxConnectionsPerUser
* The maximum number of connections a user may have to any one
* connection by default, or zero if no default limit applies.
*
* @param connectionGroupDefaultMaxConnections
* The maximum number of connections allowed per connection group by
* default, or zero if no default limit applies.
*
* @param connectionGroupDefaultMaxConnectionsPerUser
* The maximum number of connections a user may have to any one
* connection group by default, or zero if no default limit applies.
*/
public ConfigurableGuacamoleTunnelService(
int connectionDefaultMaxConnections,
int connectionDefaultMaxConnectionsPerUser,
int connectionGroupDefaultMaxConnections,
int connectionGroupDefaultMaxConnectionsPerUser) {
// Set default connection limits
this.connectionDefaultMaxConnections = connectionDefaultMaxConnections;
this.connectionDefaultMaxConnectionsPerUser = connectionDefaultMaxConnectionsPerUser;
// Set default connection group limits
this.connectionGroupDefaultMaxConnections = connectionGroupDefaultMaxConnections;
this.connectionGroupDefaultMaxConnectionsPerUser = connectionGroupDefaultMaxConnectionsPerUser;
}
/**
* Attempts to add a single instance of the given value to the given
* multiset without exceeding the specified maximum number of values. If
@@ -203,12 +150,12 @@ public class ConfigurableGuacamoleTunnelService
// Determine per-user limits on this connection
Integer connectionMaxConnectionsPerUser = connection.getModel().getMaxConnectionsPerUser();
if (connectionMaxConnectionsPerUser == null)
connectionMaxConnectionsPerUser = connectionDefaultMaxConnectionsPerUser;
connectionMaxConnectionsPerUser = jdbcEnvironment.getDefaultMaxConnectionsPerUser();
// Determine overall limits on this connection
Integer connectionMaxConnections = connection.getModel().getMaxConnections();
if (connectionMaxConnections == null)
connectionMaxConnections = connectionDefaultMaxConnections;
connectionMaxConnections = jdbcEnvironment.getDefaultMaxConnections();
// Attempt to aquire connection according to per-user limits
Seat seat = new Seat(username, connection.getIdentifier());
@@ -255,12 +202,12 @@ public class ConfigurableGuacamoleTunnelService
// Determine per-user limits on this connection group
Integer connectionGroupMaxConnectionsPerUser = connectionGroup.getModel().getMaxConnectionsPerUser();
if (connectionGroupMaxConnectionsPerUser == null)
connectionGroupMaxConnectionsPerUser = connectionGroupDefaultMaxConnectionsPerUser;
connectionGroupMaxConnectionsPerUser = jdbcEnvironment.getDefaultMaxGroupConnectionsPerUser();
// Determine overall limits on this connection group
Integer connectionGroupMaxConnections = connectionGroup.getModel().getMaxConnections();
if (connectionGroupMaxConnections == null)
connectionGroupMaxConnections = connectionGroupDefaultMaxConnections;
connectionGroupMaxConnections = jdbcEnvironment.getDefaultMaxGroupConnections();
// Attempt to aquire connection group according to per-user limits
Seat seat = new Seat(username, connectionGroup.getIdentifier());