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 index 279500ba1..ca1a0604c 100644 --- 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 @@ -63,13 +63,16 @@ public class APITunnel { * * @param record * The record to copy data from. + * + * @param uuid + * The UUID of the associated GuacamoleTunnel. */ - public APITunnel(ConnectionRecord record) { + public APITunnel(ConnectionRecord record, String uuid) { this.identifier = record.getIdentifier(); this.startDate = record.getStartDate(); this.remoteHost = record.getRemoteHost(); this.username = record.getUsername(); - this.uuid = "STUB"; // STUB + this.uuid = 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 index 885b17a78..231f8586a 100644 --- 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 @@ -34,7 +34,9 @@ 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.GuacamoleResourceNotFoundException; import org.glyptodon.guacamole.GuacamoleUnsupportedException; +import org.glyptodon.guacamole.net.GuacamoleTunnel; import org.glyptodon.guacamole.net.auth.ConnectionRecord; import org.glyptodon.guacamole.net.auth.UserContext; import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure; @@ -62,7 +64,7 @@ public class TunnelRESTService { */ @Inject private AuthenticationService authenticationService; - + /** * Retrieves the tunnels of all active connections visible to the current * user. @@ -87,8 +89,14 @@ public class TunnelRESTService { // Retrieve all active tunnels List apiTunnels = new ArrayList(); - for (ConnectionRecord record : userContext.getActiveConnections()) - apiTunnels.add(new APITunnel(record)); + for (ConnectionRecord record : userContext.getActiveConnections()) { + + // Locate associated tunnel and UUID + GuacamoleTunnel tunnel = record.getTunnel(); + if (tunnel != null) + apiTunnels.add(new APITunnel(record, tunnel.getUUID().toString())); + + } return apiTunnels; @@ -117,9 +125,16 @@ public class TunnelRESTService { UserContext userContext = authenticationService.getUserContext(authToken); - // STUB - throw new GuacamoleUnsupportedException("STUB"); - + // Retrieve specified tunnel + ConnectionRecord record = userContext.getActiveConnection(tunnelUUID); + if (record == null) + throw new GuacamoleResourceNotFoundException("No such tunnel: \"" + tunnelUUID + "\""); + + // Close tunnel, if not already closed + GuacamoleTunnel tunnel = record.getTunnel(); + if (tunnel != null && tunnel.isOpen()) + tunnel.close(); + } }