diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnection.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnection.java index dc68cfcb4..b55e906b1 100644 --- a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnection.java +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnection.java @@ -60,6 +60,11 @@ public class MySQLConnection extends AbstractConnection { */ private Integer connectionID; + /** + * The ID of the parent connection for this connection group. + */ + private Integer parentID; + /** * The ID of the user who queried or created this connection. */ @@ -98,20 +103,38 @@ public class MySQLConnection extends AbstractConnection { this.connectionID = connectionID; } + /** + * Get the ID of the parent connection group for this connection, if any. + * @return The ID of the parent connection group for this connection, if any. + */ + public Integer getParentID() { + return parentID; + } + + /** + * Sets the ID of the parent connection group for this connection. + * @param connectionID The ID of the parent connection group for this connection. + */ + public void setParentID(Integer parentID) { + this.parentID = parentID; + } + /** * Initialize from explicit values. * * @param connectionID The ID of the associated database record, if any. + * @param parentID The D of the parent connection group for this connection, if any. * @param identifier The unique identifier associated with this connection. * @param config The GuacamoleConfiguration associated with this connection. * @param history All ConnectionRecords associated with this connection. * @param userID The IID of the user who queried this connection. */ - public void init(Integer connectionID, String identifier, + public void init(Integer connectionID, Integer parentID, String identifier, GuacamoleConfiguration config, List history, int userID) { this.connectionID = connectionID; + this.parentID = parentID; setIdentifier(identifier); setConfiguration(config); this.history.addAll(history); diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnectionGroup.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnectionGroup.java index cef7f514a..42629bb4b 100644 --- a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnectionGroup.java +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnectionGroup.java @@ -45,6 +45,8 @@ import net.sourceforge.guacamole.net.auth.Connection; import net.sourceforge.guacamole.net.auth.ConnectionGroup; import net.sourceforge.guacamole.net.auth.Directory; import net.sourceforge.guacamole.net.auth.mysql.service.ConnectionGroupService; +import net.sourceforge.guacamole.net.auth.mysql.service.ConnectionService; +import net.sourceforge.guacamole.net.auth.mysql.service.PermissionCheckService; import net.sourceforge.guacamole.protocol.GuacamoleClientInformation; /** @@ -58,6 +60,11 @@ public class MySQLConnectionGroup extends AbstractConnectionGroup { */ private Integer connectionGroupID; + /** + * The ID of the parent connection group for this connection group. + */ + private Integer parentID; + /** * The ID of the user who queried or created this connection group. */ @@ -73,12 +80,24 @@ public class MySQLConnectionGroup extends AbstractConnectionGroup { */ private Directory connectionGroupDirectory = null; + /** + * Service managing connections. + */ + @Inject + private ConnectionService connectionService; + /** * Service managing connection groups. */ @Inject private ConnectionGroupService connectionGroupService; + /** + * Service for checking permissions. + */ + @Inject + private PermissionCheckService permissionCheckService; + /** * Create a default, empty connection group. */ @@ -101,15 +120,33 @@ public class MySQLConnectionGroup extends AbstractConnectionGroup { this.connectionGroupID = connectionGroupID; } + /** + * Get the ID of the parent connection group for this connection group, if any. + * @return The ID of the parent connection group for this connection group, if any. + */ + public Integer getParentID() { + return parentID; + } + + /** + * Sets the ID of the parent connection group for this connection group. + * @param connectionID The ID of the parent connection group for this connection group. + */ + public void setParentID(Integer parentID) { + this.parentID = parentID; + } + /** * Initialize from explicit values. * * @param connectionGroupID The ID of the associated database record, if any. + * @param parentID The D of the parent connection group for this connection group, if any. * @param identifier The unique identifier associated with this connection group. * @param userID The IID of the user who queried this connection. */ - public void init(Integer connectionGroupID, String identifier, int userID) { + public void init(Integer connectionGroupID, Integer parentID, String identifier, int userID) { this.connectionGroupID = connectionGroupID; + this.parentID = parentID; setIdentifier(identifier); this.userID = userID; } diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionGroupService.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionGroupService.java index a44ab06e2..5ac9e2ff3 100644 --- a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionGroupService.java +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionGroupService.java @@ -51,8 +51,6 @@ import java.util.Set; import net.sourceforge.guacamole.net.GuacamoleSocket; import net.sourceforge.guacamole.net.auth.mysql.MySQLConnectionGroup; import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionGroupMapper; -import net.sourceforge.guacamole.net.auth.mysql.model.Connection; -import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionExample; import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionGroup; import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionGroupExample; import net.sourceforge.guacamole.protocol.GuacamoleClientInformation; @@ -65,18 +63,6 @@ import net.sourceforge.guacamole.protocol.GuacamoleClientInformation; */ public class ConnectionGroupService { - /** - * Service managing users. - */ - @Inject - private UserService userService; - - /** - * Service managing connections. - */ - @Inject - private ConnectionService connectionService; - /** * DAO for accessing connection groups. */ @@ -88,15 +74,40 @@ public class ConnectionGroupService { */ @Inject private Provider mysqlConnectionGroupProvider; + + + /** + * Retrieves all connection groups with a given parent connection group ID. + * + * @param parentID The parent ID of the connection groups. + * @param userID The ID of the user who queried these connection groups. + * @return All connection groups with a given parent connection group ID. + */ + public Collection getConnectionGroupsByParentConnectionGroup(Integer parentID, int userID) { + + // A null parentID indicates the root-level group + ConnectionGroupExample example = new ConnectionGroupExample(); + if(parentID != null) + example.createCriteria().andParent_group_idEqualTo(parentID); + else + example.createCriteria().andParent_group_idIsNull(); + + // Get all connections with the given parent ID + List connectionGroups = connectionGroupDAO.selectByExample(example); + + List mySQLConnectionGroups = new ArrayList(); + + for(ConnectionGroup connectionGroup : connectionGroups) { + mySQLConnectionGroups.add(toMySQLConnectionGroup(connectionGroup, userID)); + } + + return mySQLConnectionGroups; + } public GuacamoleSocket connect(MySQLConnectionGroup group, GuacamoleClientInformation info, int userID) { throw new UnsupportedOperationException("Not yet implemented"); } - - //public Collection getConnectionGroupConnections() - - /** * Retrieves a map of all connection group names for the given IDs. @@ -148,6 +159,31 @@ public class ConnectionGroupService { } + /** + * Convert the given database-retrieved Connection into a MySQLConnection. + * The parameters of the given connection will be read and added to the + * MySQLConnection in the process. + * + * @param connection The connection to convert. + * @param userID The user who queried this connection. + * @return A new MySQLConnection containing all data associated with the + * specified connection. + */ + private MySQLConnectionGroup toMySQLConnectionGroup(ConnectionGroup connectionGroup, int userID) { + + // Create new MySQLConnection from retrieved data + MySQLConnectionGroup mySQLConnectionGroup = mysqlConnectionGroupProvider.get(); + mySQLConnectionGroup.init( + connectionGroup.getConnection_group_id(), + connectionGroup.getParent_group_id(), + connectionGroup.getConnection_group_name(), + userID + ); + + return mySQLConnectionGroup; + + } + /** * Get the connection group IDs of all the connection groups defined in the system. * diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionService.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionService.java index 8ae351fdb..5af33c28e 100644 --- a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionService.java +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionService.java @@ -172,6 +172,34 @@ public class ConnectionService { // Otherwise, return found connection return toMySQLConnection(connection, userID); } + + /** + * Retrieves all connections with a given parent connection group ID. + * + * @param parentID The parent ID of the connections. + * @param userID The ID of the user who queried these connections. + * @return All connections with a given parent connection group ID. + */ + public Collection getConnectionsByParentConnectionGroup(Integer parentID, int userID) { + + // A null parentID indicates the root-level group + ConnectionExample example = new ConnectionExample(); + if(parentID != null) + example.createCriteria().andConnection_group_idEqualTo(parentID); + else + example.createCriteria().andConnection_group_idIsNull(); + + // Get all connections with the given parent ID + List connections = connectionDAO.selectByExample(example); + + List mySQLConnections = new ArrayList(); + + for(Connection connection : connections) { + mySQLConnections.add(toMySQLConnection(connection, userID)); + } + + return mySQLConnections; + } /** * Retrieves a translation map of connection names to their corresponding @@ -267,6 +295,7 @@ public class ConnectionService { MySQLConnection mySQLConnection = mySQLConnectionProvider.get(); mySQLConnection.init( connection.getConnection_id(), + connection.getConnection_group_id(), connection.getConnection_name(), config, retrieveHistory(connection.getConnection_id()),