mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
Ticket #263: Fixed bugs around not being able to add connections or groups into the root group.
This commit is contained in:
@@ -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.
|
||||
|
@@ -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.
|
||||
|
@@ -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,8 +160,20 @@ 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);
|
||||
|
Reference in New Issue
Block a user