mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
GUAC-1100: Move connection and connection group directories to root level only.
This commit is contained in:
@@ -210,11 +210,9 @@ public class TunnelRequestService {
|
||||
// Connection identifiers
|
||||
case CONNECTION: {
|
||||
|
||||
UserContext context = session.getUserContext();
|
||||
|
||||
// Get connection directory
|
||||
Directory<Connection> directory =
|
||||
context.getRootConnectionGroup().getConnectionDirectory();
|
||||
UserContext context = session.getUserContext();
|
||||
Directory<Connection> directory = context.getConnectionDirectory();
|
||||
|
||||
// Get authorized connection
|
||||
Connection connection = directory.get(id);
|
||||
@@ -232,11 +230,9 @@ public class TunnelRequestService {
|
||||
// Connection group identifiers
|
||||
case CONNECTION_GROUP: {
|
||||
|
||||
UserContext context = session.getUserContext();
|
||||
|
||||
// Get connection group directory
|
||||
Directory<ConnectionGroup> directory =
|
||||
context.getRootConnectionGroup().getConnectionGroupDirectory();
|
||||
UserContext context = session.getUserContext();
|
||||
Directory<ConnectionGroup> directory = context.getConnectionGroupDirectory();
|
||||
|
||||
// Get authorized connection group
|
||||
ConnectionGroup group = directory.get(id);
|
||||
|
@@ -89,9 +89,8 @@ public class ObjectRetrievalService {
|
||||
public Connection retrieveConnection(UserContext userContext,
|
||||
String identifier) throws GuacamoleException {
|
||||
|
||||
// Get root directory
|
||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||
Directory<Connection> directory = rootGroup.getConnectionDirectory();
|
||||
// Get connection directory
|
||||
Directory<Connection> directory = userContext.getConnectionDirectory();
|
||||
|
||||
// Pull specified connection
|
||||
Connection connection = directory.get(identifier);
|
||||
@@ -125,14 +124,12 @@ public class ObjectRetrievalService {
|
||||
public ConnectionGroup retrieveConnectionGroup(UserContext userContext,
|
||||
String identifier) throws GuacamoleException {
|
||||
|
||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||
|
||||
// Use root group if identifier is null (or the standard root identifier)
|
||||
// Use root group if identifier is the standard root identifier
|
||||
if (identifier != null && identifier.equals(APIConnectionGroup.ROOT_IDENTIFIER))
|
||||
return rootGroup;
|
||||
return userContext.getRootConnectionGroup();
|
||||
|
||||
// Pull specified connection group otherwise
|
||||
Directory<ConnectionGroup> directory = rootGroup.getConnectionGroupDirectory();
|
||||
Directory<ConnectionGroup> directory = userContext.getConnectionGroupDirectory();
|
||||
ConnectionGroup connectionGroup = directory.get(identifier);
|
||||
|
||||
if (connectionGroup == null)
|
||||
|
@@ -210,9 +210,7 @@ public class ConnectionRESTService {
|
||||
UserContext userContext = authenticationService.getUserContext(authToken);
|
||||
|
||||
// Get the connection directory
|
||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||
Directory<Connection> connectionDirectory =
|
||||
rootGroup.getConnectionDirectory();
|
||||
Directory<Connection> connectionDirectory = userContext.getConnectionDirectory();
|
||||
|
||||
// Delete the specified connection
|
||||
connectionDirectory.remove(connectionID);
|
||||
@@ -247,12 +245,8 @@ public class ConnectionRESTService {
|
||||
if (connection == null)
|
||||
throw new GuacamoleClientException("Connection JSON must be submitted when creating connections.");
|
||||
|
||||
// Retrieve parent group
|
||||
String parentID = connection.getParentIdentifier();
|
||||
ConnectionGroup parentConnectionGroup = retrievalService.retrieveConnectionGroup(userContext, parentID);
|
||||
|
||||
// Add the new connection
|
||||
Directory<Connection> connectionDirectory = parentConnectionGroup.getConnectionDirectory();
|
||||
Directory<Connection> connectionDirectory = userContext.getConnectionDirectory();
|
||||
connectionDirectory.add(new APIConnectionWrapper(connection));
|
||||
|
||||
// Return the new connection identifier
|
||||
@@ -291,9 +285,7 @@ public class ConnectionRESTService {
|
||||
throw new GuacamoleClientException("Connection JSON must be submitted when updating connections.");
|
||||
|
||||
// Get the connection directory
|
||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||
Directory<Connection> connectionDirectory =
|
||||
rootGroup.getConnectionDirectory();
|
||||
Directory<Connection> connectionDirectory = userContext.getConnectionDirectory();
|
||||
|
||||
// Retrieve connection to update
|
||||
Connection existingConnection = retrievalService.retrieveConnection(userContext, connectionID);
|
||||
@@ -308,15 +300,6 @@ public class ConnectionRESTService {
|
||||
existingConnection.setName(connection.getName());
|
||||
connectionDirectory.update(existingConnection);
|
||||
|
||||
// Get old and new parents
|
||||
String oldParentIdentifier = existingConnection.getParentIdentifier();
|
||||
ConnectionGroup updatedParentGroup = retrievalService.retrieveConnectionGroup(userContext, connection.getParentIdentifier());
|
||||
|
||||
// Update connection parent, if changed
|
||||
if ( (oldParentIdentifier != null && !oldParentIdentifier.equals(updatedParentGroup.getIdentifier()))
|
||||
|| (oldParentIdentifier == null && updatedParentGroup.getIdentifier() != null))
|
||||
connectionDirectory.move(connectionID, updatedParentGroup.getConnectionDirectory());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@
|
||||
|
||||
package org.glyptodon.guacamole.net.basic.rest.connectiongroup;
|
||||
|
||||
import java.util.Set;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.net.GuacamoleSocket;
|
||||
import org.glyptodon.guacamole.net.auth.Connection;
|
||||
@@ -92,12 +93,12 @@ public class APIConnectionGroupWrapper implements ConnectionGroup {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Directory<Connection> getConnectionDirectory() throws GuacamoleException {
|
||||
public Set<String> getConnectionIdentifiers() {
|
||||
throw new UnsupportedOperationException("Operation not supported.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Directory<ConnectionGroup> getConnectionGroupDirectory() throws GuacamoleException {
|
||||
public Set<String> getConnectionGroupIdentifiers() {
|
||||
throw new UnsupportedOperationException("Operation not supported.");
|
||||
}
|
||||
|
||||
|
@@ -137,7 +137,7 @@ public class ConnectionGroupRESTService {
|
||||
|
||||
// Retrieve the requested tree, filtering by the given permissions
|
||||
ConnectionGroup treeRoot = retrievalService.retrieveConnectionGroup(userContext, connectionGroupID);
|
||||
ConnectionGroupTree tree = new ConnectionGroupTree(treeRoot, permissions);
|
||||
ConnectionGroupTree tree = new ConnectionGroupTree(userContext, treeRoot, permissions);
|
||||
|
||||
// Return tree as a connection group
|
||||
return tree.getRootAPIConnectionGroup();
|
||||
@@ -166,9 +166,7 @@ public class ConnectionGroupRESTService {
|
||||
UserContext userContext = authenticationService.getUserContext(authToken);
|
||||
|
||||
// Get the connection group directory
|
||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||
Directory<ConnectionGroup> connectionGroupDirectory =
|
||||
rootGroup.getConnectionGroupDirectory();
|
||||
Directory<ConnectionGroup> connectionGroupDirectory = userContext.getConnectionGroupDirectory();
|
||||
|
||||
// Delete the connection group
|
||||
connectionGroupDirectory.remove(connectionGroupID);
|
||||
@@ -205,12 +203,8 @@ public class ConnectionGroupRESTService {
|
||||
if (connectionGroup == null)
|
||||
throw new GuacamoleClientException("Connection group JSON must be submitted when creating connections groups.");
|
||||
|
||||
// Retrieve parent group
|
||||
String parentID = connectionGroup.getParentIdentifier();
|
||||
ConnectionGroup parentConnectionGroup = retrievalService.retrieveConnectionGroup(userContext, parentID);
|
||||
|
||||
// Add the new connection group
|
||||
Directory<ConnectionGroup> connectionGroupDirectory = parentConnectionGroup.getConnectionGroupDirectory();
|
||||
Directory<ConnectionGroup> connectionGroupDirectory = userContext.getConnectionGroupDirectory();
|
||||
connectionGroupDirectory.add(new APIConnectionGroupWrapper(connectionGroup));
|
||||
|
||||
// Return the new connection group identifier
|
||||
@@ -250,9 +244,7 @@ public class ConnectionGroupRESTService {
|
||||
throw new GuacamoleClientException("Connection group JSON must be submitted when updating connection groups.");
|
||||
|
||||
// Get the connection group directory
|
||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||
Directory<ConnectionGroup> connectionGroupDirectory =
|
||||
rootGroup.getConnectionGroupDirectory();
|
||||
Directory<ConnectionGroup> connectionGroupDirectory = userContext.getConnectionGroupDirectory();
|
||||
|
||||
// Retrieve connection group to update
|
||||
ConnectionGroup existingConnectionGroup = connectionGroupDirectory.get(connectionGroupID);
|
||||
@@ -262,15 +254,6 @@ public class ConnectionGroupRESTService {
|
||||
existingConnectionGroup.setType(connectionGroup.getType());
|
||||
connectionGroupDirectory.update(existingConnectionGroup);
|
||||
|
||||
// Get old and new parents
|
||||
String oldParentIdentifier = existingConnectionGroup.getParentIdentifier();
|
||||
ConnectionGroup updatedParentGroup = retrievalService.retrieveConnectionGroup(userContext, connectionGroup.getParentIdentifier());
|
||||
|
||||
// Update connection group parent, if changed
|
||||
if ( (oldParentIdentifier != null && !oldParentIdentifier.equals(updatedParentGroup.getIdentifier()))
|
||||
|| (oldParentIdentifier == null && updatedParentGroup.getIdentifier() != null))
|
||||
connectionGroupDirectory.move(connectionGroupID, updatedParentGroup.getConnectionGroupDirectory());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -31,6 +31,7 @@ import java.util.Map;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.net.auth.Connection;
|
||||
import org.glyptodon.guacamole.net.auth.ConnectionGroup;
|
||||
import org.glyptodon.guacamole.net.auth.UserContext;
|
||||
import org.glyptodon.guacamole.net.auth.permission.ObjectPermission;
|
||||
import org.glyptodon.guacamole.net.basic.rest.connection.APIConnection;
|
||||
import org.slf4j.Logger;
|
||||
@@ -48,11 +49,11 @@ public class ConnectionGroupTree {
|
||||
* Logger for this class.
|
||||
*/
|
||||
private static final Logger logger = LoggerFactory.getLogger(ConnectionGroupTree.class);
|
||||
|
||||
|
||||
/**
|
||||
* The root connection group.
|
||||
* The context of the user obtaining this tree.
|
||||
*/
|
||||
private final ConnectionGroup root;
|
||||
private final UserContext userContext;
|
||||
|
||||
/**
|
||||
* The root connection group as an APIConnectionGroup.
|
||||
@@ -174,19 +175,19 @@ public class ConnectionGroupTree {
|
||||
|
||||
// Build lists of identifiers for retrieval
|
||||
for (ConnectionGroup parent : parents) {
|
||||
childConnectionIdentifiers.addAll(parent.getConnectionDirectory().getIdentifiers());
|
||||
childConnectionGroupIdentifiers.addAll(parent.getConnectionGroupDirectory().getIdentifiers());
|
||||
childConnectionIdentifiers.addAll(parent.getConnectionIdentifiers());
|
||||
childConnectionGroupIdentifiers.addAll(parent.getConnectionGroupIdentifiers());
|
||||
}
|
||||
|
||||
// Retrieve child connections
|
||||
if (!childConnectionIdentifiers.isEmpty()) {
|
||||
Collection<Connection> childConnections = root.getConnectionDirectory().getAll(childConnectionIdentifiers);
|
||||
Collection<Connection> childConnections = userContext.getConnectionDirectory().getAll(childConnectionIdentifiers);
|
||||
addConnections(childConnections);
|
||||
}
|
||||
|
||||
// Retrieve child connection groups
|
||||
if (!childConnectionGroupIdentifiers.isEmpty()) {
|
||||
Collection<ConnectionGroup> childConnectionGroups = root.getConnectionGroupDirectory().getAll(childConnectionGroupIdentifiers);
|
||||
Collection<ConnectionGroup> childConnectionGroups = userContext.getConnectionGroupDirectory().getAll(childConnectionGroupIdentifiers);
|
||||
addConnectionGroups(childConnectionGroups);
|
||||
addDescendants(childConnectionGroups);
|
||||
}
|
||||
@@ -197,6 +198,9 @@ public class ConnectionGroupTree {
|
||||
* Creates a new connection group tree using the given connection group as
|
||||
* the tree root.
|
||||
*
|
||||
* @param userContext
|
||||
* The context of the user obtaining the connection group tree.
|
||||
*
|
||||
* @param root
|
||||
* The connection group to use as the root of this connection group
|
||||
* tree.
|
||||
@@ -211,11 +215,12 @@ public class ConnectionGroupTree {
|
||||
* If an error occurs while retrieving the tree of connection groups
|
||||
* and their descendants.
|
||||
*/
|
||||
public ConnectionGroupTree(ConnectionGroup root,
|
||||
public ConnectionGroupTree(UserContext userContext, ConnectionGroup root,
|
||||
List<ObjectPermission.Type> permissions) throws GuacamoleException {
|
||||
|
||||
this.userContext = userContext;
|
||||
|
||||
// Store root of tree
|
||||
this.root = root;
|
||||
this.rootAPIGroup = new APIConnectionGroup(root);
|
||||
retrievedGroups.put(root.getIdentifier(), this.rootAPIGroup);
|
||||
|
||||
|
Reference in New Issue
Block a user