mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-221: Provide REST API endpoint for retrieving the underlying protocol of a tunnel.
This commit is contained in:
@@ -24,6 +24,7 @@ import com.google.inject.assistedinject.Assisted;
|
|||||||
import com.google.inject.assistedinject.AssistedInject;
|
import com.google.inject.assistedinject.AssistedInject;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.DefaultValue;
|
import javax.ws.rs.DefaultValue;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
@@ -31,8 +32,10 @@ import javax.ws.rs.QueryParam;
|
|||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import org.apache.guacamole.GuacamoleException;
|
import org.apache.guacamole.GuacamoleException;
|
||||||
import org.apache.guacamole.GuacamoleResourceNotFoundException;
|
import org.apache.guacamole.GuacamoleResourceNotFoundException;
|
||||||
|
import org.apache.guacamole.environment.Environment;
|
||||||
import org.apache.guacamole.net.auth.ActiveConnection;
|
import org.apache.guacamole.net.auth.ActiveConnection;
|
||||||
import org.apache.guacamole.net.auth.UserContext;
|
import org.apache.guacamole.net.auth.UserContext;
|
||||||
|
import org.apache.guacamole.protocols.ProtocolInfo;
|
||||||
import org.apache.guacamole.rest.activeconnection.APIActiveConnection;
|
import org.apache.guacamole.rest.activeconnection.APIActiveConnection;
|
||||||
import org.apache.guacamole.rest.directory.DirectoryObjectResource;
|
import org.apache.guacamole.rest.directory.DirectoryObjectResource;
|
||||||
import org.apache.guacamole.rest.directory.DirectoryObjectResourceFactory;
|
import org.apache.guacamole.rest.directory.DirectoryObjectResourceFactory;
|
||||||
@@ -57,6 +60,12 @@ public class TunnelResource {
|
|||||||
*/
|
*/
|
||||||
private final UserTunnel tunnel;
|
private final UserTunnel tunnel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Guacamole server environment.
|
||||||
|
*/
|
||||||
|
@Inject
|
||||||
|
private Environment environment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A factory which can be used to create instances of resources representing
|
* A factory which can be used to create instances of resources representing
|
||||||
* ActiveConnections.
|
* ActiveConnections.
|
||||||
@@ -106,6 +115,39 @@ public class TunnelResource {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the underlying protocol used by the connection associated with
|
||||||
|
* this tunnel. If possible, the parameters available for that protocol are
|
||||||
|
* retrieved, as well.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* A ProtocolInfo object describing the protocol used by the connection
|
||||||
|
* associated with this tunnel.
|
||||||
|
*
|
||||||
|
* @throws GuacamoleException
|
||||||
|
* If the protocol used by the connection associated with this tunnel
|
||||||
|
* cannot be determined.
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("protocol")
|
||||||
|
public ProtocolInfo getProtocol() throws GuacamoleException {
|
||||||
|
|
||||||
|
// Pull protocol name from underlying socket
|
||||||
|
String protocol = tunnel.getSocket().getProtocol();
|
||||||
|
if (protocol == null)
|
||||||
|
throw new GuacamoleResourceNotFoundException("Protocol of tunnel is not known/exposed.");
|
||||||
|
|
||||||
|
// If there is no such protocol defined, provide as much info as is
|
||||||
|
// known (just the name)
|
||||||
|
ProtocolInfo info = environment.getProtocol(protocol);
|
||||||
|
if (info == null)
|
||||||
|
return new ProtocolInfo(protocol);
|
||||||
|
|
||||||
|
// All protocol information for this tunnel is known
|
||||||
|
return info;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Intercepts and returns the entire contents of a specific stream.
|
* Intercepts and returns the entire contents of a specific stream.
|
||||||
*
|
*
|
||||||
|
@@ -79,6 +79,36 @@ angular.module('rest').factory('tunnelService', ['$injector',
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a request to the REST API to retrieve the underlying protocol of
|
||||||
|
* the connection associated with a particular tunnel, returning a promise
|
||||||
|
* that provides a @link{Protocol} object if successful.
|
||||||
|
*
|
||||||
|
* @param {String} tunnel
|
||||||
|
* The UUID of the tunnel associated with the Guacamole connection
|
||||||
|
* whose underlying protocol is being retrieved.
|
||||||
|
*
|
||||||
|
* @returns {Promise.<Protocol>}
|
||||||
|
* A promise which will resolve with a @link{Protocol} object upon
|
||||||
|
* success.
|
||||||
|
*/
|
||||||
|
service.getProtocol = function getProtocol(tunnel) {
|
||||||
|
|
||||||
|
// Build HTTP parameters set
|
||||||
|
var httpParameters = {
|
||||||
|
token : authenticationService.getCurrentToken()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Retrieve the protocol details of the specified tunnel
|
||||||
|
return requestService({
|
||||||
|
method : 'GET',
|
||||||
|
url : 'api/session/tunnels/' + encodeURIComponent(tunnel)
|
||||||
|
+ '/protocol',
|
||||||
|
params : httpParameters
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the set of sharing profiles that the current user can use to
|
* Retrieves the set of sharing profiles that the current user can use to
|
||||||
* share the active connection of the given tunnel.
|
* share the active connection of the given tunnel.
|
||||||
|
Reference in New Issue
Block a user