mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-586: Use auth provider identifiers within active connection REST service.
This commit is contained in:
@@ -30,6 +30,7 @@ import java.util.Map;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
@@ -44,8 +45,10 @@ 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.APIPatch;
|
||||
import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure;
|
||||
import org.glyptodon.guacamole.net.basic.rest.ObjectRetrievalService;
|
||||
import org.glyptodon.guacamole.net.basic.rest.PATCH;
|
||||
import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService;
|
||||
import org.slf4j.Logger;
|
||||
@@ -56,7 +59,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
@Path("/activeConnections")
|
||||
@Path("/data/{dataSource}/activeConnections")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public class ActiveConnectionRESTService {
|
||||
@@ -72,6 +75,12 @@ public class ActiveConnectionRESTService {
|
||||
@Inject
|
||||
private AuthenticationService authenticationService;
|
||||
|
||||
/**
|
||||
* Service for convenient retrieval of objects.
|
||||
*/
|
||||
@Inject
|
||||
private ObjectRetrievalService retrievalService;
|
||||
|
||||
/**
|
||||
* Gets a list of active connections in the system, filtering the returned
|
||||
* list by the given permissions, if specified.
|
||||
@@ -80,6 +89,10 @@ public class ActiveConnectionRESTService {
|
||||
* 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 active connections to be retrieved.
|
||||
*
|
||||
* @param permissions
|
||||
* The set of permissions to filter with. A user must have one or more
|
||||
* of these permissions for a user to appear in the result.
|
||||
@@ -96,10 +109,12 @@ public class ActiveConnectionRESTService {
|
||||
@GET
|
||||
@AuthProviderRESTExposure
|
||||
public Map<String, APIActiveConnection> getActiveConnections(@QueryParam("token") String authToken,
|
||||
@PathParam("dataSource") String authProviderIdentifier,
|
||||
@QueryParam("permission") List<ObjectPermission.Type> permissions)
|
||||
throws GuacamoleException {
|
||||
|
||||
UserContext userContext = authenticationService.getUserContext(authToken);
|
||||
GuacamoleSession session = authenticationService.getGuacamoleSession(authToken);
|
||||
UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier);
|
||||
User self = userContext.self();
|
||||
|
||||
// Do not filter on permissions if no permissions are specified
|
||||
@@ -140,6 +155,10 @@ public class ActiveConnectionRESTService {
|
||||
* 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 active connections to be deleted.
|
||||
*
|
||||
* @param patches
|
||||
* The active connection patches to apply for this request.
|
||||
*
|
||||
@@ -149,9 +168,11 @@ public class ActiveConnectionRESTService {
|
||||
@PATCH
|
||||
@AuthProviderRESTExposure
|
||||
public void patchTunnels(@QueryParam("token") String authToken,
|
||||
@PathParam("dataSource") String authProviderIdentifier,
|
||||
List<APIPatch<String>> patches) throws GuacamoleException {
|
||||
|
||||
UserContext userContext = authenticationService.getUserContext(authToken);
|
||||
GuacamoleSession session = authenticationService.getGuacamoleSession(authToken);
|
||||
UserContext userContext = retrievalService.retrieveUserContext(session, authProviderIdentifier);
|
||||
|
||||
// Get the directory
|
||||
Directory<ActiveConnection> activeConnectionDirectory = userContext.getActiveConnectionDirectory();
|
||||
|
@@ -23,8 +23,13 @@
|
||||
/**
|
||||
* Service for operating on active connections via the REST API.
|
||||
*/
|
||||
angular.module('rest').factory('activeConnectionService', ['$http', 'authenticationService',
|
||||
function activeConnectionService($http, authenticationService) {
|
||||
angular.module('rest').factory('activeConnectionService', ['$injector',
|
||||
function activeConnectionService($injector) {
|
||||
|
||||
// Required services
|
||||
var $http = $injector.get('$http');
|
||||
var $q = $injector.get('$q');
|
||||
var authenticationService = $injector.get('authenticationService');
|
||||
|
||||
var service = {};
|
||||
|
||||
@@ -39,13 +44,12 @@ angular.module('rest').factory('activeConnectionService', ['$http', 'authenticat
|
||||
* result. If null, no filtering will be performed. Valid values are
|
||||
* listed within PermissionSet.ObjectType.
|
||||
*
|
||||
|
||||
* @returns {Promise.<Object.<String, ActiveConnection>>}
|
||||
* A promise which will resolve with a map of @link{ActiveConnection}
|
||||
* objects, where each key is the identifier of the corresponding
|
||||
* active connection.
|
||||
*/
|
||||
service.getActiveConnections = function getActiveConnections(permissionTypes) {
|
||||
service.getActiveConnections = function getActiveConnections(dataSource, permissionTypes) {
|
||||
|
||||
// Build HTTP parameters set
|
||||
var httpParameters = {
|
||||
@@ -59,12 +63,74 @@ angular.module('rest').factory('activeConnectionService', ['$http', 'authenticat
|
||||
// Retrieve tunnels
|
||||
return $http({
|
||||
method : 'GET',
|
||||
url : 'api/activeConnections',
|
||||
url : 'api/data/' + encodeURIComponent(dataSource) + '/activeConnections',
|
||||
params : httpParameters
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a promise which resolves with all active connections accessible
|
||||
* by the current user, as a map of @link{ActiveConnection} maps, as would
|
||||
* be returned by getActiveConnections(), grouped by the identifier of
|
||||
* their corresponding data source. All given data sources are queried. If
|
||||
* an error occurs while retrieving any ActiveConnection map, the promise
|
||||
* will be rejected.
|
||||
*
|
||||
* @param {String[]} dataSources
|
||||
* The unique identifier of the data sources containing the active
|
||||
* connections to be retrieved. These identifiers correspond to
|
||||
* AuthenticationProviders within the Guacamole web application.
|
||||
*
|
||||
* @param {String[]} [permissionTypes]
|
||||
* The set of permissions to filter with. A user must have one or more
|
||||
* of these permissions for an active connection to appear in the
|
||||
* result. If null, no filtering will be performed. Valid values are
|
||||
* listed within PermissionSet.ObjectType.
|
||||
*
|
||||
* @returns {Promise.<Object.<String, Object.<String, ActiveConnection>>>}
|
||||
* A promise which resolves with all active connections available to
|
||||
* the current user, as a map of ActiveConnection maps, as would be
|
||||
* returned by getActiveConnections(), grouped by the identifier of
|
||||
* their corresponding data source.
|
||||
*/
|
||||
service.getAllActiveConnections = function getAllActiveConnections(dataSources, permissionTypes) {
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
var activeConnectionRequests = [];
|
||||
var activeConnectionMaps = {};
|
||||
|
||||
// Retrieve all active connections from all data sources
|
||||
angular.forEach(dataSources, function retrieveActiveConnections(dataSource) {
|
||||
activeConnectionRequests.push(
|
||||
service.getActiveConnections(dataSource, permissionTypes)
|
||||
.success(function activeConnectionsRetrieved(activeConnections) {
|
||||
activeConnectionMaps[dataSource] = activeConnections;
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
// Resolve when all requests are completed
|
||||
$q.all(activeConnectionRequests)
|
||||
.then(
|
||||
|
||||
// All requests completed successfully
|
||||
function allActiveConnectionsRetrieved() {
|
||||
deferred.resolve(userArrays);
|
||||
},
|
||||
|
||||
// At least one request failed
|
||||
function activeConnectionRetrievalFailed(e) {
|
||||
deferred.reject(e);
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
return deferred.promise;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to delete the active connections having
|
||||
* the given identifiers, effectively disconnecting them, returning a
|
||||
@@ -77,7 +143,7 @@ angular.module('rest').factory('activeConnectionService', ['$http', 'authenticat
|
||||
* A promise for the HTTP call which will succeed if and only if the
|
||||
* delete operation is successful.
|
||||
*/
|
||||
service.deleteActiveConnections = function deleteActiveConnections(identifiers) {
|
||||
service.deleteActiveConnections = function deleteActiveConnections(dataSource, identifiers) {
|
||||
|
||||
// Build HTTP parameters set
|
||||
var httpParameters = {
|
||||
@@ -96,7 +162,7 @@ angular.module('rest').factory('activeConnectionService', ['$http', 'authenticat
|
||||
// Perform active connection deletion via PATCH
|
||||
return $http({
|
||||
method : 'PATCH',
|
||||
url : 'api/activeConnections',
|
||||
url : 'api/data/' + encodeURIComponent(dataSource) + '/activeConnections',
|
||||
params : httpParameters,
|
||||
data : activeConnectionPatch
|
||||
});
|
||||
|
Reference in New Issue
Block a user