diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/Connection.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnection.java similarity index 89% rename from guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/Connection.java rename to guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnection.java index 53012d400..797f045da 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/Connection.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/APIConnection.java @@ -20,6 +20,7 @@ package org.glyptodon.guacamole.net.basic.rest.connection; import java.util.List; import org.glyptodon.guacamole.GuacamoleException; +import org.glyptodon.guacamole.net.auth.Connection; import org.glyptodon.guacamole.net.auth.ConnectionRecord; import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; @@ -28,7 +29,7 @@ import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; * * @author James Muehlner */ -public class Connection { +public class APIConnection { /** * The name of this connection. @@ -51,17 +52,17 @@ public class Connection { private List history; /** - * Create an empty Connection. + * Create an empty APIConnection. */ - public Connection() {} + public APIConnection() {} /** - * Create a Connection from a org.glyptodon.guacamole.net.auth.Connection. - * @param connection The connection to create this Connection from. + * Create an APIConnection from a Connection record. + * @param connection The connection to create this APIConnection from. * @throws GuacamoleException If a problem is encountered while - * instantiating this new Connection. + * instantiating this new APIConnection. */ - public Connection(org.glyptodon.guacamole.net.auth.Connection connection) + public APIConnection(Connection connection) throws GuacamoleException { this.name = connection.getName(); this.identifier = connection.getIdentifier(); diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionRESTService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionRESTService.java index 92a46e2b0..b0f99c35e 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionRESTService.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionRESTService.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.Path; +import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.WebApplicationException; @@ -30,6 +31,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleSecurityException; +import org.glyptodon.guacamole.net.auth.Connection; import org.glyptodon.guacamole.net.auth.ConnectionGroup; import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.net.auth.UserContext; @@ -52,13 +54,23 @@ public class ConnectionRESTService { private AuthenticationService authenticationService; /** - * A service for managing the REST endpoint Connection objects. + * A service for managing the REST endpoint APIConnection objects. */ @Inject private ConnectionService connectionService; + /** + * Gets a list of connections with the given ConnectionGroup parentID. + * If no parentID is provided, returns the connections from the root group. + * + * @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. + * @return The connection list. + */ @GET - public List getConnections(@QueryParam("token") String authToken, @QueryParam("parentID") String parentID) { + public List getConnections(@QueryParam("token") String authToken, @QueryParam("parentID") String parentID) { UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken); try { @@ -78,12 +90,11 @@ public class ConnectionRESTService { .entity(new APIError("No ConnectionGroup found with the provided parentID.")) .build()); - Directory connectionDirectory = + Directory connectionDirectory = parentConnectionGroup.getConnectionDirectory(); // Get the list of connection names - List connections - = new ArrayList(); + List connections = new ArrayList(); Iterable identifiers = connectionDirectory.getIdentifiers(); // Get the connection for each name @@ -101,5 +112,46 @@ public class ConnectionRESTService { .entity(e).build()); } } + + /** + * Gets an individual connection. + * + * @param authToken The authentication token that is used to authenticate + * the user performing the operation. + * @param connectionID The ID of the APIConnection.. + * @return The connection. + */ + @GET + @Path("/{connectionID}") + public APIConnection getConnection(@QueryParam("token") String authToken, @PathParam("connectionID") String connectionID) { + UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken); + + try { + + // Get the connection directory + ConnectionGroup rootGroup = userContext.getRootConnectionGroup(); + Directory connectionDirectory = + rootGroup.getConnectionDirectory(); + + // Get the connection + Connection connection = connectionDirectory.get(connectionID); + + if(connection == null) + throw new WebApplicationException( + Response.status(Response.Status.BAD_REQUEST) + .entity(new APIError("No Connection found with the provided ID.")) + .build()); + + return new APIConnection(connection); + } catch(GuacamoleSecurityException e) { + throw new WebApplicationException( + Response.status(Response.Status.UNAUTHORIZED) + .entity(new APIError("Permission Denied.")).build()); + } catch(GuacamoleException e) { + throw new WebApplicationException( + Response.status(Response.Status.INTERNAL_SERVER_ERROR) + .entity(e).build()); + } + } } diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionService.java index 182261035..51513b494 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionService.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionService.java @@ -30,21 +30,21 @@ import org.glyptodon.guacamole.GuacamoleException; public class ConnectionService { /** - * Converts a list of org.glyptodon.guacamole.net.auth.Connection to - * Connection objects for exposure with the REST endpoints. + * Converts a list of org.glyptodon.guacamole.net.auth.APIConnection to + * APIConnection objects for exposure with the REST endpoints. * - * @param connections The org.glyptodon.guacamole.net.auth.Connection to + * @param connections The org.glyptodon.guacamole.net.auth.APIConnection to * convert for REST endpoint use. - * @return A List of Connection objects for use with the REST endpoint. + * @return A List of APIConnection objects for use with the REST endpoint. * @throws GuacamoleException If an error occurs while converting the * connections. */ - public List convertConnectionList(List connections) + public List convertConnectionList(List connections) throws GuacamoleException { - List restConnections = new ArrayList(); + List restConnections = new ArrayList(); for(org.glyptodon.guacamole.net.auth.Connection connection : connections) { - restConnections.add(new Connection(connection)); + restConnections.add(new APIConnection(connection)); } return restConnections;