GUAC-586: Use auth provider identifiers within connection group REST service.

This commit is contained in:
Michael Jumper
2015-08-31 14:30:09 -07:00
parent 16cd2ab49b
commit a6cab24983
2 changed files with 56 additions and 22 deletions

View File

@@ -40,6 +40,7 @@ import org.glyptodon.guacamole.net.auth.ConnectionGroup;
import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.net.auth.Directory;
import org.glyptodon.guacamole.net.auth.UserContext; import org.glyptodon.guacamole.net.auth.UserContext;
import org.glyptodon.guacamole.net.auth.permission.ObjectPermission; import org.glyptodon.guacamole.net.auth.permission.ObjectPermission;
import org.glyptodon.guacamole.net.basic.GuacamoleSession;
import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure; import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure;
import org.glyptodon.guacamole.net.basic.rest.ObjectRetrievalService; import org.glyptodon.guacamole.net.basic.rest.ObjectRetrievalService;
import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService; import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService;
@@ -51,7 +52,7 @@ import org.slf4j.LoggerFactory;
* *
* @author James Muehlner * @author James Muehlner
*/ */
@Path("/connectionGroups") @Path("/data/{dataSource}/connectionGroups")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public class ConnectionGroupRESTService { public class ConnectionGroupRESTService {
@@ -80,6 +81,10 @@ public class ConnectionGroupRESTService {
* The authentication token that is used to authenticate the user * The authentication token that is used to authenticate the user
* performing the operation. * performing the operation.
* *
* @param authProviderIdentifier
* The unique identifier of the AuthenticationProvider associated with
* the UserContext containing the connection group to be retrieved.
*
* @param connectionGroupID * @param connectionGroupID
* The ID of the connection group to retrieve. * The ID of the connection group to retrieve.
* *
@@ -92,13 +97,15 @@ public class ConnectionGroupRESTService {
@GET @GET
@Path("/{connectionGroupID}") @Path("/{connectionGroupID}")
@AuthProviderRESTExposure @AuthProviderRESTExposure
public APIConnectionGroup getConnectionGroup(@QueryParam("token") String authToken, public APIConnectionGroup getConnectionGroup(@QueryParam("token") String authToken,
@PathParam("connectionGroupID") String connectionGroupID) throws GuacamoleException { @PathParam("dataSource") String authProviderIdentifier,
@PathParam("connectionGroupID") String connectionGroupID)
throws GuacamoleException {
UserContext userContext = authenticationService.getUserContext(authToken); GuacamoleSession session = authenticationService.getGuacamoleSession(authToken);
// Retrieve the requested connection group // Retrieve the requested connection group
return new APIConnectionGroup(retrievalService.retrieveConnectionGroup(userContext, connectionGroupID)); return new APIConnectionGroup(retrievalService.retrieveConnectionGroup(session, authProviderIdentifier, connectionGroupID));
} }
@@ -109,6 +116,10 @@ public class ConnectionGroupRESTService {
* The authentication token that is used to authenticate the user * The authentication token that is used to authenticate the user
* performing the operation. * performing the operation.
* *
* @param authProviderIdentifier
* The unique identifier of the AuthenticationProvider associated with
* the UserContext containing the connection group to be retrieved.
*
* @param connectionGroupID * @param connectionGroupID
* The ID of the connection group to retrieve. * The ID of the connection group to retrieve.
* *
@@ -129,11 +140,13 @@ public class ConnectionGroupRESTService {
@Path("/{connectionGroupID}/tree") @Path("/{connectionGroupID}/tree")
@AuthProviderRESTExposure @AuthProviderRESTExposure
public APIConnectionGroup getConnectionGroupTree(@QueryParam("token") String authToken, public APIConnectionGroup getConnectionGroupTree(@QueryParam("token") String authToken,
@PathParam("dataSource") String authProviderIdentifier,
@PathParam("connectionGroupID") String connectionGroupID, @PathParam("connectionGroupID") String connectionGroupID,
@QueryParam("permission") List<ObjectPermission.Type> permissions) @QueryParam("permission") List<ObjectPermission.Type> permissions)
throws GuacamoleException { throws GuacamoleException {
UserContext userContext = authenticationService.getUserContext(authToken); GuacamoleSession session = authenticationService.getGuacamoleSession(authToken);
UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier);
// Retrieve the requested tree, filtering by the given permissions // Retrieve the requested tree, filtering by the given permissions
ConnectionGroup treeRoot = retrievalService.retrieveConnectionGroup(userContext, connectionGroupID); ConnectionGroup treeRoot = retrievalService.retrieveConnectionGroup(userContext, connectionGroupID);
@@ -151,6 +164,10 @@ public class ConnectionGroupRESTService {
* The authentication token that is used to authenticate the user * The authentication token that is used to authenticate the user
* performing the operation. * performing the operation.
* *
* @param authProviderIdentifier
* The unique identifier of the AuthenticationProvider associated with
* the UserContext containing the connection group to be deleted.
*
* @param connectionGroupID * @param connectionGroupID
* The identifier of the connection group to delete. * The identifier of the connection group to delete.
* *
@@ -161,9 +178,12 @@ public class ConnectionGroupRESTService {
@Path("/{connectionGroupID}") @Path("/{connectionGroupID}")
@AuthProviderRESTExposure @AuthProviderRESTExposure
public void deleteConnectionGroup(@QueryParam("token") String authToken, public void deleteConnectionGroup(@QueryParam("token") String authToken,
@PathParam("connectionGroupID") String connectionGroupID) throws GuacamoleException { @PathParam("dataSource") String authProviderIdentifier,
@PathParam("connectionGroupID") String connectionGroupID)
throws GuacamoleException {
UserContext userContext = authenticationService.getUserContext(authToken); GuacamoleSession session = authenticationService.getGuacamoleSession(authToken);
UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier);
// Get the connection group directory // Get the connection group directory
Directory<ConnectionGroup> connectionGroupDirectory = userContext.getConnectionGroupDirectory(); Directory<ConnectionGroup> connectionGroupDirectory = userContext.getConnectionGroupDirectory();
@@ -183,6 +203,10 @@ public class ConnectionGroupRESTService {
* The authentication token that is used to authenticate the user * The authentication token that is used to authenticate the user
* performing the operation. * performing the operation.
* *
* @param authProviderIdentifier
* The unique identifier of the AuthenticationProvider associated with
* the UserContext in which the connection group is to be created.
*
* @param connectionGroup * @param connectionGroup
* The connection group to create. * The connection group to create.
* *
@@ -196,9 +220,11 @@ public class ConnectionGroupRESTService {
@Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN)
@AuthProviderRESTExposure @AuthProviderRESTExposure
public String createConnectionGroup(@QueryParam("token") String authToken, public String createConnectionGroup(@QueryParam("token") String authToken,
@PathParam("dataSource") String authProviderIdentifier,
APIConnectionGroup connectionGroup) throws GuacamoleException { APIConnectionGroup connectionGroup) throws GuacamoleException {
UserContext userContext = authenticationService.getUserContext(authToken); GuacamoleSession session = authenticationService.getGuacamoleSession(authToken);
UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier);
// Validate that connection group data was provided // Validate that connection group data was provided
if (connectionGroup == null) if (connectionGroup == null)
@@ -222,6 +248,10 @@ public class ConnectionGroupRESTService {
* The authentication token that is used to authenticate the user * The authentication token that is used to authenticate the user
* performing the operation. * performing the operation.
* *
* @param authProviderIdentifier
* The unique identifier of the AuthenticationProvider associated with
* the UserContext containing the connection group to be updated.
*
* @param connectionGroupID * @param connectionGroupID
* The identifier of the existing connection group to update. * The identifier of the existing connection group to update.
* *
@@ -235,10 +265,13 @@ public class ConnectionGroupRESTService {
@Path("/{connectionGroupID}") @Path("/{connectionGroupID}")
@AuthProviderRESTExposure @AuthProviderRESTExposure
public void updateConnectionGroup(@QueryParam("token") String authToken, public void updateConnectionGroup(@QueryParam("token") String authToken,
@PathParam("connectionGroupID") String connectionGroupID, APIConnectionGroup connectionGroup) @PathParam("dataSource") String authProviderIdentifier,
@PathParam("connectionGroupID") String connectionGroupID,
APIConnectionGroup connectionGroup)
throws GuacamoleException { throws GuacamoleException {
UserContext userContext = authenticationService.getUserContext(authToken); GuacamoleSession session = authenticationService.getGuacamoleSession(authToken);
UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier);
// Validate that connection group data was provided // Validate that connection group data was provided
if (connectionGroup == null) if (connectionGroup == null)

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2014 Glyptodon LLC * Copyright (C) 2015 Glyptodon LLC
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -28,6 +28,7 @@ angular.module('rest').factory('connectionGroupService', ['$injector',
// Required services // Required services
var $http = $injector.get('$http'); var $http = $injector.get('$http');
var $q = $injector.get('$q');
var authenticationService = $injector.get('authenticationService'); var authenticationService = $injector.get('authenticationService');
var cacheService = $injector.get('cacheService'); var cacheService = $injector.get('cacheService');
@@ -57,7 +58,7 @@ angular.module('rest').factory('connectionGroupService', ['$injector',
* A promise which will resolve with a @link{ConnectionGroup} upon * A promise which will resolve with a @link{ConnectionGroup} upon
* success. * success.
*/ */
service.getConnectionGroupTree = function getConnectionGroupTree(connectionGroupID, permissionTypes) { service.getConnectionGroupTree = function getConnectionGroupTree(dataSource, connectionGroupID, permissionTypes) {
// Use the root connection group ID if no ID is passed in // Use the root connection group ID if no ID is passed in
connectionGroupID = connectionGroupID || ConnectionGroup.ROOT_IDENTIFIER; connectionGroupID = connectionGroupID || ConnectionGroup.ROOT_IDENTIFIER;
@@ -75,12 +76,12 @@ angular.module('rest').factory('connectionGroupService', ['$injector',
return $http({ return $http({
cache : cacheService.connections, cache : cacheService.connections,
method : 'GET', method : 'GET',
url : 'api/connectionGroups/' + encodeURIComponent(connectionGroupID) + '/tree', url : 'api/data/' + encodeURIComponent(dataSource) + '/connectionGroups/' + encodeURIComponent(connectionGroupID) + '/tree',
params : httpParameters params : httpParameters
}); });
}; };
/** /**
* Makes a request to the REST API to get an individual connection group, * Makes a request to the REST API to get an individual connection group,
* returning a promise that provides the corresponding * returning a promise that provides the corresponding
@@ -94,7 +95,7 @@ angular.module('rest').factory('connectionGroupService', ['$injector',
* A promise which will resolve with a @link{ConnectionGroup} upon * A promise which will resolve with a @link{ConnectionGroup} upon
* success. * success.
*/ */
service.getConnectionGroup = function getConnectionGroup(connectionGroupID) { service.getConnectionGroup = function getConnectionGroup(dataSource, connectionGroupID) {
// Use the root connection group ID if no ID is passed in // Use the root connection group ID if no ID is passed in
connectionGroupID = connectionGroupID || ConnectionGroup.ROOT_IDENTIFIER; connectionGroupID = connectionGroupID || ConnectionGroup.ROOT_IDENTIFIER;
@@ -108,7 +109,7 @@ angular.module('rest').factory('connectionGroupService', ['$injector',
return $http({ return $http({
cache : cacheService.connections, cache : cacheService.connections,
method : 'GET', method : 'GET',
url : 'api/connectionGroups/' + encodeURIComponent(connectionGroupID), url : 'api/data/' + encodeURIComponent(dataSource) + '/connectionGroups/' + encodeURIComponent(connectionGroupID),
params : httpParameters params : httpParameters
}); });
@@ -127,7 +128,7 @@ angular.module('rest').factory('connectionGroupService', ['$injector',
* A promise for the HTTP call which will succeed if and only if the * A promise for the HTTP call which will succeed if and only if the
* save operation is successful. * save operation is successful.
*/ */
service.saveConnectionGroup = function saveConnectionGroup(connectionGroup) { service.saveConnectionGroup = function saveConnectionGroup(dataSource, connectionGroup) {
// Build HTTP parameters set // Build HTTP parameters set
var httpParameters = { var httpParameters = {
@@ -138,7 +139,7 @@ angular.module('rest').factory('connectionGroupService', ['$injector',
if (!connectionGroup.identifier) { if (!connectionGroup.identifier) {
return $http({ return $http({
method : 'POST', method : 'POST',
url : 'api/connectionGroups', url : 'api/data/' + encodeURIComponent(dataSource) + '/connectionGroups',
params : httpParameters, params : httpParameters,
data : connectionGroup data : connectionGroup
}) })
@@ -154,7 +155,7 @@ angular.module('rest').factory('connectionGroupService', ['$injector',
else { else {
return $http({ return $http({
method : 'PUT', method : 'PUT',
url : 'api/connectionGroups/' + encodeURIComponent(connectionGroup.identifier), url : 'api/data/' + encodeURIComponent(dataSource) + '/connectionGroups/' + encodeURIComponent(connectionGroup.identifier),
params : httpParameters, params : httpParameters,
data : connectionGroup data : connectionGroup
}) })
@@ -177,7 +178,7 @@ angular.module('rest').factory('connectionGroupService', ['$injector',
* A promise for the HTTP call which will succeed if and only if the * A promise for the HTTP call which will succeed if and only if the
* delete operation is successful. * delete operation is successful.
*/ */
service.deleteConnectionGroup = function deleteConnectionGroup(connectionGroup) { service.deleteConnectionGroup = function deleteConnectionGroup(dataSource, connectionGroup) {
// Build HTTP parameters set // Build HTTP parameters set
var httpParameters = { var httpParameters = {
@@ -187,7 +188,7 @@ angular.module('rest').factory('connectionGroupService', ['$injector',
// Delete connection group // Delete connection group
return $http({ return $http({
method : 'DELETE', method : 'DELETE',
url : 'api/connectionGroups/' + encodeURIComponent(connectionGroup.identifier), url : 'api/data/' + encodeURIComponent(dataSource) + '/connectionGroups/' + encodeURIComponent(connectionGroup.identifier),
params : httpParameters params : httpParameters
}) })