GUAC-932: Require auth token for listing protocols. Clean style of JS and Java.

This commit is contained in:
Michael Jumper
2014-12-18 01:10:43 -08:00
parent 993fbef86d
commit dc9d9da8d2
2 changed files with 39 additions and 8 deletions

View File

@@ -24,14 +24,15 @@ package org.glyptodon.guacamole.net.basic.rest.protocol;
import com.google.inject.Inject;
import java.util.Map;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.net.basic.ProtocolInfo;
import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure;
import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,9 +41,8 @@ import org.slf4j.LoggerFactory;
*
* @author James Muehlner
*/
@Path("/protocol")
@Path("/protocols")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class ProtocolRESTService {
/**
@@ -50,6 +50,12 @@ public class ProtocolRESTService {
*/
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.
*/
@@ -59,15 +65,27 @@ public class ProtocolRESTService {
/**
* Gets a map of protocols defined in the system - protocol name to protocol.
*
* @return The protocol map.
* @throws GuacamoleException If a problem is encountered while listing protocols.
* @param authToken
* 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
@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.
return protocolRetrievalservice.getProtocolMap();
}
}

View File

@@ -23,7 +23,8 @@
/**
* 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 = {};
@@ -37,7 +38,19 @@ angular.module('rest').factory('protocolService', ['$http', function protocolSer
* objects upon success.
*/
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;