mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-1132: Implement tunnel REST service.
This commit is contained in:
@@ -63,13 +63,16 @@ public class APITunnel {
|
|||||||
*
|
*
|
||||||
* @param record
|
* @param record
|
||||||
* The record to copy data from.
|
* 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.identifier = record.getIdentifier();
|
||||||
this.startDate = record.getStartDate();
|
this.startDate = record.getStartDate();
|
||||||
this.remoteHost = record.getRemoteHost();
|
this.remoteHost = record.getRemoteHost();
|
||||||
this.username = record.getUsername();
|
this.username = record.getUsername();
|
||||||
this.uuid = "STUB"; // STUB
|
this.uuid = uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -34,7 +34,9 @@ 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.GuacamoleUnsupportedException;
|
||||||
|
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;
|
||||||
import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure;
|
import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure;
|
||||||
@@ -62,7 +64,7 @@ public class TunnelRESTService {
|
|||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
private AuthenticationService authenticationService;
|
private AuthenticationService authenticationService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the tunnels of all active connections visible to the current
|
* Retrieves the tunnels of all active connections visible to the current
|
||||||
* user.
|
* user.
|
||||||
@@ -87,8 +89,14 @@ public class TunnelRESTService {
|
|||||||
|
|
||||||
// Retrieve all active tunnels
|
// Retrieve all active tunnels
|
||||||
List<APITunnel> apiTunnels = new ArrayList<APITunnel>();
|
List<APITunnel> apiTunnels = new ArrayList<APITunnel>();
|
||||||
for (ConnectionRecord record : userContext.getActiveConnections())
|
for (ConnectionRecord record : userContext.getActiveConnections()) {
|
||||||
apiTunnels.add(new APITunnel(record));
|
|
||||||
|
// Locate associated tunnel and UUID
|
||||||
|
GuacamoleTunnel tunnel = record.getTunnel();
|
||||||
|
if (tunnel != null)
|
||||||
|
apiTunnels.add(new APITunnel(record, tunnel.getUUID().toString()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return apiTunnels;
|
return apiTunnels;
|
||||||
|
|
||||||
@@ -117,9 +125,16 @@ public class TunnelRESTService {
|
|||||||
|
|
||||||
UserContext userContext = authenticationService.getUserContext(authToken);
|
UserContext userContext = authenticationService.getUserContext(authToken);
|
||||||
|
|
||||||
// STUB
|
// Retrieve specified tunnel
|
||||||
throw new GuacamoleUnsupportedException("STUB");
|
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user