mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 00:53:21 +00:00 
			
		
		
		
	GUAC-932: Clean up REST JavaScript for connections and groups. Update Java style to match.
This commit is contained in:
		| @@ -36,17 +36,17 @@ import javax.ws.rs.PathParam; | ||||
| import javax.ws.rs.Produces; | ||||
| import javax.ws.rs.QueryParam; | ||||
| import javax.ws.rs.core.MediaType; | ||||
| import javax.ws.rs.core.Response.Status; | ||||
| import org.glyptodon.guacamole.GuacamoleClientException; | ||||
| import org.glyptodon.guacamole.GuacamoleException; | ||||
| import org.glyptodon.guacamole.GuacamoleResourceNotFoundException; | ||||
| import org.glyptodon.guacamole.net.auth.Connection; | ||||
| import org.glyptodon.guacamole.net.auth.ConnectionGroup; | ||||
| import org.glyptodon.guacamole.net.auth.ConnectionRecord; | ||||
| import org.glyptodon.guacamole.net.auth.Directory; | ||||
| import org.glyptodon.guacamole.net.auth.UserContext; | ||||
| import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure; | ||||
| import org.glyptodon.guacamole.net.basic.rest.HTTPException; | ||||
| import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService; | ||||
| import org.glyptodon.guacamole.net.basic.rest.connectiongroup.APIConnectionGroup; | ||||
| import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| @@ -56,7 +56,7 @@ import org.slf4j.LoggerFactory; | ||||
|  *  | ||||
|  * @author James Muehlner | ||||
|  */ | ||||
| @Path("/connection") | ||||
| @Path("/connections") | ||||
| @Produces(MediaType.APPLICATION_JSON) | ||||
| @Consumes(MediaType.APPLICATION_JSON) | ||||
| public class ConnectionRESTService { | ||||
| @@ -73,13 +73,20 @@ public class ConnectionRESTService { | ||||
|     private AuthenticationService authenticationService; | ||||
|      | ||||
|     /** | ||||
|      * Gets an individual connection. | ||||
|      * Retrieves an individual connection. | ||||
|      *  | ||||
|      * @param authToken The authentication token that is used to authenticate | ||||
|      *                  the user performing the operation. | ||||
|      * @param connectionID The ID of the Connection.. | ||||
|      * @return The connection. | ||||
|      * @throws GuacamoleException If a problem is encountered while retrieving the connection. | ||||
|      * @param authToken | ||||
|      *     The authentication token that is used to authenticate the user | ||||
|      *     performing the operation. | ||||
|      * | ||||
|      * @param connectionID | ||||
|      *     The identifier of the connection to retrieve. | ||||
|      * | ||||
|      * @return | ||||
|      *     The connection having the given identifier. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while retrieving the connection. | ||||
|      */ | ||||
|     @GET | ||||
|     @Path("/{connectionID}") | ||||
| @@ -97,7 +104,7 @@ public class ConnectionRESTService { | ||||
|         // Get the connection | ||||
|         Connection connection = connectionDirectory.get(connectionID); | ||||
|         if (connection == null) | ||||
|             throw new HTTPException(Status.NOT_FOUND, "No Connection found with the provided ID."); | ||||
|             throw new GuacamoleResourceNotFoundException("No such connection: \"" + connectionID + "\""); | ||||
|  | ||||
|         return new APIConnection(connection); | ||||
|  | ||||
| @@ -111,7 +118,7 @@ public class ConnectionRESTService { | ||||
|      *     performing the operation. | ||||
|      * | ||||
|      * @param connectionID | ||||
|      *     The ID of the connection. | ||||
|      *     The identifier of the connection. | ||||
|      * | ||||
|      * @return | ||||
|      *     A map of parameter name/value pairs. | ||||
| @@ -135,7 +142,7 @@ public class ConnectionRESTService { | ||||
|         // Get the connection | ||||
|         Connection connection = connectionDirectory.get(connectionID); | ||||
|         if (connection == null) | ||||
|             throw new HTTPException(Status.NOT_FOUND, "No Connection found with the provided ID."); | ||||
|             throw new GuacamoleResourceNotFoundException("No such connection: \"" + connectionID + "\""); | ||||
|  | ||||
|         // Retrieve connection configuration | ||||
|         GuacamoleConfiguration config = connection.getConfiguration(); | ||||
| @@ -157,7 +164,7 @@ public class ConnectionRESTService { | ||||
|      *     performing the operation. | ||||
|      * | ||||
|      * @param connectionID | ||||
|      *     The ID of the connection. | ||||
|      *     The identifier of the connection. | ||||
|      * | ||||
|      * @return | ||||
|      *     A list of connection records, describing the start and end times of | ||||
| @@ -182,7 +189,7 @@ public class ConnectionRESTService { | ||||
|         // Get the connection | ||||
|         Connection connection = connectionDirectory.get(connectionID); | ||||
|         if (connection == null) | ||||
|             throw new HTTPException(Status.NOT_FOUND, "No Connection found with the provided ID."); | ||||
|             throw new GuacamoleResourceNotFoundException("No such connection: \"" + connectionID + "\""); | ||||
|  | ||||
|         return connection.getHistory(); | ||||
|  | ||||
| @@ -191,10 +198,15 @@ public class ConnectionRESTService { | ||||
|     /** | ||||
|      * Deletes an individual connection. | ||||
|      *  | ||||
|      * @param authToken The authentication token that is used to authenticate | ||||
|      *                  the user performing the operation. | ||||
|      * @param connectionID The ID of the Connection to delete. | ||||
|      * @throws GuacamoleException If a problem is encountered while deleting the connection. | ||||
|      * @param authToken | ||||
|      *     The authentication token that is used to authenticate the user | ||||
|      *     performing the operation. | ||||
|      * | ||||
|      * @param connectionID | ||||
|      *     The identifier of the connection to delete. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while deleting the connection. | ||||
|      */ | ||||
|     @DELETE | ||||
|     @Path("/{connectionID}") | ||||
| @@ -211,72 +223,112 @@ public class ConnectionRESTService { | ||||
|  | ||||
|         // Make sure the connection is there before trying to delete | ||||
|         if (connectionDirectory.get(connectionID) == null) | ||||
|             throw new HTTPException(Status.NOT_FOUND, "No Connection found with the provided ID."); | ||||
|             throw new GuacamoleResourceNotFoundException("No such connection: \"" + connectionID + "\""); | ||||
|  | ||||
|         // Delete the connection | ||||
|         connectionDirectory.remove(connectionID); | ||||
|  | ||||
|     } | ||||
|      | ||||
|  | ||||
|     /** | ||||
|      * Creates a new connection and returns the identifier of the new connection. | ||||
|      * If a parentID is provided, the connection will be created in the | ||||
|      * connection group with the parentID. Otherwise, the root connection group | ||||
|      * will be used. | ||||
|      * Retrieves a single connection group from the given user context. If | ||||
|      * the given identifier is null or the root identifier, the root connection | ||||
|      * group will be returned. | ||||
|      * | ||||
|      * @param userContext | ||||
|      *     The user context to retrieve the connection group from. | ||||
|      * | ||||
|      * @param identifier | ||||
|      *     The identifier of the connection group to retrieve. | ||||
|      * | ||||
|      * @return | ||||
|      *     The connection group having the given identifier, or the root | ||||
|      *     connection group if the identifier is null or the root identifier. | ||||
|      * | ||||
|      * @throws GuacamoleException  | ||||
|      *     If an error occurs while retrieving the connection group, or if the | ||||
|      *     connection group does not exist. | ||||
|      */ | ||||
|     private ConnectionGroup retrieveConnectionGroup(UserContext userContext, | ||||
|             String identifier) throws GuacamoleException { | ||||
|  | ||||
|         ConnectionGroup rootGroup = userContext.getRootConnectionGroup(); | ||||
|  | ||||
|         // Use root group if identifier is null (or the standard root identifier) | ||||
|         if (identifier == null || identifier.equals(APIConnectionGroup.ROOT_IDENTIFIER)) | ||||
|             return rootGroup; | ||||
|  | ||||
|         // Pull specified connection group otherwise | ||||
|         Directory<String, ConnectionGroup> directory = rootGroup.getConnectionGroupDirectory(); | ||||
|         ConnectionGroup connectionGroup = directory.get(identifier); | ||||
|  | ||||
|         if (connectionGroup == null) | ||||
|             throw new GuacamoleResourceNotFoundException("No such connection group: \"" + identifier + "\""); | ||||
|  | ||||
|         return connectionGroup; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new connection and returns the identifier of the new | ||||
|      * connection. | ||||
|      *  | ||||
|      * @param authToken The authentication token that is used to authenticate | ||||
|      *                  the user performing the operation. | ||||
|      * @param parentID The ID of the ConnectionGroup the connections | ||||
|      *                 belong to. If null, the root connection group will be used. | ||||
|      * @param connection The connection to create. | ||||
|      * @return The identifier of the new connection. | ||||
|      * @throws GuacamoleException If a problem is encountered while creating the connection. | ||||
|      * @param authToken | ||||
|      *     The authentication token that is used to authenticate the user | ||||
|      *     performing the operation. | ||||
|      * | ||||
|      * @param connection | ||||
|      *     The connection to create. | ||||
|      * | ||||
|      * @return | ||||
|      *     The identifier of the new connection. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while creating the connection. | ||||
|      */ | ||||
|     @POST | ||||
|     @AuthProviderRESTExposure | ||||
|     public String createConnection(@QueryParam("token") String authToken,  | ||||
|             @QueryParam("parentID") String parentID, APIConnection connection) throws GuacamoleException { | ||||
|     public String createConnection(@QueryParam("token") String authToken, | ||||
|             APIConnection connection) throws GuacamoleException { | ||||
|  | ||||
|         UserContext userContext = authenticationService.getUserContext(authToken); | ||||
|          | ||||
|         // Validate that connection data was provided | ||||
|         if (connection == null) | ||||
|             throw new GuacamoleClientException("A connection is required for this request."); | ||||
|             throw new GuacamoleClientException("Connection JSON must be submitted when creating connections."); | ||||
|  | ||||
|         // If the parent connection group is passed in, try to find it. | ||||
|         ConnectionGroup parentConnectionGroup; | ||||
|         if (parentID == null) | ||||
|             parentConnectionGroup = userContext.getRootConnectionGroup(); | ||||
|         // Retrieve parent group | ||||
|         String parentID = connection.getParentIdentifier(); | ||||
|         ConnectionGroup parentConnectionGroup = retrieveConnectionGroup(userContext, parentID); | ||||
|  | ||||
|         else { | ||||
|             ConnectionGroup rootGroup = userContext.getRootConnectionGroup(); | ||||
|             Directory<String, ConnectionGroup> connectionGroupDirectory = rootGroup.getConnectionGroupDirectory(); | ||||
|             parentConnectionGroup = connectionGroupDirectory.get(parentID); | ||||
|         } | ||||
|  | ||||
|         if (parentConnectionGroup == null) | ||||
|             throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID."); | ||||
|  | ||||
|         Directory<String, Connection> connectionDirectory =  | ||||
|                 parentConnectionGroup.getConnectionDirectory(); | ||||
|  | ||||
|         // Create the connection | ||||
|         // Add the new connection | ||||
|         Directory<String, Connection> connectionDirectory = parentConnectionGroup.getConnectionDirectory(); | ||||
|         connectionDirectory.add(new APIConnectionWrapper(connection)); | ||||
|  | ||||
|         // Return the new connection identifier | ||||
|         return connection.getIdentifier(); | ||||
|  | ||||
|     } | ||||
|      | ||||
|    | ||||
|     /** | ||||
|      * Updates a connection. | ||||
|      * Updates an existing connection. If the parent identifier of the | ||||
|      * connection is changed, the connection will also be moved to the new | ||||
|      * parent group. | ||||
|      *  | ||||
|      * @param authToken The authentication token that is used to authenticate | ||||
|      *                  the user performing the operation. | ||||
|      * @param connectionID The ID of the Connection to move. | ||||
|      * @param connection The connection to update. | ||||
|      * @throws GuacamoleException If a problem is encountered while updating the connection. | ||||
|      * @param authToken | ||||
|      *     The authentication token that is used to authenticate the user | ||||
|      *     performing the operation. | ||||
|      * | ||||
|      * @param connectionID | ||||
|      *     The identifier of the connection to update. | ||||
|      * | ||||
|      * @param connection | ||||
|      *     The connection data to update the specified connection with. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while updating the connection. | ||||
|      */ | ||||
|     @POST | ||||
|     @PUT | ||||
|     @Path("/{connectionID}") | ||||
|     @AuthProviderRESTExposure | ||||
|     public void updateConnection(@QueryParam("token") String authToken,  | ||||
| @@ -284,62 +336,27 @@ public class ConnectionRESTService { | ||||
|  | ||||
|         UserContext userContext = authenticationService.getUserContext(authToken); | ||||
|          | ||||
|         // Validate that connection data was provided | ||||
|         if (connection == null) | ||||
|             throw new GuacamoleClientException("A connection is required for this request."); | ||||
|             throw new GuacamoleClientException("Connection JSON must be submitted when updating connections."); | ||||
|  | ||||
|         // Get the connection directory | ||||
|         ConnectionGroup rootGroup = userContext.getRootConnectionGroup(); | ||||
|         Directory<String, Connection> connectionDirectory = | ||||
|                 rootGroup.getConnectionDirectory(); | ||||
|          | ||||
|         Connection connectionFromAuthProvider = connectionDirectory.get(connectionID); | ||||
|  | ||||
|         // Make sure the connection is there before trying to update | ||||
|         if (connectionFromAuthProvider == null) | ||||
|             throw new HTTPException(Status.NOT_FOUND, "No Connection found with the provided ID."); | ||||
|         Connection existingConnection = connectionDirectory.get(connectionID); | ||||
|         if (existingConnection == null) | ||||
|             throw new GuacamoleResourceNotFoundException("No such connection: \"" + connectionID + "\""); | ||||
|          | ||||
|         // Copy the information from this connection over to an object from the Auth Provider | ||||
|         APIConnectionWrapper wrappedConnection = new APIConnectionWrapper(connection); | ||||
|         connectionFromAuthProvider.setConfiguration(wrappedConnection.getConfiguration()); | ||||
|         connectionFromAuthProvider.setName(wrappedConnection.getName()); | ||||
|         Connection wrappedConnection = new APIConnectionWrapper(connection); | ||||
|  | ||||
|         // Update the connection | ||||
|         connectionDirectory.update(connectionFromAuthProvider); | ||||
|         existingConnection.setConfiguration(wrappedConnection.getConfiguration()); | ||||
|         existingConnection.setName(wrappedConnection.getName()); | ||||
|         connectionDirectory.update(existingConnection); | ||||
|  | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * Moves an individual connection to a different connection group. | ||||
|      *  | ||||
|      * @param authToken The authentication token that is used to authenticate | ||||
|      *                  the user performing the operation. | ||||
|      * @param connectionID The ID of the Connection to move. | ||||
|      * @param parentID The ID of the ConnectionGroup the connection is to be moved to. | ||||
|      * @throws GuacamoleException If a problem is encountered while moving the connection. | ||||
|      */ | ||||
|     @PUT | ||||
|     @Path("/{connectionID}") | ||||
|     @AuthProviderRESTExposure | ||||
|     public void moveConnection(@QueryParam("token") String authToken,  | ||||
|             @PathParam("connectionID") String connectionID, @QueryParam("parentID") String parentID)  | ||||
|             throws GuacamoleException { | ||||
|  | ||||
|         UserContext userContext = authenticationService.getUserContext(authToken); | ||||
|  | ||||
|         // Get the connection directory | ||||
|         ConnectionGroup rootGroup = userContext.getRootConnectionGroup(); | ||||
|         Directory<String, Connection> connectionDirectory = | ||||
|                 rootGroup.getConnectionDirectory(); | ||||
|  | ||||
|         // Find the new parent connection group | ||||
|         Directory<String, ConnectionGroup> connectionGroupDirectory = rootGroup.getConnectionGroupDirectory(); | ||||
|         ConnectionGroup parentConnectionGroup = connectionGroupDirectory.get(parentID); | ||||
|  | ||||
|         if (parentConnectionGroup == null) | ||||
|             throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID."); | ||||
|  | ||||
|         // Move the connection | ||||
|         connectionDirectory.move(connectionID, parentConnectionGroup.getConnectionDirectory()); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -58,7 +58,7 @@ import org.slf4j.LoggerFactory; | ||||
|  *  | ||||
|  * @author James Muehlner | ||||
|  */ | ||||
| @Path("/connectionGroup") | ||||
| @Path("/connectionGroups") | ||||
| @Produces(MediaType.APPLICATION_JSON) | ||||
| @Consumes(MediaType.APPLICATION_JSON) | ||||
| public class ConnectionGroupRESTService { | ||||
| @@ -256,10 +256,15 @@ public class ConnectionGroupRESTService { | ||||
|     /** | ||||
|      * Deletes an individual connection group. | ||||
|      *  | ||||
|      * @param authToken The authentication token that is used to authenticate | ||||
|      *                  the user performing the operation. | ||||
|      * @param connectionGroupID The ID of the ConnectionGroup to delete. | ||||
|      * @throws GuacamoleException If a problem is encountered while deleting the connection group. | ||||
|      * @param authToken | ||||
|      *     The authentication token that is used to authenticate the user | ||||
|      *     performing the operation. | ||||
|      * | ||||
|      * @param connectionGroupID | ||||
|      *     The identifier of the connection group to delete. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while deleting the connection group. | ||||
|      */ | ||||
|     @DELETE | ||||
|     @Path("/{connectionGroupID}") | ||||
| @@ -281,7 +286,7 @@ public class ConnectionGroupRESTService { | ||||
|  | ||||
|         // Make sure the connection is there before trying to delete | ||||
|         if (connectionGroupDirectory.get(connectionGroupID) == null) | ||||
|             throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided ID."); | ||||
|             throw new GuacamoleResourceNotFoundException("No such connection group: \"" + connectionGroupID + "\""); | ||||
|  | ||||
|         // Delete the connection group | ||||
|         connectionGroupDirectory.remove(connectionGroupID); | ||||
| @@ -294,42 +299,49 @@ public class ConnectionGroupRESTService { | ||||
|      * connection group with the parentID. Otherwise, the root connection group | ||||
|      * will be used. | ||||
|      *  | ||||
|      * @param authToken The authentication token that is used to authenticate | ||||
|      *                  the user performing the operation. | ||||
|      * @param parentID The ID of the ConnectionGroup the connection groups | ||||
|      *                 belong to. If null, the root connection group will be used. | ||||
|      * @param connectionGroup The connection group to create. | ||||
|      * @return The identifier of the new connection group. | ||||
|      * @throws GuacamoleException If a problem is encountered while creating the connection group. | ||||
|      * @param authToken | ||||
|      *     The authentication token that is used to authenticate the user | ||||
|      *     performing the operation. | ||||
|      * | ||||
|      * @param connectionGroup | ||||
|      *     The connection group to create. | ||||
|      *  | ||||
|      * @return | ||||
|      *     The identifier of the new connection group. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while creating the connection group. | ||||
|      */ | ||||
|     @POST | ||||
|     @AuthProviderRESTExposure | ||||
|     public String createConnectionGroup(@QueryParam("token") String authToken,  | ||||
|             @QueryParam("parentID") String parentID, APIConnectionGroup connectionGroup) throws GuacamoleException { | ||||
|     public String createConnectionGroup(@QueryParam("token") String authToken, | ||||
|             APIConnectionGroup connectionGroup) throws GuacamoleException { | ||||
|  | ||||
|         UserContext userContext = authenticationService.getUserContext(authToken); | ||||
|  | ||||
|         // Validate that connection group data was provided | ||||
|         if (connectionGroup == null) | ||||
|             throw new GuacamoleClientException("A connection group is required for this request."); | ||||
|             throw new GuacamoleClientException("Connection group JSON must be submitted when creating connections groups."); | ||||
|  | ||||
|         // If the parent connection group is passed in, try to find it. | ||||
|         String parentID = connectionGroup.getParentIdentifier(); | ||||
|         ConnectionGroup rootGroup = userContext.getRootConnectionGroup(); | ||||
|  | ||||
|         // Use root group if no parent is specified | ||||
|         ConnectionGroup parentConnectionGroup; | ||||
|         if (parentID == null) | ||||
|             parentConnectionGroup = userContext.getRootConnectionGroup(); | ||||
|             parentConnectionGroup = rootGroup; | ||||
|  | ||||
|         // Pull specified connection group otherwise | ||||
|         else { | ||||
|             ConnectionGroup rootGroup = userContext.getRootConnectionGroup(); | ||||
|             Directory<String, ConnectionGroup> connectionGroupDirectory = rootGroup.getConnectionGroupDirectory(); | ||||
|             parentConnectionGroup = connectionGroupDirectory.get(parentID); | ||||
|  | ||||
|             if (parentConnectionGroup == null) | ||||
|                 throw new GuacamoleResourceNotFoundException("No such connection group: \"" + parentID + "\""); | ||||
|         } | ||||
|  | ||||
|         if (parentConnectionGroup == null) | ||||
|             throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID."); | ||||
|  | ||||
|         Directory<String, ConnectionGroup> connectionGroupDirectory =  | ||||
|                 parentConnectionGroup.getConnectionGroupDirectory(); | ||||
|  | ||||
|         // Create the connection group | ||||
|         // Add the new connection group | ||||
|         Directory<String, ConnectionGroup> connectionGroupDirectory = parentConnectionGroup.getConnectionGroupDirectory(); | ||||
|         connectionGroupDirectory.add(new APIConnectionGroupWrapper(connectionGroup)); | ||||
|  | ||||
|         // Return the new connection group identifier | ||||
| @@ -338,15 +350,24 @@ public class ConnectionGroupRESTService { | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * Updates a connection group. | ||||
|      * Updates a connection group. If the parent identifier of the | ||||
|      * connection group is changed, the connection group will also be moved to | ||||
|      * the new parent group. | ||||
|      *  | ||||
|      * @param authToken The authentication token that is used to authenticate | ||||
|      *                  the user performing the operation. | ||||
|      * @param connectionGroupID The ID of the ConnectionGroup to update. | ||||
|      * @param connectionGroup The connection group to update. | ||||
|      * @throws GuacamoleException If a problem is encountered while updating the connection group. | ||||
|      * @param authToken | ||||
|      *     The authentication token that is used to authenticate the user | ||||
|      *     performing the operation. | ||||
|      * | ||||
|      * @param connectionGroupID | ||||
|      *     The identifier of the existing connection group to update. | ||||
|      * | ||||
|      * @param connectionGroup | ||||
|      *     The data to update the existing connection group with. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while updating the connection group. | ||||
|      */ | ||||
|     @POST | ||||
|     @PUT | ||||
|     @Path("/{connectionGroupID}") | ||||
|     @AuthProviderRESTExposure | ||||
|     public void updateConnectionGroup(@QueryParam("token") String authToken,  | ||||
| @@ -355,8 +376,9 @@ public class ConnectionGroupRESTService { | ||||
|  | ||||
|         UserContext userContext = authenticationService.getUserContext(authToken); | ||||
|          | ||||
|         // Validate that connection group data was provided | ||||
|         if (connectionGroup == null) | ||||
|             throw new GuacamoleClientException("A connection group is required for this request."); | ||||
|             throw new GuacamoleClientException("Connection group JSON must be submitted when updating connection groups."); | ||||
|  | ||||
|         // Get the connection directory | ||||
|         ConnectionGroup rootGroup = userContext.getRootConnectionGroup(); | ||||
| @@ -370,51 +392,11 @@ public class ConnectionGroupRESTService { | ||||
|  | ||||
|         // Make sure the connection group is there before trying to update | ||||
|         if (connectionGroupDirectory.get(connectionGroupID) == null) | ||||
|             throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided ID."); | ||||
|             throw new GuacamoleResourceNotFoundException("No such connection group: \"" + connectionGroupID + "\""); | ||||
|  | ||||
|         // Update the connection group | ||||
|         connectionGroupDirectory.update(new APIConnectionGroupWrapper(connectionGroup)); | ||||
|  | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * Moves an individual connection group to a different connection group. | ||||
|      *  | ||||
|      * @param authToken The authentication token that is used to authenticate | ||||
|      *                  the user performing the operation. | ||||
|      * @param connectionGroupID The ID of the ConnectionGroup to move. | ||||
|      * @param parentID The ID of the ConnectionGroup the connection group is to be moved to. | ||||
|      * @throws GuacamoleException If a problem is encountered while moving the connection group. | ||||
|      */ | ||||
|     @PUT | ||||
|     @Path("/{connectionGroupID}") | ||||
|     @AuthProviderRESTExposure | ||||
|     public void moveConnectionGroup(@QueryParam("token") String authToken,  | ||||
|             @PathParam("connectionGroupID") String connectionGroupID,  | ||||
|             @QueryParam("parentID") String parentID) throws GuacamoleException { | ||||
|  | ||||
|         UserContext userContext = authenticationService.getUserContext(authToken); | ||||
|          | ||||
|         // Get the connection group directory | ||||
|         ConnectionGroup rootGroup = userContext.getRootConnectionGroup(); | ||||
|          | ||||
|         // Use the root group if it was asked for | ||||
|         if (connectionGroupID != null && connectionGroupID.equals(APIConnectionGroup.ROOT_IDENTIFIER)) | ||||
|             connectionGroupID = rootGroup.getIdentifier(); | ||||
|          | ||||
|         Directory<String, ConnectionGroup> connectionGroupDirectory = | ||||
|                 rootGroup.getConnectionGroupDirectory(); | ||||
|  | ||||
|         // Find the new parent connection group | ||||
|         Directory<String, ConnectionGroup> newConnectionGroupDirectory = rootGroup.getConnectionGroupDirectory(); | ||||
|         ConnectionGroup parentConnectionGroup = newConnectionGroupDirectory.get(parentID); | ||||
|  | ||||
|         if (parentConnectionGroup == null) | ||||
|             throw new HTTPException(Status.NOT_FOUND, "No ConnectionGroup found with the provided parentID."); | ||||
|  | ||||
|         // Move the connection group | ||||
|         connectionGroupDirectory.move(connectionGroupID, parentConnectionGroup.getConnectionGroupDirectory()); | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user