Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
GUAC-1373: Move property/attribute logic into ModeledConnection and M…
Browse files Browse the repository at this point in the history
…odeledConnectionGroup.
  • Loading branch information
mike-jumper committed Nov 12, 2015
1 parent a774686 commit 65393ad
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
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.auth.jdbc.tunnel.ConfigurableGuacamoleTunnelService;
import org.glyptodon.guacamole.auth.jdbc.tunnel.RestrictedGuacamoleTunnelService;
import org.glyptodon.guacamole.net.auth.AuthenticationProvider;
import org.mybatis.guice.MyBatisModule;
import org.mybatis.guice.datasource.builtin.PooledDataSourceProvider;
Expand Down Expand Up @@ -153,7 +153,7 @@ protected void initialize() {
bind(ConnectionGroupService.class);
bind(ConnectionPermissionService.class);
bind(ConnectionService.class);
bind(GuacamoleTunnelService.class).to(ConfigurableGuacamoleTunnelService.class);
bind(GuacamoleTunnelService.class).to(RestrictedGuacamoleTunnelService.class);
bind(PasswordEncryptionService.class).to(SHA256PasswordEncryptionService.class);
bind(SaltService.class).to(SecureRandomSaltService.class);
bind(SystemPermissionService.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Map;
import org.glyptodon.guacamole.auth.jdbc.tunnel.GuacamoleTunnelService;
import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.auth.jdbc.JDBCEnvironment;
import org.glyptodon.guacamole.auth.jdbc.base.ModeledGroupedDirectoryObject;
import org.glyptodon.guacamole.form.Field;
import org.glyptodon.guacamole.form.Form;
Expand Down Expand Up @@ -88,6 +89,12 @@ public class ModeledConnection extends ModeledGroupedDirectoryObject<ConnectionM
CONCURRENCY_LIMITS
));

/**
* The environment of the Guacamole server.
*/
@Inject
private JDBCEnvironment environment;

/**
* Service for managing connections.
*/
Expand Down Expand Up @@ -200,4 +207,53 @@ public void setAttributes(Map<String, String> attributes) {

}

/**
* Returns the maximum number of connections that should be allowed to this
* connection overall. If no limit applies, zero is returned.
*
* @return
* The maximum number of connections that should be allowed to this
* connection overall, or zero if no limit applies.
*
* @throws GuacamoleException
* If an error occurs while parsing the concurrency limit properties
* specified within guacamole.properties.
*/
public int getMaxConnections() throws GuacamoleException {

// Pull default from environment if connection limit is unset
Integer value = getModel().getMaxConnections();
if (value == null)
return environment.getDefaultMaxConnections();

// Otherwise use defined value
return value;

}

/**
* Returns the maximum number of connections that should be allowed to this
* connection for any individual user. If no limit applies, zero is
* returned.
*
* @return
* The maximum number of connections that should be allowed to this
* connection for any individual user, or zero if no limit applies.
*
* @throws GuacamoleException
* If an error occurs while parsing the concurrency limit properties
* specified within guacamole.properties.
*/
public int getMaxConnectionsPerUser() throws GuacamoleException {

// Pull default from environment if per-user connection limit is unset
Integer value = getModel().getMaxConnectionsPerUser();
if (value == null)
return environment.getDefaultMaxConnectionsPerUser();

// Otherwise use defined value
return value;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.glyptodon.guacamole.auth.jdbc.connection.ConnectionService;
import org.glyptodon.guacamole.auth.jdbc.tunnel.GuacamoleTunnelService;
import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.auth.jdbc.JDBCEnvironment;
import org.glyptodon.guacamole.auth.jdbc.base.ModeledGroupedDirectoryObject;
import org.glyptodon.guacamole.form.Field;
import org.glyptodon.guacamole.form.Form;
Expand Down Expand Up @@ -86,6 +87,12 @@ public class ModeledConnectionGroup extends ModeledGroupedDirectoryObject<Connec
CONCURRENCY_LIMITS
));

/**
* The environment of the Guacamole server.
*/
@Inject
private JDBCEnvironment environment;

/**
* Service for managing connections.
*/
Expand Down Expand Up @@ -186,4 +193,55 @@ public void setAttributes(Map<String, String> attributes) {

}

/**
* Returns the maximum number of connections that should be allowed to this
* connection group overall. If no limit applies, zero is returned.
*
* @return
* The maximum number of connections that should be allowed to this
* connection group overall, or zero if no limit applies.
*
* @throws GuacamoleException
* If an error occurs while parsing the concurrency limit properties
* specified within guacamole.properties.
*/
public int getMaxConnections() throws GuacamoleException {

// Pull default from environment if connection limit is unset
Integer value = getModel().getMaxConnections();
if (value == null)
return environment.getDefaultMaxGroupConnections();

// Otherwise use defined value
return value;

}

/**
* Returns the maximum number of connections that should be allowed to this
* connection group for any individual user. If no limit applies, zero is
* returned.
*
* @return
* The maximum number of connections that should be allowed to this
* connection group for any individual user, or zero if no limit
* applies.
*
* @throws GuacamoleException
* If an error occurs while parsing the concurrency limit properties
* specified within guacamole.properties.
*/
public int getMaxConnectionsPerUser() throws GuacamoleException {

// Pull default from environment if per-user connection limit is unset
Integer value = getModel().getMaxConnectionsPerUser();
if (value == null)
return environment.getDefaultMaxGroupConnectionsPerUser();

// Otherwise use defined value
return value;

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
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;
Expand All @@ -33,7 +32,6 @@
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;


Expand All @@ -46,14 +44,8 @@
* @author Michael Jumper
*/
@Singleton
public class ConfigurableGuacamoleTunnelService
public class RestrictedGuacamoleTunnelService
extends AbstractGuacamoleTunnelService {

/**
* The Guacamole server environment.
*/
@Inject
private JDBCEnvironment environment;

/**
* Set of all currently-active user/connection pairs (seats).
Expand Down Expand Up @@ -148,23 +140,14 @@ public int compare(ModeledConnection a, ModeledConnection b) {
// 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 = environment.getDefaultMaxConnectionsPerUser();

// Determine overall limits on this connection
Integer connectionMaxConnections = connection.getModel().getMaxConnections();
if (connectionMaxConnections == null)
connectionMaxConnections = environment.getDefaultMaxConnections();

// Attempt to aquire connection according to per-user limits
Seat seat = new Seat(username, connection.getIdentifier());
if (tryAdd(activeSeats, seat, connectionMaxConnectionsPerUser)) {
if (tryAdd(activeSeats, seat,
connection.getMaxConnectionsPerUser())) {

// Attempt to aquire connection according to overall limits
if (tryAdd(activeConnections, connection.getIdentifier(),
connectionMaxConnections))
connection.getMaxConnections()))
return connection;

// Acquire failed - retry with next connection
Expand Down Expand Up @@ -200,24 +183,14 @@ protected void acquire(AuthenticatedUser user,
// Get username
String username = user.getUser().getIdentifier();

// Determine per-user limits on this connection group
Integer connectionGroupMaxConnectionsPerUser = connectionGroup.getModel().getMaxConnectionsPerUser();
if (connectionGroupMaxConnectionsPerUser == null)
connectionGroupMaxConnectionsPerUser = environment.getDefaultMaxGroupConnectionsPerUser();

// Determine overall limits on this connection group
Integer connectionGroupMaxConnections = connectionGroup.getModel().getMaxConnections();
if (connectionGroupMaxConnections == null)
connectionGroupMaxConnections = environment.getDefaultMaxGroupConnections();

// Attempt to aquire connection group according to per-user limits
Seat seat = new Seat(username, connectionGroup.getIdentifier());
if (tryAdd(activeGroupSeats, seat,
connectionGroupMaxConnectionsPerUser)) {
connectionGroup.getMaxConnectionsPerUser())) {

// Attempt to aquire connection group according to overall limits
if (tryAdd(activeGroups, connectionGroup.getIdentifier(),
connectionGroupMaxConnections))
connectionGroup.getMaxConnections()))
return;

// Acquire failed
Expand Down

0 comments on commit 65393ad

Please sign in to comment.