mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +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 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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user