diff --git a/guacamole/src/main/webapp/scripts/service.js b/guacamole/src/main/webapp/scripts/service.js index 4eacfd713..9b7711569 100644 --- a/guacamole/src/main/webapp/scripts/service.js +++ b/guacamole/src/main/webapp/scripts/service.js @@ -43,6 +43,65 @@ GuacamoleService.Connection = function(protocol, id) { }; +/** + * A basic set of permissions that can be assigned to a user, describing + * whether they can create other users/connections and describing which + * users/connections they have permission to read or modify. + */ +GuacamoleService.PermissionSet = function() { + + /** + * Whether permission to create users is granted. + */ + this.create_user = false; + + /** + * Whether permission to create connections is granted. + */ + this.create_connection = false; + + /** + * Object with a property entry for each readable user. + */ + this.read_user = {}; + + /** + * Object with a property entry for each updatable user. + */ + this.update_user = {}; + + /** + * Object with a property entry for each removable user. + */ + this.remove_user = {}; + + /** + * Object with a property entry for each administerable user. + */ + this.administer_user = {}; + + /** + * Object with a property entry for each readable connection. + */ + this.read_connection = {}; + + /** + * Object with a property entry for each updatable connection. + */ + this.update_connection = {}; + + /** + * Object with a property entry for each removable connection. + */ + this.remove_connection = {}; + + /** + * Object with a property entry for each administerable connection. + */ + this.administer_connection = {}; + +}; + /** * Collection of service functions which deal with connections. Each function * makes an explicit HTTP query to the server, and parses the response. @@ -182,4 +241,151 @@ GuacamoleService.Users = { } -}; \ No newline at end of file +}; + +/** + * Collection of service functions which deal with permissions. Each function + * makes an explicit HTTP query to the server, and parses the response. + */ +GuacamoleService.Permissions = { + + /** + * Returns a PermissionSet describing the permissions given to a + * specified user. + * + * @param {String} username The username of the user to list permissions + * of. + * @param {String} parameters Any parameters which should be passed to the + * server for the sake of authentication + * (optional). + * @return {GuacamoleService.PermissionSet} A PermissionSet describing the + * permissions given to the + * specified user. + */ + "list" : function(username, parameters) { + + // Construct request URL + var list_url = "permissions?user=" + encodeURIComponent(username); + if (parameters) list_url += "&" + parameters; + + // Get permission list + var xhr = new XMLHttpRequest(); + xhr.open("GET", list_url, false); + xhr.send(null); + + // If fail, throw error + if (xhr.status != 200) + throw new Error(xhr.statusText); + + // Otherwise, build PermissionSet + var i, type, name; + var permissions = new GuacamoleService.PermissionSet(); + + // Read connections permissions + var connectionsElements = xhr.responseXML.getElementsByTagName("connections"); + for (i=0; i