mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-10 07:01:21 +00:00
GUAC-932: Refactor existing REST service JS into single 'rest' module.
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The DAO for connection group operations agains the REST API.
|
||||
*/
|
||||
angular.module('rest').factory('connectionGroupDAO', ['$http', 'authenticationService',
|
||||
function connectionGrouDAO($http, authenticationService) {
|
||||
|
||||
/**
|
||||
* The ID of the root connection group.
|
||||
*/
|
||||
var ROOT_CONNECTION_GROUP_ID = "ROOT";
|
||||
|
||||
var service = {};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to get the list of connection groups,
|
||||
* returning a promise that can be used for processing the results of the call.
|
||||
*
|
||||
* @param {string} parentID The parent ID for the connection group.
|
||||
* If not passed in, it will query a list of the
|
||||
* connection groups in the root group.
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.getConnectionGroups = function getConnectionGroups(parentID) {
|
||||
|
||||
var parentIDParam = "";
|
||||
if(parentID !== undefined)
|
||||
parentIDParam = "&parentID=" + parentID;
|
||||
|
||||
return $http.get("api/connectionGroup?token=" + authenticationService.getCurrentToken() + parentIDParam);
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to get an individual connection group,
|
||||
* returning a promise that can be used for processing the results of the call.
|
||||
*
|
||||
* @param {string} connectionGroupID The ID for the connection group.
|
||||
* If not passed in, it will query the
|
||||
* root connection group.
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.getConnectionGroup = function getConnectionGroup(connectionGroupID) {
|
||||
|
||||
// Use the root connection group ID if no ID is passed in
|
||||
connectionGroupID = connectionGroupID || ROOT_CONNECTION_GROUP_ID;
|
||||
|
||||
return $http.get("api/connectionGroup/" + connectionGroupID + "?token=" + authenticationService.getCurrentToken());
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to save a connection group,
|
||||
* returning a promise that can be used for processing the results of the call.
|
||||
*
|
||||
* @param {object} connectionGroup The connection group to update
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.saveConnectionGroup = function saveConnectionGroup(connectionGroup) {
|
||||
// This is a new connection group
|
||||
if(!connectionGroup.identifier) {
|
||||
return $http.post("api/connectionGroup/?token=" + authenticationService.getCurrentToken(), connectionGroup).success(
|
||||
function setConnectionGroupID(connectionGroupID){
|
||||
// Set the identifier on the new connection
|
||||
connectionGroup.identifier = connectionGroupID;
|
||||
return connectionGroupID;
|
||||
});
|
||||
} else {
|
||||
return $http.post(
|
||||
"api/connectionGroup/" + connectionGroup.identifier +
|
||||
"?token=" + authenticationService.getCurrentToken(),
|
||||
connectionGroup);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to move a connection group to a different group,
|
||||
* returning a promise that can be used for processing the results of the call.
|
||||
*
|
||||
* @param {object} connectionGroup The connection group to move.
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.moveConnectionGroup = function moveConnectionGroup(connectionGroup) {
|
||||
|
||||
return $http.put(
|
||||
"api/connectionGroup/" + connectionGroup.identifier +
|
||||
"?token=" + authenticationService.getCurrentToken() +
|
||||
"&parentID=" + connectionGroup.parentIdentifier,
|
||||
connectionGroup);
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to delete a connection group,
|
||||
* returning a promise that can be used for processing the results of the call.
|
||||
*
|
||||
* @param {object} connectionGroup The connection group to delete
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.deleteConnectionGroup = function deleteConnectionGroup(connectionGroup) {
|
||||
return $http['delete'](
|
||||
"api/connectionGroup/" + connectionGroup.identifier +
|
||||
"?token=" + authenticationService.getCurrentToken());
|
||||
};
|
||||
|
||||
return service;
|
||||
}]);
|
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A service for performing useful connection group related functionaltiy.
|
||||
*/
|
||||
angular.module('rest').factory('connectionGroupService', ['$injector', function connectionGroupService($injector) {
|
||||
|
||||
var connectionGroupDAO = $injector.get('connectionGroupDAO');
|
||||
var connectionService = $injector.get('connectionService');
|
||||
var permissionCheckService = $injector.get('permissionCheckService');
|
||||
var $q = $injector.get('$q');
|
||||
var displayObjectPreparationService = $injector.get('displayObjectPreparationService');
|
||||
|
||||
var service = {};
|
||||
|
||||
// Add all groups from this group to the parent group child list
|
||||
function addToParent(connectionGroup, parentGroup, context, includeConnections) {
|
||||
|
||||
// Include connections by default
|
||||
if(typeof includeConnections === 'undefined')
|
||||
includeConnections = true;
|
||||
|
||||
parentGroup.children.push(connectionGroup);
|
||||
|
||||
// Prepare this group for display
|
||||
displayObjectPreparationService.prepareConnectionGroup(connectionGroup);
|
||||
|
||||
if(includeConnections) {
|
||||
// Get all connections in the group and add them under this connection group
|
||||
context.openRequest();
|
||||
connectionService.getConnections(connectionGroup.identifier).success(function fetchConnections(connections) {
|
||||
for(var i = 0; i < connections.length; i++) {
|
||||
connections[i].isConnection = true;
|
||||
connectionGroup.children.push(connections[i]);
|
||||
}
|
||||
context.closeRequest();
|
||||
});
|
||||
}
|
||||
|
||||
// Get all connection groups in the group and repeat
|
||||
context.openRequest();
|
||||
connectionGroupDAO.getConnectionGroups(connectionGroup.identifier).success(function fetchConnectionGroups(connectionGroups) {
|
||||
for(var i = 0; i < connectionGroups.length; i++) {
|
||||
addToParent(connectionGroups[i], connectionGroup, context, includeConnections);
|
||||
}
|
||||
context.closeRequest();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries all connections and connection groups under the connection group
|
||||
* with the provided parent ID, and returns them in a heirarchical structure
|
||||
* with convinient display properties set on the objects.
|
||||
*
|
||||
* @param {array} items The root list of connections and groups. Should be an
|
||||
* initally empty array that will get filled in as the
|
||||
* connections and groups are loaded.
|
||||
*
|
||||
* @param {string} parentID The parent ID for the connection group.
|
||||
* If not passed in, it will begin with
|
||||
* the root connection group.
|
||||
*
|
||||
* @param {boolean} includeConnections Whether or not to include connections
|
||||
* in the structure. Defaults to true.
|
||||
*
|
||||
* @param {boolean} includeRoot Whether or not to include the root connection group
|
||||
* in the structure. Defaults to false.
|
||||
*
|
||||
* @return {promise} A promise that will be fulfilled when all connections
|
||||
* and groups have been loaded.
|
||||
*/
|
||||
service.getAllGroupsAndConnections = function getAllGroupsAndConnections(items, parentID, includeConnections, includeRoot) {
|
||||
|
||||
// Include connections by default
|
||||
if(typeof includeConnections === 'undefined')
|
||||
includeConnections = true;
|
||||
|
||||
var context = {
|
||||
// The number of requets to the server currently open
|
||||
openRequests : 0,
|
||||
|
||||
// Create the promise
|
||||
finishedFetching : $q.defer(),
|
||||
|
||||
// Notify the caller that the promise has been completed
|
||||
complete : function complete() {
|
||||
this.finishedFetching.resolve(items);
|
||||
},
|
||||
|
||||
/**
|
||||
* Indicate that a request has been started.
|
||||
*/
|
||||
openRequest : function openRequest() {
|
||||
this.openRequests++;
|
||||
},
|
||||
|
||||
/**
|
||||
* Indicate that a request has been completed. If this was the last
|
||||
* open request, fulfill the promise.
|
||||
*/
|
||||
closeRequest : function closeRequest() {
|
||||
if(--this.openRequests === 0)
|
||||
this.complete();
|
||||
}
|
||||
};
|
||||
|
||||
// Include the root only if it was asked for
|
||||
if(includeRoot) {
|
||||
context.openRequest();
|
||||
connectionGroupDAO.getConnectionGroup(parentID).success(function setRootGroup (rootGroup) {
|
||||
items.push(rootGroup);
|
||||
rootGroup.children = [];
|
||||
getChildrenOfRootGroup(rootGroup.children);
|
||||
context.closeRequest();
|
||||
});
|
||||
} else {
|
||||
getChildrenOfRootGroup(items);
|
||||
}
|
||||
|
||||
// Get the children of the root group
|
||||
function getChildrenOfRootGroup(children) {
|
||||
context.openRequest();
|
||||
connectionGroupDAO.getConnectionGroups(parentID).success(function fetchRootConnectionGroups(connectionGroups) {
|
||||
for(var i = 0; i < connectionGroups.length; i++) {
|
||||
addToParent(connectionGroups[i], {children: children}, context, includeConnections);
|
||||
}
|
||||
|
||||
if(includeConnections) {
|
||||
// Get all connections in the root group and add them under this connection group
|
||||
context.openRequest();
|
||||
connectionService.getConnections().success(function fetchRootConnections(connections) {
|
||||
for(var i = 0; i < connections.length; i++) {
|
||||
|
||||
// Prepare this connection for display
|
||||
displayObjectPreparationService.prepareConnection(connections[i]);
|
||||
|
||||
children.push(connections[i]);
|
||||
}
|
||||
context.closeRequest();
|
||||
});
|
||||
}
|
||||
|
||||
context.closeRequest();
|
||||
});
|
||||
}
|
||||
|
||||
// Return the promise
|
||||
return context.finishedFetching.promise;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Filters the list of connections and groups using the provided permissions.
|
||||
*
|
||||
* @param {array} items The heirarchical list of groups and connections.
|
||||
*
|
||||
* @param {object} permissionList The list of permissions to use
|
||||
* when filtering.
|
||||
*
|
||||
* @param {object} permissionCriteria A map of object type to permission type(s)
|
||||
* required for that object type.
|
||||
*
|
||||
* @return {array} The filtered list.
|
||||
*/
|
||||
service.filterConnectionsAndGroupByPermission = function filterConnectionsAndGroupByPermission(items, permissionList, permissionCriteria) {
|
||||
var requiredConnectionPermission = permissionCriteria.CONNECTION;
|
||||
var requiredConnectionGroupPermission = permissionCriteria.CONNECTION_GROUP;
|
||||
|
||||
for(var i = 0; i < items.length; i++) {
|
||||
var item = items[i];
|
||||
|
||||
if(item.isConnection && requiredConnectionPermission) {
|
||||
|
||||
/*
|
||||
* If item is a connection and a permission is required for this
|
||||
* item, check now to see if the permission exists. If not,
|
||||
* remove the item.
|
||||
*/
|
||||
if(!permissionCheckService.checkPermission(permissionList,
|
||||
"CONNECTION", item.identifier, requiredConnectionPermission)) {
|
||||
items.splice(i, 1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
/*
|
||||
* If item is a group and a permission is required for this
|
||||
* item, check now to see if the permission exists. If not,
|
||||
* remove the item.
|
||||
*/
|
||||
if(requiredConnectionGroupPermission) {
|
||||
if(!permissionCheckService.checkPermission(permissionList,
|
||||
"CONNECTION_GROUP", item.identifier, requiredConnectionGroupPermission)) {
|
||||
items.splice(i, 1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter the children of this connection group as well
|
||||
if(item.children && item.children.length)
|
||||
service.filterConnectionsAndGroupByPermission(items.children);
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
|
||||
};
|
||||
|
||||
return service;
|
||||
}]);
|
148
guacamole/src/main/webapp/app/rest/services/connectionService.js
Normal file
148
guacamole/src/main/webapp/app/rest/services/connectionService.js
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Service for operating on connections via the REST API.
|
||||
*/
|
||||
angular.module('rest').factory('connectionService', ['$http', 'authenticationService',
|
||||
function connectionService($http, authenticationService) {
|
||||
|
||||
var service = {};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to get a single connection, returning a
|
||||
* promise that provides the corresponding @link{Connection} if successful.
|
||||
*
|
||||
* @param {String} id The ID of the connection.
|
||||
* @returns {Promise.<Connection>}
|
||||
* A promise which will resolve with a @link{Connection} upon success.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* connectionService.getConnection('myConnection').success(function(connection) {
|
||||
* // Do something with the connection
|
||||
* });
|
||||
*/
|
||||
service.getConnection = function getConnection(id) {
|
||||
return $http.get("api/connection/" + id + "?token=" + authenticationService.getCurrentToken());
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to get the list of connections,
|
||||
* returning a promise that can be used for processing the results of the
|
||||
* call.
|
||||
*
|
||||
* @param {string} parentID The parent ID for the connection.
|
||||
* If not passed in, it will query a list of the
|
||||
* connections in the root group.
|
||||
*
|
||||
* @returns {Promise.<Connection[]>}
|
||||
* A promise which will resolve with an array of @link{Connection}
|
||||
* objects upon success.
|
||||
*/
|
||||
service.getConnections = function getConnections(parentID) {
|
||||
|
||||
var parentIDParam = "";
|
||||
if(parentID !== undefined)
|
||||
parentIDParam = "&parentID=" + parentID;
|
||||
|
||||
return $http.get("api/connection?token=" + authenticationService.getCurrentToken() + parentIDParam);
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to save a connection, returning a
|
||||
* promise that can be used for processing the results of the call.
|
||||
*
|
||||
* @param {Connection} connection The connection to update
|
||||
*
|
||||
* @returns {Promise}
|
||||
* A promise for the HTTP call which will succeed if and only if the
|
||||
* save operation is successful.
|
||||
*/
|
||||
service.saveConnection = function saveConnection(connection) {
|
||||
|
||||
/*
|
||||
* FIXME: This should not be necessary. Perhaps the need for this is a
|
||||
* sign that history should be queried separately, and not reside as
|
||||
* part of the connection object?
|
||||
*/
|
||||
// Do not try to save the connection history records
|
||||
var connectionToSave = angular.copy(connection);
|
||||
delete connectionToSave.history;
|
||||
|
||||
// This is a new connection
|
||||
if(!connectionToSave.identifier) {
|
||||
return $http.post("api/connection/?token=" + authenticationService.getCurrentToken(), connectionToSave).success(
|
||||
function setConnectionID(connectionID){
|
||||
// Set the identifier on the new connection
|
||||
connection.identifier = connectionID; // FIXME: Functions with side effects = bad
|
||||
return connectionID; // FIXME: Why? Where does this value go?
|
||||
});
|
||||
} else {
|
||||
return $http.post(
|
||||
"api/connection/" + connectionToSave.identifier +
|
||||
"?token=" + authenticationService.getCurrentToken(),
|
||||
connectionToSave);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* FIXME: Why is this different from save?
|
||||
*
|
||||
* Makes a request to the REST API to move a connection to a different
|
||||
* group, returning a promise that can be used for processing the results
|
||||
* of the call.
|
||||
*
|
||||
* @param {Connection} connection The connection to move.
|
||||
*
|
||||
* @returns {Promise}
|
||||
* A promise for the HTTP call which will succeed if and only if the
|
||||
* move operation is successful.
|
||||
*/
|
||||
service.moveConnection = function moveConnection(connection) {
|
||||
|
||||
return $http.put(
|
||||
"api/connection/" + connection.identifier +
|
||||
"?token=" + authenticationService.getCurrentToken() +
|
||||
"&parentID=" + connection.parentIdentifier,
|
||||
connection);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to delete a connection,
|
||||
* returning a promise that can be used for processing the results of the call.
|
||||
*
|
||||
* @param {Connection} connection The connection to delete
|
||||
*
|
||||
* @returns {Promise}
|
||||
* A promise for the HTTP call which will succeed if and only if the
|
||||
* delete operation is successful.
|
||||
*/
|
||||
service.deleteConnection = function deleteConnection(connection) {
|
||||
return $http['delete'](
|
||||
"api/connection/" + connection.identifier +
|
||||
"?token=" + authenticationService.getCurrentToken());
|
||||
};
|
||||
|
||||
return service;
|
||||
}]);
|
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A service for checking if a specific permission exists
|
||||
* in a given list of permissions.
|
||||
*/
|
||||
angular.module('rest').factory('permissionCheckService', [
|
||||
function permissionCheckService() {
|
||||
|
||||
var service = {};
|
||||
|
||||
/**
|
||||
* A service for checking if the given permission list contains the given
|
||||
* permission, defined by the objectType, objectID, and permissionType.
|
||||
* If the objectType or objectID are not passed, they will not be checked.
|
||||
*
|
||||
* For example, checkPermission(list, "CONNECTION", undefined, "READ") would
|
||||
* check if the permission list contains permission to read any connection.
|
||||
*
|
||||
* @param {array} permissions The array of permissions to check.
|
||||
* @param {string} objectType The object type for the permission.
|
||||
* If not passed, this will not be checked.
|
||||
* @param {string} objectID The ID of the object the permission is for.
|
||||
* If not passed, this will not be checked.
|
||||
* @param {string} permissionType The actual permission type to check for.
|
||||
* @returns {boolean} True if the given permissions contain the requested permission, false otherwise.
|
||||
*/
|
||||
service.checkPermission = function checkPermission(permissions, objectType, objectID, permissionType) {
|
||||
|
||||
// Loop through all the permissions and check if any of them match the given parameters
|
||||
for(var i = 0; i < permissions.length; i++) {
|
||||
var permission = permissions[i];
|
||||
|
||||
if(objectType === "SYSTEM") {
|
||||
// System permissions have no object ID, we only need to check the type.
|
||||
if(permission.permissionType === permissionType)
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
// Object permissions need to match the object ID and type if given.
|
||||
if(permission.permissionType === permissionType &&
|
||||
(!objectType || permission.objectType === objectType) &&
|
||||
(!objectID || permission.objectID === objectID))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Didn't find any that matched
|
||||
return false;
|
||||
}
|
||||
|
||||
return service;
|
||||
}]);
|
115
guacamole/src/main/webapp/app/rest/services/permissionDAO.js
Normal file
115
guacamole/src/main/webapp/app/rest/services/permissionDAO.js
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The DAO for permission operations agains the REST API.
|
||||
*/
|
||||
angular.module('rest').factory('permissionDAO', ['$http', 'authenticationService',
|
||||
function permissionDAO($http, authenticationService) {
|
||||
|
||||
var service = {};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to get the list of permissions for a given user,
|
||||
* returning a promise that can be used for processing the results of the call.
|
||||
*
|
||||
* @param {string} userID The ID of the user to retrieve the permissions for.
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.getPermissions = function getPermissions(userID) {
|
||||
return $http.get("api/permission/" + userID + "/?token=" + authenticationService.getCurrentToken());
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to add a permission for a given user,
|
||||
* returning a promise that can be used for processing the results of the call.
|
||||
*
|
||||
* @param {string} userID The ID of the user to add the permission for.
|
||||
* @param {object} permission The permission to add.
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.addPermission = function addPermission(userID, permission) {
|
||||
return $http.post("api/permission/" + userID + "/?token=" + authenticationService.getCurrentToken(), permission);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to remove a permission for a given user,
|
||||
* returning a promise that can be used for processing the results of the call.
|
||||
*
|
||||
* @param {string} userID The ID of the user to remove the permission for.
|
||||
* @param {object} permission The permission to remove.
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.removePermission = function removePermission(userID, permission) {
|
||||
return $http.post("api/permission/remove/" + userID + "/?token=" + authenticationService.getCurrentToken(), permission);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to modify the permissions for a given user,
|
||||
* returning a promise that can be used for processing the results of the call.
|
||||
*
|
||||
* @param {string} userID The ID of the user to remove the permission for.
|
||||
* @param {array} permissionsToAdd The permissions to add.
|
||||
* @param {array} permissionsToRemove The permissions to remove.
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.patchPermissions = function patchPermissions(userID, permissionsToAdd, permissionsToRemove) {
|
||||
var permissionPatch = [];
|
||||
|
||||
// Add all the add operations to the patch
|
||||
for(var i = 0; i < permissionsToAdd.length; i++ ) {
|
||||
permissionPatch.push({
|
||||
op : "add",
|
||||
path : userID,
|
||||
value : permissionsToAdd[i]
|
||||
});
|
||||
}
|
||||
|
||||
// Add all the remove operations to the patch
|
||||
for(var i = 0; i < permissionsToRemove.length; i++ ) {
|
||||
permissionPatch.push({
|
||||
op : "remove",
|
||||
path : userID,
|
||||
value : permissionsToRemove[i]
|
||||
});
|
||||
}
|
||||
|
||||
// Make the HTTP call
|
||||
return $http({
|
||||
method : 'PATCH',
|
||||
url : "api/permission/?token=" + authenticationService.getCurrentToken(),
|
||||
data : permissionPatch
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return service;
|
||||
}]);
|
41
guacamole/src/main/webapp/app/rest/services/protocolDAO.js
Normal file
41
guacamole/src/main/webapp/app/rest/services/protocolDAO.js
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The DAO for protocol operations agains the REST API.
|
||||
*/
|
||||
angular.module('rest').factory('protocolDAO', ['$http', function protocolDAO($http) {
|
||||
|
||||
var service = {};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to get the list of protocols,
|
||||
* returning a promise that can be used for processing the results of the call.
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.getProtocols = function getProtocols() {
|
||||
return $http.get("api/protocol");
|
||||
};
|
||||
|
||||
return service;
|
||||
}]);
|
100
guacamole/src/main/webapp/app/rest/services/userDAO.js
Normal file
100
guacamole/src/main/webapp/app/rest/services/userDAO.js
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The DAO for connection operations agains the REST API.
|
||||
*/
|
||||
angular.module('rest').factory('userDAO', ['$http', 'authenticationService',
|
||||
function userDAO($http, authenticationService) {
|
||||
|
||||
var service = {};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to get the list of users,
|
||||
* returning a promise that can be used for processing the results of the call.
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.getUsers = function getUsers() {
|
||||
return $http.get("api/user?token=" + authenticationService.getCurrentToken());
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to get the list of users,
|
||||
* returning a promise that can be used for processing the results of the call.
|
||||
*
|
||||
* @param {string} userID The ID of the user to retrieve.
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.getUser = function getUser(userID) {
|
||||
return $http.get("api/user/" + userID + "/?token=" + authenticationService.getCurrentToken());
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to delete a user,
|
||||
* returning a promise that can be used for processing the results of the call.
|
||||
*
|
||||
* @param {object} user The user to delete.
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.deleteUser = function deleteUser(user) {
|
||||
return $http['delete'](
|
||||
"api/user/" + user.username +
|
||||
"?token=" + authenticationService.getCurrentToken());
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to create a user,
|
||||
* returning a promise that can be used for processing the results of the call.
|
||||
*
|
||||
* @param {object} user The user to create.
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.createUser = function createUser(user) {
|
||||
return $http.post(
|
||||
"api/user/"
|
||||
+ "?token=" + authenticationService.getCurrentToken(),
|
||||
user
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to save a user,
|
||||
* returning a promise that can be used for processing the results of the call.
|
||||
*
|
||||
* @param {object} user The user to update.
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.saveUser = function saveUser(user) {
|
||||
return $http.post(
|
||||
"api/user/" + user.username +
|
||||
"?token=" + authenticationService.getCurrentToken(),
|
||||
user);
|
||||
};
|
||||
|
||||
return service;
|
||||
}]);
|
57
guacamole/src/main/webapp/app/rest/services/userService.js
Normal file
57
guacamole/src/main/webapp/app/rest/services/userService.js
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A service for performing useful user related functionaltiy.
|
||||
*/
|
||||
angular.module('rest').factory('userService', ['$injector', function userService($injector) {
|
||||
|
||||
var permissionCheckService = $injector.get('permissionCheckService');
|
||||
|
||||
var service = {};
|
||||
|
||||
/**
|
||||
* Filters the list of users using the provided permissions.
|
||||
*
|
||||
* @param {array} users The user list.
|
||||
*
|
||||
* @param {object} permissionList The list of permissions to use
|
||||
* when filtering.
|
||||
*
|
||||
* @param {object} permissionCriteria The required permission for each user.
|
||||
*
|
||||
* @return {array} The filtered list.
|
||||
*/
|
||||
service.filterUsersByPermission = function filterUsersByPermission(users, permissionList, permissionCriteria) {
|
||||
for(var i = 0; i < users.length; i++) {
|
||||
if(!permissionCheckService.checkPermission(permissionList,
|
||||
"USER", user.username, permissionCriteria)) {
|
||||
items.splice(i, 1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return users;
|
||||
};
|
||||
|
||||
return service;
|
||||
}]);
|
Reference in New Issue
Block a user