diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServletModule.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServletModule.java index cc4e90e6d..a2f0232f3 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServletModule.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/RESTServletModule.java @@ -31,6 +31,7 @@ import org.glyptodon.guacamole.net.basic.rest.clipboard.ClipboardRESTService; import org.glyptodon.guacamole.net.basic.rest.connection.ConnectionRESTService; import org.glyptodon.guacamole.net.basic.rest.connectiongroup.ConnectionGroupRESTService; import org.glyptodon.guacamole.net.basic.rest.protocol.ProtocolRESTService; +import org.glyptodon.guacamole.net.basic.rest.tunnel.TunnelRESTService; import org.glyptodon.guacamole.net.basic.rest.user.UserRESTService; /** @@ -50,6 +51,7 @@ public class RESTServletModule extends ServletModule { bind(ProtocolRESTService.class); bind(UserRESTService.class); bind(TokenRESTService.class); + bind(TunnelRESTService.class); // Set up the servlet and JSON mappings bind(GuiceContainer.class); diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/tunnel/APITunnel.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/tunnel/APITunnel.java new file mode 100644 index 000000000..795b4e05e --- /dev/null +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/tunnel/APITunnel.java @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2015 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package org.glyptodon.guacamole.net.basic.rest.tunnel; + +import java.util.Date; +import org.glyptodon.guacamole.net.auth.ConnectionRecord; + +/** + * Tunnel-related information which may be exposed through the REST endpoints. + * + * @author Michael Jumper + */ +public class APITunnel { + + /** + * The date and time the connection began. + */ + private final Date startDate; + + /** + * The host from which the connection originated, if known. + */ + private final String remoteHost; + + /** + * The name of the user who used or is using the connection. + */ + private final String username; + + /** + * The UUID of the tunnel. + */ + private final String uuid; + + /** + * Creates a new APITunnel, copying the information from the given + * connection record. + * + * @param record + * The record to copy data from. + */ + public APITunnel(ConnectionRecord record) { + this.startDate = record.getStartDate(); + this.remoteHost = record.getRemoteHost(); + this.username = record.getUsername(); + this.uuid = "STUB"; // STUB + } + + /** + * Returns the date and time the connection began. + * + * @return + * The date and time the connection began. + */ + public Date getStartDate() { + return startDate; + } + + /** + * Returns the remote host from which this connection originated. + * + * @return + * The remote host from which this connection originated. + */ + public String getRemoteHost() { + return remoteHost; + } + + /** + * Returns the name of the user who used or is using the connection at the + * times given by this tunnel. + * + * @return + * The name of the user who used or is using the associated connection. + */ + public String getUsername() { + return username; + } + + /** + * Returns the UUID of the underlying Guacamole tunnel. Absolutely every + * Guacamole tunnel has an associated UUID. + * + * @return + * The UUID of the underlying Guacamole tunnel. + */ + public String getUUID() { + return uuid; + } + +} diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/tunnel/TunnelRESTService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/tunnel/TunnelRESTService.java new file mode 100644 index 000000000..885b17a78 --- /dev/null +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/tunnel/TunnelRESTService.java @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2015 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package org.glyptodon.guacamole.net.basic.rest.tunnel; + +import com.google.inject.Inject; +import java.util.ArrayList; +import java.util.List; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +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.core.MediaType; +import org.glyptodon.guacamole.GuacamoleException; +import org.glyptodon.guacamole.GuacamoleUnsupportedException; +import org.glyptodon.guacamole.net.auth.ConnectionRecord; +import org.glyptodon.guacamole.net.auth.UserContext; +import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure; +import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A REST Service for retrieving and managing the tunnels of active connections. + * + * @author Michael Jumper + */ +@Path("/tunnels") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class TunnelRESTService { + + /** + * Logger for this class. + */ + private static final Logger logger = LoggerFactory.getLogger(TunnelRESTService.class); + + /** + * A service for authenticating users from auth tokens. + */ + @Inject + private AuthenticationService authenticationService; + + /** + * Retrieves the tunnels of all active connections visible to the current + * user. + * + * @param authToken + * The authentication token that is used to authenticate the user + * performing the operation. + * + * @return + * The tunnels of all active connections visible to the current user. + * + * @throws GuacamoleException + * If an error occurs while retrieving the tunnels. + */ + @GET + @Path("/") + @AuthProviderRESTExposure + public List getTunnels(@QueryParam("token") String authToken) + throws GuacamoleException { + + UserContext userContext = authenticationService.getUserContext(authToken); + + // Retrieve all active tunnels + List apiTunnels = new ArrayList(); + for (ConnectionRecord record : userContext.getActiveConnections()) + apiTunnels.add(new APITunnel(record)); + + return apiTunnels; + + } + + /** + * Deletes the tunnel having the given UUID, effectively closing the + * tunnel and killing the associated connection. + * + * @param authToken + * The authentication token that is used to authenticate the user + * performing the operation. + * + * @param tunnelUUID + * The UUID associated with the tunnel being deleted. + * + * @throws GuacamoleException + * If an error occurs while deleting the tunnel. + */ + @DELETE + @Path("/{tunnelUUID}") + @AuthProviderRESTExposure + public void deleteTunnel(@QueryParam("token") String authToken, + @PathParam("tunnelUUID") String tunnelUUID) + throws GuacamoleException { + + UserContext userContext = authenticationService.getUserContext(authToken); + + // STUB + throw new GuacamoleUnsupportedException("STUB"); + + } + +} diff --git a/guacamole/src/main/webapp/app/rest/types/ActiveTunnel.js b/guacamole/src/main/webapp/app/rest/types/ActiveTunnel.js new file mode 100644 index 000000000..e5fe66bc9 --- /dev/null +++ b/guacamole/src/main/webapp/app/rest/types/ActiveTunnel.js @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2015 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * Service which defines the ActiveTunnel class. + */ +angular.module('rest').factory('ActiveTunnel', [function defineActiveTunnel() { + + /** + * The object returned by REST API calls when representing the data + * associated with an active tunnel. Each tunnel denotes an active + * connection, uniquely identified by the tunnel UUID. + * + * @constructor + * @param {ActiveTunnel|Object} [template={}] + * The object whose properties should be copied within the new + * ActiveTunnel. + */ + var ActiveTunnel = function ActiveTunnel(template) { + + // Use empty object by default + template = template || {}; + + /** + * The time that the tunnel began, in seconds since + * 1970-01-01 00:00:00 UTC. + * + * @type Number + */ + this.startDate = template.startDate; + + /** + * The remote host that initiated the tunnel, if known. + * + * @type String + */ + this.remoteHost = template.remoteHost; + + /** + * The username of the user associated with the tunnel. + * + * @type String + */ + this.username = template.username; + + /** + * The UUID which uniquely identifies the tunnel. + * + * @type String + */ + this.uuid = template.uuid; + + }; + + return ActiveTunnel; + +}]); \ No newline at end of file