From 16cd2ab49bdbe6dbd0ecc840aa9a90f24e7bc1ce Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 31 Aug 2015 14:30:00 -0700 Subject: [PATCH] GUAC-586: Use auth provider identifiers within connection REST service. --- .../connection/ConnectionRESTService.java | 72 +++++++++++++++---- .../app/rest/services/connectionService.js | 24 +++---- 2 files changed, 69 insertions(+), 27 deletions(-) diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionRESTService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionRESTService.java index 2f29fbe81..270e3c302 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionRESTService.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionRESTService.java @@ -48,6 +48,7 @@ import org.glyptodon.guacamole.net.auth.permission.ObjectPermission; import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet; import org.glyptodon.guacamole.net.auth.permission.SystemPermission; import org.glyptodon.guacamole.net.auth.permission.SystemPermissionSet; +import org.glyptodon.guacamole.net.basic.GuacamoleSession; import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure; import org.glyptodon.guacamole.net.basic.rest.ObjectRetrievalService; import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService; @@ -60,7 +61,7 @@ import org.slf4j.LoggerFactory; * * @author James Muehlner */ -@Path("/connections") +@Path("/data/{dataSource}/connections") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public class ConnectionRESTService { @@ -89,6 +90,10 @@ public class ConnectionRESTService { * The authentication token that is used to authenticate the user * performing the operation. * + * @param authProviderIdentifier + * The unique identifier of the AuthenticationProvider associated with + * the UserContext containing the connection to be retrieved. + * * @param connectionID * The identifier of the connection to retrieve. * @@ -102,12 +107,14 @@ public class ConnectionRESTService { @Path("/{connectionID}") @AuthProviderRESTExposure public APIConnection getConnection(@QueryParam("token") String authToken, - @PathParam("connectionID") String connectionID) throws GuacamoleException { + @PathParam("dataSource") String authProviderIdentifier, + @PathParam("connectionID") String connectionID) + throws GuacamoleException { - UserContext userContext = authenticationService.getUserContext(authToken); + GuacamoleSession session = authenticationService.getGuacamoleSession(authToken); // Retrieve the requested connection - return new APIConnection(retrievalService.retrieveConnection(userContext, connectionID)); + return new APIConnection(retrievalService.retrieveConnection(session, authProviderIdentifier, connectionID)); } @@ -118,6 +125,11 @@ public class ConnectionRESTService { * The authentication token that is used to authenticate the user * performing the operation. * + * @param authProviderIdentifier + * The unique identifier of the AuthenticationProvider associated with + * the UserContext containing the connection whose parameters are to be + * retrieved. + * * @param connectionID * The identifier of the connection. * @@ -131,9 +143,12 @@ public class ConnectionRESTService { @Path("/{connectionID}/parameters") @AuthProviderRESTExposure public Map getConnectionParameters(@QueryParam("token") String authToken, - @PathParam("connectionID") String connectionID) throws GuacamoleException { + @PathParam("dataSource") String authProviderIdentifier, + @PathParam("connectionID") String connectionID) + throws GuacamoleException { - UserContext userContext = authenticationService.getUserContext(authToken); + GuacamoleSession session = authenticationService.getGuacamoleSession(authToken); + UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier); User self = userContext.self(); // Retrieve permission sets @@ -163,6 +178,11 @@ public class ConnectionRESTService { * The authentication token that is used to authenticate the user * performing the operation. * + * @param authProviderIdentifier + * The unique identifier of the AuthenticationProvider associated with + * the UserContext containing the connection whose history is to be + * retrieved. + * * @param connectionID * The identifier of the connection. * @@ -177,12 +197,14 @@ public class ConnectionRESTService { @Path("/{connectionID}/history") @AuthProviderRESTExposure public List getConnectionHistory(@QueryParam("token") String authToken, - @PathParam("connectionID") String connectionID) throws GuacamoleException { + @PathParam("dataSource") String authProviderIdentifier, + @PathParam("connectionID") String connectionID) + throws GuacamoleException { + + GuacamoleSession session = authenticationService.getGuacamoleSession(authToken); - UserContext userContext = authenticationService.getUserContext(authToken); - // Retrieve the requested connection - Connection connection = retrievalService.retrieveConnection(userContext, connectionID); + Connection connection = retrievalService.retrieveConnection(session, authProviderIdentifier, connectionID); // Retrieve the requested connection's history List apiRecords = new ArrayList(); @@ -201,6 +223,10 @@ public class ConnectionRESTService { * The authentication token that is used to authenticate the user * performing the operation. * + * @param authProviderIdentifier + * The unique identifier of the AuthenticationProvider associated with + * the UserContext containing the connection to be deleted. + * * @param connectionID * The identifier of the connection to delete. * @@ -210,10 +236,13 @@ public class ConnectionRESTService { @DELETE @Path("/{connectionID}") @AuthProviderRESTExposure - public void deleteConnection(@QueryParam("token") String authToken, @PathParam("connectionID") String connectionID) + public void deleteConnection(@QueryParam("token") String authToken, + @PathParam("dataSource") String authProviderIdentifier, + @PathParam("connectionID") String connectionID) throws GuacamoleException { - UserContext userContext = authenticationService.getUserContext(authToken); + GuacamoleSession session = authenticationService.getGuacamoleSession(authToken); + UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier); // Get the connection directory Directory connectionDirectory = userContext.getConnectionDirectory(); @@ -231,6 +260,10 @@ public class ConnectionRESTService { * The authentication token that is used to authenticate the user * performing the operation. * + * @param authProviderIdentifier + * The unique identifier of the AuthenticationProvider associated with + * the UserContext in which the connection is to be created. + * * @param connection * The connection to create. * @@ -244,9 +277,11 @@ public class ConnectionRESTService { @Produces(MediaType.TEXT_PLAIN) @AuthProviderRESTExposure public String createConnection(@QueryParam("token") String authToken, + @PathParam("dataSource") String authProviderIdentifier, APIConnection connection) throws GuacamoleException { - UserContext userContext = authenticationService.getUserContext(authToken); + GuacamoleSession session = authenticationService.getGuacamoleSession(authToken); + UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier); // Validate that connection data was provided if (connection == null) @@ -270,6 +305,10 @@ public class ConnectionRESTService { * The authentication token that is used to authenticate the user * performing the operation. * + * @param authProviderIdentifier + * The unique identifier of the AuthenticationProvider associated with + * the UserContext containing the connection to be updated. + * * @param connectionID * The identifier of the connection to update. * @@ -283,9 +322,12 @@ public class ConnectionRESTService { @Path("/{connectionID}") @AuthProviderRESTExposure public void updateConnection(@QueryParam("token") String authToken, - @PathParam("connectionID") String connectionID, APIConnection connection) throws GuacamoleException { + @PathParam("dataSource") String authProviderIdentifier, + @PathParam("connectionID") String connectionID, + APIConnection connection) throws GuacamoleException { - UserContext userContext = authenticationService.getUserContext(authToken); + GuacamoleSession session = authenticationService.getGuacamoleSession(authToken); + UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier); // Validate that connection data was provided if (connection == null) diff --git a/guacamole/src/main/webapp/app/rest/services/connectionService.js b/guacamole/src/main/webapp/app/rest/services/connectionService.js index 2afba2489..cbf40eb81 100644 --- a/guacamole/src/main/webapp/app/rest/services/connectionService.js +++ b/guacamole/src/main/webapp/app/rest/services/connectionService.js @@ -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 * of this software and associated documentation files (the "Software"), to deal @@ -48,7 +48,7 @@ angular.module('rest').factory('connectionService', ['$injector', * // Do something with the connection * }); */ - service.getConnection = function getConnection(id) { + service.getConnection = function getConnection(dataSource, id) { // Build HTTP parameters set var httpParameters = { @@ -59,7 +59,7 @@ angular.module('rest').factory('connectionService', ['$injector', return $http({ cache : cacheService.connections, method : 'GET', - url : 'api/connections/' + encodeURIComponent(id), + url : 'api/data/' + encodeURIComponent(dataSource) + '/connections/' + encodeURIComponent(id), params : httpParameters }); @@ -77,7 +77,7 @@ angular.module('rest').factory('connectionService', ['$injector', * A promise which will resolve with an array of * @link{ConnectionHistoryEntry} objects upon success. */ - service.getConnectionHistory = function getConnectionHistory(id) { + service.getConnectionHistory = function getConnectionHistory(dataSource, id) { // Build HTTP parameters set var httpParameters = { @@ -87,7 +87,7 @@ angular.module('rest').factory('connectionService', ['$injector', // Retrieve connection history return $http({ method : 'GET', - url : 'api/connections/' + encodeURIComponent(id) + '/history', + url : 'api/data/' + encodeURIComponent(dataSource) + '/connections/' + encodeURIComponent(id) + '/history', params : httpParameters }); @@ -105,7 +105,7 @@ angular.module('rest').factory('connectionService', ['$injector', * A promise which will resolve with an map of parameter name/value * pairs upon success. */ - service.getConnectionParameters = function getConnectionParameters(id) { + service.getConnectionParameters = function getConnectionParameters(dataSource, id) { // Build HTTP parameters set var httpParameters = { @@ -116,7 +116,7 @@ angular.module('rest').factory('connectionService', ['$injector', return $http({ cache : cacheService.connections, method : 'GET', - url : 'api/connections/' + encodeURIComponent(id) + '/parameters', + url : 'api/data/' + encodeURIComponent(dataSource) + '/connections/' + encodeURIComponent(id) + '/parameters', params : httpParameters }); @@ -135,7 +135,7 @@ angular.module('rest').factory('connectionService', ['$injector', * A promise for the HTTP call which will succeed if and only if the * save operation is successful. */ - service.saveConnection = function saveConnection(connection) { + service.saveConnection = function saveConnection(dataSource, connection) { // Build HTTP parameters set var httpParameters = { @@ -146,7 +146,7 @@ angular.module('rest').factory('connectionService', ['$injector', if (!connection.identifier) { return $http({ method : 'POST', - url : 'api/connections', + url : 'api/data/' + encodeURIComponent(dataSource) + '/connections', params : httpParameters, data : connection }) @@ -162,7 +162,7 @@ angular.module('rest').factory('connectionService', ['$injector', else { return $http({ method : 'PUT', - url : 'api/connections/' + encodeURIComponent(connection.identifier), + url : 'api/data/' + encodeURIComponent(dataSource) + '/connections/' + encodeURIComponent(connection.identifier), params : httpParameters, data : connection }) @@ -185,7 +185,7 @@ angular.module('rest').factory('connectionService', ['$injector', * A promise for the HTTP call which will succeed if and only if the * delete operation is successful. */ - service.deleteConnection = function deleteConnection(connection) { + service.deleteConnection = function deleteConnection(dataSource, connection) { // Build HTTP parameters set var httpParameters = { @@ -195,7 +195,7 @@ angular.module('rest').factory('connectionService', ['$injector', // Delete connection return $http({ method : 'DELETE', - url : 'api/connections/' + encodeURIComponent(connection.identifier), + url : 'api/data/' + encodeURIComponent(dataSource) + '/connections/' + encodeURIComponent(connection.identifier), params : httpParameters })