Ticket #263: Made sure that we can't create connection group cycles.

This commit is contained in:
James Muehlner
2013-08-15 09:49:38 -07:00
parent 5fb3352d1d
commit e55131c3c5

View File

@@ -87,10 +87,10 @@ public class ConnectionGroupDirectory implements Directory<String, ConnectionGro
private ConnectionGroupPermissionMapper connectionGroupPermissionDAO; private ConnectionGroupPermissionMapper connectionGroupPermissionDAO;
/** /**
* Set the user and parentID for this directory. * Set the user and relativeParentID for this directory.
* *
* @param user_id The ID of the user owning this connection group directory. * @param user_id The ID of the user owning this connection group directory.
* @param parentID The ID of the parent connection group. * @param relativeParentID The ID of the parent connection group.
*/ */
public void init(int user_id, Integer parentID) { public void init(int user_id, Integer parentID) {
this.parentID = parentID; this.parentID = parentID;
@@ -243,17 +243,20 @@ public class ConnectionGroupDirectory implements Directory<String, ConnectionGro
public void move(String identifier, Directory<String, ConnectionGroup> directory) public void move(String identifier, Directory<String, ConnectionGroup> directory)
throws GuacamoleException { throws GuacamoleException {
if(MySQLConstants.CONNECTION_GROUP_ROOT_IDENTIFIER.equals(identifier))
throw new GuacamoleException("The root connection group cannot be moved.");
if(!(directory instanceof ConnectionGroupDirectory)) if(!(directory instanceof ConnectionGroupDirectory))
throw new GuacamoleException("Directory not from database"); throw new GuacamoleException("Directory not from database");
int toConnectionGroupID = ((ConnectionGroupDirectory)directory).parentID; int toConnectionGroupID = ((ConnectionGroupDirectory)directory).parentID;
// Get connection // Get connection group
MySQLConnectionGroup mySQLConnectionGroup = MySQLConnectionGroup mySQLConnectionGroup =
connectionGroupService.retrieveConnectionGroup(identifier, user_id); connectionGroupService.retrieveConnectionGroup(identifier, user_id);
if(mySQLConnectionGroup == null) if(mySQLConnectionGroup == null)
throw new GuacamoleException("Connection not found."); throw new GuacamoleException("Connection group not found.");
// Verify permission to update the connection // Verify permission to update the connection
permissionCheckService.verifyConnectionAccess(this.user_id, permissionCheckService.verifyConnectionAccess(this.user_id,
@@ -283,6 +286,18 @@ public class ConnectionGroupDirectory implements Directory<String, ConnectionGro
if(previousConnectionGroup != null) if(previousConnectionGroup != null)
throw new GuacamoleClientException("That connection group name is already in use."); throw new GuacamoleClientException("That connection group name is already in use.");
// Verify that moving this connectionGroup would not cause a cycle
Integer relativeParentID = toConnectionGroupID;
while(relativeParentID != null) {
if(relativeParentID == mySQLConnectionGroup.getConnectionGroupID())
throw new GuacamoleException("Connection group cycle detected.");
MySQLConnectionGroup relativeParentGroup = connectionGroupService.
retrieveConnectionGroup(relativeParentID, user_id);
relativeParentID = relativeParentGroup.getParentID();
}
// Update the connection // Update the connection
mySQLConnectionGroup.setParentID(toConnectionGroupID); mySQLConnectionGroup.setParentID(toConnectionGroupID);
connectionGroupService.updateConnectionGroup(mySQLConnectionGroup); connectionGroupService.updateConnectionGroup(mySQLConnectionGroup);