mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +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 org.glyptodon.guacamole.auth.jdbc.connection.ConnectionDirectory;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import org.glyptodon.guacamole.GuacamoleException;
|
import org.glyptodon.guacamole.GuacamoleException;
|
||||||
import org.glyptodon.guacamole.auth.jdbc.base.RestrictedObject;
|
import org.glyptodon.guacamole.auth.jdbc.base.RestrictedObject;
|
||||||
@@ -130,9 +131,22 @@ public class UserContext extends RestrictedObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConnectionRecord getActiveConnection(String tunnelUUID)
|
public Collection<ConnectionRecord> getActiveConnections(Collection<String> tunnelUUIDs)
|
||||||
throws GuacamoleException {
|
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;
|
throws GuacamoleException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the connection record associated with the active connection
|
* Returns the connection records associated with the active connections
|
||||||
* having the tunnel with the given UUID. The active connection will only
|
* having the tunnels with the given UUIDs. An active connection will only
|
||||||
* be returned if the current user has access.
|
* be returned if the current user has access.
|
||||||
*
|
*
|
||||||
* @param tunnelUUID
|
* @param tunnelUUIDs
|
||||||
* The UUID of the tunnel whose associated connection record should be
|
* The UUIDs of the tunnels whose associated connection records should
|
||||||
* returned.
|
* be returned.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* The connection record associated with the active connection having
|
* A collection of all connection records associated with the active
|
||||||
* the tunnel with the given UUID, if any, or null if no such
|
* connections having the tunnels with the given UUIDs, if any, or an
|
||||||
* connection exists.
|
* empty collection if no such connections exist.
|
||||||
*
|
*
|
||||||
* @throws GuacamoleException
|
* @throws GuacamoleException
|
||||||
* If an error occurs while reading active connection records, or if
|
* If an error occurs while reading active connection records, or if
|
||||||
* permission is denied.
|
* permission is denied.
|
||||||
*/
|
*/
|
||||||
ConnectionRecord getActiveConnection(String tunnelUUID)
|
Collection<ConnectionRecord> getActiveConnections(Collection<String> tunnelUUIDs)
|
||||||
throws GuacamoleException;
|
throws GuacamoleException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -175,9 +175,9 @@ public class SimpleUserContext implements UserContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConnectionRecord getActiveConnection(String tunnelUUID)
|
public Collection<ConnectionRecord> getActiveConnections(Collection<String> tunnelUUID)
|
||||||
throws GuacamoleException {
|
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 com.google.inject.Inject;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
@@ -34,8 +35,6 @@ import javax.ws.rs.Produces;
|
|||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import org.glyptodon.guacamole.GuacamoleException;
|
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.GuacamoleTunnel;
|
||||||
import org.glyptodon.guacamole.net.auth.ConnectionRecord;
|
import org.glyptodon.guacamole.net.auth.ConnectionRecord;
|
||||||
import org.glyptodon.guacamole.net.auth.UserContext;
|
import org.glyptodon.guacamole.net.auth.UserContext;
|
||||||
@@ -103,34 +102,33 @@ public class TunnelRESTService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the tunnel having the given UUID, effectively closing the
|
* Deletes the tunnels having the given UUIDs, effectively closing the
|
||||||
* tunnel and killing the associated connection.
|
* tunnels and killing the associated connections.
|
||||||
*
|
*
|
||||||
* @param authToken
|
* @param authToken
|
||||||
* The authentication token that is used to authenticate the user
|
* The authentication token that is used to authenticate the user
|
||||||
* performing the operation.
|
* performing the operation.
|
||||||
*
|
*
|
||||||
* @param tunnelUUID
|
* @param tunnelUUIDs
|
||||||
* The UUID associated with the tunnel being deleted.
|
* The UUIDs associated with the tunnels being deleted.
|
||||||
*
|
*
|
||||||
* @throws GuacamoleException
|
* @throws GuacamoleException
|
||||||
* If an error occurs while deleting the tunnel.
|
* If an error occurs while deleting the tunnels.
|
||||||
*/
|
*/
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/{tunnelUUID}")
|
@Path("/")
|
||||||
@AuthProviderRESTExposure
|
@AuthProviderRESTExposure
|
||||||
public void deleteTunnel(@QueryParam("token") String authToken,
|
public void deleteTunnels(@QueryParam("token") String authToken,
|
||||||
@PathParam("tunnelUUID") String tunnelUUID)
|
@QueryParam("tunnelUUID") Collection<String> tunnelUUIDs)
|
||||||
throws GuacamoleException {
|
throws GuacamoleException {
|
||||||
|
|
||||||
|
// Attempt to get all requested tunnels
|
||||||
UserContext userContext = authenticationService.getUserContext(authToken);
|
UserContext userContext = authenticationService.getUserContext(authToken);
|
||||||
|
Collection<ConnectionRecord> records = userContext.getActiveConnections(tunnelUUIDs);
|
||||||
|
|
||||||
// Retrieve specified tunnel
|
// Close each tunnel, if not already closed
|
||||||
ConnectionRecord record = userContext.getActiveConnection(tunnelUUID);
|
for (ConnectionRecord record : records) {
|
||||||
if (record == null)
|
|
||||||
throw new GuacamoleResourceNotFoundException("No such tunnel: \"" + tunnelUUID + "\"");
|
|
||||||
|
|
||||||
// Close tunnel, if not already closed
|
|
||||||
GuacamoleTunnel tunnel = record.getTunnel();
|
GuacamoleTunnel tunnel = record.getTunnel();
|
||||||
if (tunnel != null && tunnel.isOpen())
|
if (tunnel != null && tunnel.isOpen())
|
||||||
tunnel.close();
|
tunnel.close();
|
||||||
@@ -138,3 +136,5 @@ public class TunnelRESTService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user