mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUAC-1132: Allow batch retrieval/deletion of tunnels.
This commit is contained in:
@@ -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<ConnectionRecord> getActiveConnections(Collection<String> tunnelUUIDs)
|
||||
throws GuacamoleException {
|
||||
return tunnelService.getActiveConnection(getCurrentUser(), tunnelUUID);
|
||||
|
||||
// Look up active connections for each given tunnel UUID
|
||||
Collection<ConnectionRecord> records = new ArrayList<ConnectionRecord>(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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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<ConnectionRecord> getActiveConnections(Collection<String> tunnelUUIDs)
|
||||
throws GuacamoleException;
|
||||
|
||||
}
|
||||
|
@@ -175,9 +175,9 @@ public class SimpleUserContext implements UserContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionRecord getActiveConnection(String tunnelUUID)
|
||||
public Collection<ConnectionRecord> getActiveConnections(Collection<String> tunnelUUID)
|
||||
throws GuacamoleException {
|
||||
return null;
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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<String> tunnelUUIDs)
|
||||
throws GuacamoleException {
|
||||
|
||||
// Attempt to get all requested tunnels
|
||||
UserContext userContext = authenticationService.getUserContext(authToken);
|
||||
Collection<ConnectionRecord> 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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user