GUAC-1132: Implement tunnel REST service.

This commit is contained in:
Michael Jumper
2015-03-17 13:45:55 -07:00
parent 5ce0a3a5a4
commit d0c57a2378
2 changed files with 26 additions and 8 deletions

View File

@@ -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;
} }
/** /**

View File

@@ -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;
@@ -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,8 +125,15 @@ 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();
} }