diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/UserContext.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/UserContext.java index b28a0c49e..ae06013ec 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/UserContext.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/UserContext.java @@ -28,6 +28,7 @@ import org.glyptodon.guacamole.auth.jdbc.connectiongroup.ConnectionGroupDirector import org.glyptodon.guacamole.auth.jdbc.connection.ConnectionDirectory; import com.google.inject.Inject; import com.google.inject.Provider; +import java.util.ArrayList; import java.util.Collection; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.auth.jdbc.base.RestrictedObject; @@ -130,9 +131,22 @@ public class UserContext extends RestrictedObject } @Override - public ConnectionRecord getActiveConnection(String tunnelUUID) + public Collection getActiveConnections(Collection tunnelUUIDs) throws GuacamoleException { - return tunnelService.getActiveConnection(getCurrentUser(), tunnelUUID); + + // Look up active connections for each given tunnel UUID + Collection records = new ArrayList(tunnelUUIDs.size()); + for (String tunnelUUID : tunnelUUIDs) { + + // Add corresponding record only if it exists + ConnectionRecord record = tunnelService.getActiveConnection(getCurrentUser(), tunnelUUID); + if (record != null) + records.add(record); + + } + + return records; + } } diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/UserContext.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/UserContext.java index 7c52834de..bad5901fe 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/UserContext.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/UserContext.java @@ -113,24 +113,24 @@ public interface UserContext { throws GuacamoleException; /** - * Returns the connection record associated with the active connection - * having the tunnel with the given UUID. The active connection will only + * Returns the connection records associated with the active connections + * having the tunnels with the given UUIDs. An active connection will only * be returned if the current user has access. * - * @param tunnelUUID - * The UUID of the tunnel whose associated connection record should be - * returned. + * @param tunnelUUIDs + * The UUIDs of the tunnels whose associated connection records should + * be returned. * * @return - * The connection record associated with the active connection having - * the tunnel with the given UUID, if any, or null if no such - * connection exists. + * A collection of all connection records associated with the active + * connections having the tunnels with the given UUIDs, if any, or an + * empty collection if no such connections exist. * * @throws GuacamoleException * If an error occurs while reading active connection records, or if * permission is denied. */ - ConnectionRecord getActiveConnection(String tunnelUUID) + Collection getActiveConnections(Collection tunnelUUIDs) throws GuacamoleException; } diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java index 480c79017..3f6b45fe2 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java @@ -175,9 +175,9 @@ public class SimpleUserContext implements UserContext { } @Override - public ConnectionRecord getActiveConnection(String tunnelUUID) + public Collection getActiveConnections(Collection tunnelUUID) throws GuacamoleException { - return null; + return Collections.EMPTY_LIST; } } 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 231f8586a..4713d1166 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 @@ -24,6 +24,7 @@ package org.glyptodon.guacamole.net.basic.rest.tunnel; import com.google.inject.Inject; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -34,8 +35,6 @@ 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; @@ -103,37 +102,38 @@ public class TunnelRESTService { } /** - * Deletes the tunnel having the given UUID, effectively closing the - * tunnel and killing the associated connection. + * Deletes the tunnels having the given UUIDs, effectively closing the + * tunnels and killing the associated connections. * * @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. + * @param tunnelUUIDs + * The UUIDs associated with the tunnels being deleted. * * @throws GuacamoleException - * If an error occurs while deleting the tunnel. + * If an error occurs while deleting the tunnels. */ @DELETE - @Path("/{tunnelUUID}") + @Path("/") @AuthProviderRESTExposure - public void deleteTunnel(@QueryParam("token") String authToken, - @PathParam("tunnelUUID") String tunnelUUID) + public void deleteTunnels(@QueryParam("token") String authToken, + @QueryParam("tunnelUUID") Collection tunnelUUIDs) throws GuacamoleException { + // Attempt to get all requested tunnels UserContext userContext = authenticationService.getUserContext(authToken); + Collection records = userContext.getActiveConnections(tunnelUUIDs); - // Retrieve specified tunnel - ConnectionRecord record = userContext.getActiveConnection(tunnelUUID); - if (record == null) - throw new GuacamoleResourceNotFoundException("No such tunnel: \"" + tunnelUUID + "\""); + // Close each tunnel, if not already closed + for (ConnectionRecord record : records) { - // Close tunnel, if not already closed - GuacamoleTunnel tunnel = record.getTunnel(); - if (tunnel != null && tunnel.isOpen()) - tunnel.close(); + GuacamoleTunnel tunnel = record.getTunnel(); + if (tunnel != null && tunnel.isOpen()) + tunnel.close(); + + } }