mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-08 14:11:21 +00:00
GUAC-932: Require auth token for listing protocols. Clean style of JS and Java.
This commit is contained in:
@@ -24,14 +24,15 @@ package org.glyptodon.guacamole.net.basic.rest.protocol;
|
|||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.ws.rs.Consumes;
|
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
|
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.net.basic.ProtocolInfo;
|
import org.glyptodon.guacamole.net.basic.ProtocolInfo;
|
||||||
import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure;
|
import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure;
|
||||||
|
import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -40,9 +41,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
*
|
*
|
||||||
* @author James Muehlner
|
* @author James Muehlner
|
||||||
*/
|
*/
|
||||||
@Path("/protocol")
|
@Path("/protocols")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
public class ProtocolRESTService {
|
public class ProtocolRESTService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,6 +50,12 @@ public class ProtocolRESTService {
|
|||||||
*/
|
*/
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ProtocolRESTService.class);
|
private static final Logger logger = LoggerFactory.getLogger(ProtocolRESTService.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A service for authenticating users from auth tokens.
|
||||||
|
*/
|
||||||
|
@Inject
|
||||||
|
private AuthenticationService authenticationService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service for retrieving protocol definitions.
|
* Service for retrieving protocol definitions.
|
||||||
*/
|
*/
|
||||||
@@ -59,15 +65,27 @@ public class ProtocolRESTService {
|
|||||||
/**
|
/**
|
||||||
* Gets a map of protocols defined in the system - protocol name to protocol.
|
* Gets a map of protocols defined in the system - protocol name to protocol.
|
||||||
*
|
*
|
||||||
* @return The protocol map.
|
* @param authToken
|
||||||
* @throws GuacamoleException If a problem is encountered while listing protocols.
|
* The authentication token that is used to authenticate the user
|
||||||
|
* performing the operation.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* A map of protocol information, where each key is the unique name
|
||||||
|
* associated with that protocol.
|
||||||
|
*
|
||||||
|
* @throws GuacamoleException
|
||||||
|
* If an error occurs while retrieving the available protocols.
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@AuthProviderRESTExposure
|
@AuthProviderRESTExposure
|
||||||
public Map<String, ProtocolInfo> getProtocols() throws GuacamoleException {
|
public Map<String, ProtocolInfo> getProtocols(@QueryParam("token") String authToken) throws GuacamoleException {
|
||||||
|
|
||||||
|
// Verify the given auth token is valid
|
||||||
|
authenticationService.getUserContext(authToken);
|
||||||
|
|
||||||
// Get and return a map of all protocols.
|
// Get and return a map of all protocols.
|
||||||
return protocolRetrievalservice.getProtocolMap();
|
return protocolRetrievalservice.getProtocolMap();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,8 @@
|
|||||||
/**
|
/**
|
||||||
* Service for operating on protocol metadata via the REST API.
|
* Service for operating on protocol metadata via the REST API.
|
||||||
*/
|
*/
|
||||||
angular.module('rest').factory('protocolService', ['$http', function protocolService($http) {
|
angular.module('rest').factory('protocolService', ['$http', 'authenticationService',
|
||||||
|
function protocolService($http, authenticationService) {
|
||||||
|
|
||||||
var service = {};
|
var service = {};
|
||||||
|
|
||||||
@@ -37,7 +38,19 @@ angular.module('rest').factory('protocolService', ['$http', function protocolSer
|
|||||||
* objects upon success.
|
* objects upon success.
|
||||||
*/
|
*/
|
||||||
service.getProtocols = function getProtocols() {
|
service.getProtocols = function getProtocols() {
|
||||||
return $http.get("api/protocol");
|
|
||||||
|
// Build HTTP parameters set
|
||||||
|
var httpParameters = {
|
||||||
|
token : authenticationService.getCurrentToken()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Retrieve available protocols
|
||||||
|
return $http({
|
||||||
|
method : 'GET',
|
||||||
|
url : 'api/protocols',
|
||||||
|
params : httpParameters
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
|
Reference in New Issue
Block a user