Ticket #263: Fixed bugs around not being able to add connections or groups into the root group.

This commit is contained in:
James Muehlner
2013-08-14 16:45:30 -07:00
parent 28dbd67da6
commit 0abd544165
3 changed files with 56 additions and 10 deletions

View File

@@ -42,11 +42,13 @@ import java.util.Set;
import net.sourceforge.guacamole.GuacamoleClientException;
import net.sourceforge.guacamole.GuacamoleException;
import net.sourceforge.guacamole.net.auth.ConnectionGroup;
import net.sourceforge.guacamole.net.auth.ConnectionGroup.Type;
import net.sourceforge.guacamole.net.auth.Directory;
import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionGroupPermissionMapper;
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionGroupPermissionKey;
import net.sourceforge.guacamole.net.auth.mysql.service.ConnectionGroupService;
import net.sourceforge.guacamole.net.auth.mysql.service.PermissionCheckService;
import net.sourceforge.guacamole.net.auth.permission.ObjectPermission;
import org.mybatis.guice.transactional.Transactional;
/**
@@ -142,6 +144,10 @@ public class ConnectionGroupDirectory implements Directory<String, ConnectionGro
if(name.isEmpty())
throw new GuacamoleClientException("The connection group name cannot be blank.");
Type type = object.getType();
String mySQLType = MySQLConstants.getConnectionGroupTypeConstant(type);
// Verify permission to create
permissionCheckService.verifySystemAccess(this.user_id,
MySQLConstants.SYSTEM_CONNECTION_GROUP_CREATE);
@@ -162,7 +168,7 @@ public class ConnectionGroupDirectory implements Directory<String, ConnectionGro
// Create connection group
MySQLConnectionGroup connectionGroup = connectionGroupService
.createConnectionGroup(name, user_id, parentID);
.createConnectionGroup(name, user_id, parentID, mySQLType);
// Finally, give the current user full access to the newly created
// connection group.

View File

@@ -1,6 +1,7 @@
package net.sourceforge.guacamole.net.auth.mysql;
import net.sourceforge.guacamole.net.auth.ConnectionGroup;
import net.sourceforge.guacamole.net.auth.permission.ObjectPermission;
import net.sourceforge.guacamole.net.auth.permission.SystemPermission;
@@ -231,6 +232,27 @@ public final class MySQLConstants {
}
/**
* Given the type of a connection group, returns the MySQL constant
* representing that type.
*
* @param type The connection group type to look up.
* @return The MySQL constant corresponding to the given type.
*/
public static String getConnectionGroupTypeConstant(ConnectionGroup.Type type) {
// Convert permission type to MySQL constant
switch (type) {
case ORGANIZATIONAL: return CONNECTION_GROUP_ORGANIZATIONAL;
case BALANCING: return CONNECTION_GROUP_BALANCING;
}
// If we get here, permission support was not properly implemented
throw new UnsupportedOperationException(
"Unsupported connection group type: " + type);
}
/**
* Given the type of a permission affecting the system, returns the MySQL
* constant representing that permission type.

View File

@@ -134,15 +134,19 @@ public class ConnectionGroupService {
* @return The connection group having the given unique identifier,
* or null if no such connection group was found.
*/
public MySQLConnectionGroup retrieveConnectionGroup(String uniqueIdentifier, int userID) {
public MySQLConnectionGroup retrieveConnectionGroup(String uniqueIdentifier,
int userID) throws GuacamoleException {
// The unique identifier for a MySQLConnectionGroup is the database ID
int connectionGroupID;
try {
connectionGroupID = Integer.parseInt(uniqueIdentifier);
} catch(NumberFormatException e) {
// Invalid number means it can't be a DB record; not found
return null;
Integer connectionGroupID = null;
// Try to parse the connectionID if it's not the root group
if(!MySQLConstants.CONNECTION_GROUP_ROOT_IDENTIFIER.equals(uniqueIdentifier)) {
try {
connectionGroupID = Integer.parseInt(uniqueIdentifier);
} catch(NumberFormatException e) {
throw new GuacamoleException("Invalid connection group ID.");
}
}
return retrieveConnectionGroup(connectionGroupID, userID);
@@ -156,7 +160,19 @@ public class ConnectionGroupService {
* @return The connection group having the given ID, or null if no such
* connection was found.
*/
public MySQLConnectionGroup retrieveConnectionGroup(int id, int userID) {
public MySQLConnectionGroup retrieveConnectionGroup(Integer id, int userID) {
// This is the root connection group, so just create it here
if(id == null) {
MySQLConnectionGroup connectionGroup = mysqlConnectionGroupProvider.get();
connectionGroup.init(null, null,
MySQLConstants.CONNECTION_GROUP_ROOT_IDENTIFIER,
MySQLConstants.CONNECTION_GROUP_ROOT_IDENTIFIER,
net.sourceforge.guacamole.net.auth.ConnectionGroup.Type.BALANCING,
userID);
return connectionGroup;
}
// Query connection by ID
ConnectionGroup connectionGroup = connectionGroupDAO.selectByPrimaryKey(id);
@@ -330,16 +346,18 @@ public class ConnectionGroupService {
*
* @param name The name to assign to the new connection group.
* @param userID The ID of the user who created this connection group.
* @param Type The type of the new connection group.
* @return A new MySQLConnectionGroup containing the data of the newly created
* connection group.
*/
public MySQLConnectionGroup createConnectionGroup(String name, int userID,
Integer parentID) {
Integer parentID, String type) {
// Initialize database connection
ConnectionGroup connectionGroup = new ConnectionGroup();
connectionGroup.setConnection_group_name(name);
connectionGroup.setParent_id(parentID);
connectionGroup.setType(type);
// Create connection
connectionGroupDAO.insert(connectionGroup);