diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/ActiveConnectionMap.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/ActiveConnectionMap.java index b0ed80c67..5c06f5019 100644 --- a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/ActiveConnectionMap.java +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/ActiveConnectionMap.java @@ -139,7 +139,8 @@ public class ActiveConnectionMap { * Returns the ID of the connection with the lowest number of current * active users, if found. * - * @param connectionIDs + * @param connectionIDs The subset of connection IDs to find the least + * used connection within. * * @return The ID of the connection with the lowest number of current * active users, if found. @@ -149,28 +150,28 @@ public class ActiveConnectionMap { if(connectionIDs.isEmpty()) return null; - List groupConnections = - new ArrayList(); + int minUserCount = Integer.MAX_VALUE; + Integer minConnectionID = null; for(Integer connectionID : connectionIDs) { Connection connection = activeConnectionMap.get(connectionID); - // Create the Connection if it does not exist + /* + * If the connection is not found in the map, it has not been used, + * and therefore will be count 0. + */ if(connection == null) { - connection = new Connection(connectionID); - activeConnectionMap.put(connectionID, connection); + minUserCount = 0; + minConnectionID = connectionID; + } + // If this is the least active connection + else if(connection.getCurrentUserCount() < minUserCount) { + minUserCount = connection.getCurrentUserCount(); + minConnectionID = connection.getConnectionID(); } - - groupConnections.add(connection); } - // Sort the Connections into decending order - Collections.sort(groupConnections); - - if(!groupConnections.isEmpty()) - return groupConnections.get(0).getConnectionID(); - - return null; + return minConnectionID; } /** diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/ConnectionDirectory.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/ConnectionDirectory.java index de7f71ec3..bb85159db 100644 --- a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/ConnectionDirectory.java +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/ConnectionDirectory.java @@ -291,9 +291,14 @@ public class ConnectionDirectory implements Directory{ } @Override - public void move(String identifier, String groupIdentifier) + public void move(String identifier, Directory directory) throws GuacamoleException { - + + if(!(directory instanceof ConnectionDirectory)) + throw new GuacamoleException("Directory not from database"); + + int toConnectionGroupID = ((ConnectionDirectory)directory).parentID; + // Get connection MySQLConnection mySQLConnection = connectionService.retrieveConnection(identifier, user_id); @@ -314,15 +319,6 @@ public class ConnectionDirectory implements Directory{ permissionCheckService.verifyConnectionGroupAccess(this.user_id, mySQLConnection.getParentID(), MySQLConstants.CONNECTION_GROUP_UPDATE); - Integer toConnectionGroupID; - if(groupIdentifier.equals(MySQLConstants.CONNECTION_GROUP_ROOT_IDENTIFIER)) - toConnectionGroupID = null; - try { - toConnectionGroupID = Integer.valueOf(groupIdentifier); - } catch(NumberFormatException e) { - throw new GuacamoleException("Invalid connection group identifier."); - } - // Verify permission to use the to connection group for organizational purposes permissionCheckService.verifyConnectionGroupUsageAccess (toConnectionGroupID, user_id, MySQLConstants.CONNECTION_GROUP_ORGANIZATIONAL); diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/ConnectionGroupDirectory.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/ConnectionGroupDirectory.java index 0cd4e39ee..25e821b40 100644 --- a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/ConnectionGroupDirectory.java +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/ConnectionGroupDirectory.java @@ -63,7 +63,7 @@ public class ConnectionGroupDirectory implements Directory directory) throws GuacamoleException { + + if(!(directory instanceof ConnectionGroupDirectory)) + throw new GuacamoleException("Directory not from database"); + + int toConnectionGroupID = ((ConnectionGroupDirectory)directory).parentID; // Get connection MySQLConnectionGroup mySQLConnectionGroup = @@ -258,15 +263,6 @@ public class ConnectionGroupDirectory implements Directory { +public class UserDirectory implements Directory { /** * The ID of the user who this user directory belongs to. @@ -712,7 +713,7 @@ public class UserDirectory implements Directory groupIdentifier) throws GuacamoleException { throw new GuacamoleSecurityException("Permission denied."); } diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/Directory.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/Directory.java index 4b472bdc8..910a096d1 100644 --- a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/Directory.java +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/Directory.java @@ -115,16 +115,15 @@ public interface Directory { void remove(IdentifierType identifier) throws GuacamoleException; /** - * Moves the object with the given identifier to the group with the given - * group identifier. + * Moves the object with the given identifier to the given directory. * * @param identifier The identifier of the object to remove. - * @param groupIdentifier The identifier of the group to move the object to. + * @param directory The directory to move the object to. * * @throws GuacamoleException If an error occurs while moving the object, * or if moving object is not allowed. */ - void move(IdentifierType identifier, IdentifierType groupIdentifier) + void move(IdentifierType identifier, Directory directory) throws GuacamoleException; } diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/UserContext.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/UserContext.java index 1c54909ab..20f4e72d9 100644 --- a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/UserContext.java +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/UserContext.java @@ -81,6 +81,6 @@ public interface UserContext { * @throws GuacamoleException If an error occurs while creating the * Directory. */ - ConnectionGroup getConnectionGroup() throws GuacamoleException; + ConnectionGroup getRootConnectionGroup() throws GuacamoleException; } diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionDirectory.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionDirectory.java index 392cd51b1..9905c97c0 100644 --- a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionDirectory.java +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionDirectory.java @@ -110,7 +110,7 @@ public class SimpleConnectionDirectory } @Override - public void move(String identifier, String groupIdentifier) + public void move(String identifier, Directory directory) throws GuacamoleException { throw new GuacamoleSecurityException("Permission denied."); } diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionGroupDirectory.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionGroupDirectory.java index b6bb4076a..003911d9c 100644 --- a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionGroupDirectory.java +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionGroupDirectory.java @@ -87,7 +87,7 @@ public class SimpleConnectionGroupDirectory } @Override - public void move(String identifier, String groupIdentifier) + public void move(String identifier, Directory directory) throws GuacamoleException { throw new GuacamoleSecurityException("Permission denied."); } diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserContext.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserContext.java index 493d1bfba..08ec1151d 100644 --- a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserContext.java +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserContext.java @@ -124,7 +124,7 @@ public class SimpleUserContext implements UserContext { } @Override - public ConnectionGroup getConnectionGroup() throws GuacamoleException { + public ConnectionGroup getRootConnectionGroup() throws GuacamoleException { return connectionGroup; } diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserDirectory.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserDirectory.java index 80fea37c5..d1c71b68b 100644 --- a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserDirectory.java +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserDirectory.java @@ -101,7 +101,7 @@ public class SimpleUserDirectory implements Directory { } @Override - public void move(String identifier, String groupIdentifier) + public void move(String identifier, Directory directory) throws GuacamoleException { throw new GuacamoleSecurityException("Permission denied."); }