GUAC-932: Remove use of localStorageUtility where possible. Use cookies for auth data.

This commit is contained in:
Michael Jumper
2014-11-30 03:31:46 -08:00
parent 4d1e604759
commit fee75204bd
12 changed files with 55 additions and 50 deletions

View File

@@ -23,4 +23,4 @@
/** /**
* The module for authentication and management of tokens. * The module for authentication and management of tokens.
*/ */
angular.module('auth', ['util']); angular.module('auth', ['ngCookies']);

View File

@@ -23,12 +23,13 @@
/** /**
* A service for authenticating a user against the REST API. * A service for authenticating a user against the REST API.
*/ */
angular.module('auth').factory('authenticationService', ['$http', '$injector', angular.module('auth').factory('authenticationService', ['$http', '$cookieStore',
function authenticationService($http, $injector) { function authenticationService($http, $cookieStore) {
var localStorageUtility = $injector.get("localStorageUtility");
var service = {}; var service = {};
var AUTH_COOKIE_ID = "GUAC_AUTH";
/** /**
* Makes a request to authenticate a user using the token REST API endpoint, * Makes a request to authenticate a user using the token REST API endpoint,
* returning a promise that can be used for processing the results of the call. * returning a promise that can be used for processing the results of the call.
@@ -49,8 +50,10 @@ angular.module('auth').factory('authenticationService', ['$http', '$injector',
password: password password: password
}) })
}).success(function success(data, status, headers, config) { }).success(function success(data, status, headers, config) {
localStorageUtility.set('authToken', data.authToken); $cookieStore.put(AUTH_COOKIE_ID, {
localStorageUtility.set('userID', data.userID); authToken : data.authToken,
userID : data.userID
});
}); });
}; };
@@ -73,7 +76,8 @@ angular.module('auth').factory('authenticationService', ['$http', '$injector',
* @returns {String} The user ID of the current user. * @returns {String} The user ID of the current user.
*/ */
service.getCurrentUserID = function getCurrentUserID() { service.getCurrentUserID = function getCurrentUserID() {
return localStorageUtility.get('userID'); var authData = $cookieStore.get(AUTH_COOKIE_ID);
return authData && authData.userID;
}; };
/** /**
@@ -83,7 +87,8 @@ angular.module('auth').factory('authenticationService', ['$http', '$injector',
* @returns {String} The auth token associated with the current user. * @returns {String} The auth token associated with the current user.
*/ */
service.getCurrentToken = function getCurrentToken() { service.getCurrentToken = function getCurrentToken() {
return localStorageUtility.get('authToken'); var authData = $cookieStore.get(AUTH_COOKIE_ID);
return authData && authData.authToken;
}; };
return service; return service;

View File

@@ -23,4 +23,4 @@
/** /**
* The module for code used to connect to a connection or balancing group. * The module for code used to connect to a connection or balancing group.
*/ */
angular.module('client', []); angular.module('client', ['auth']);

View File

@@ -122,12 +122,12 @@ angular.module('client').directive('guacClient', [function guacClient() {
*/ */
var touchPad = new Guacamole.Mouse.Touchpad(displayContainer); var touchPad = new Guacamole.Mouse.Touchpad(displayContainer);
var $window = $injector.get('$window'), var $window = $injector.get('$window'),
guacAudio = $injector.get('guacAudio'), guacAudio = $injector.get('guacAudio'),
guacVideo = $injector.get('guacVideo'), guacVideo = $injector.get('guacVideo'),
guacTunnelFactory = $injector.get('guacTunnelFactory'), guacTunnelFactory = $injector.get('guacTunnelFactory'),
guacClientFactory = $injector.get('guacClientFactory'), guacClientFactory = $injector.get('guacClientFactory'),
localStorageUtility = $injector.get('localStorageUtility'); authenticationService = $injector.get('authenticationService');
/** /**
* Updates the scale of the attached Guacamole.Client based on current window * Updates the scale of the attached Guacamole.Client based on current window
@@ -175,7 +175,7 @@ angular.module('client').directive('guacClient', [function guacClient() {
// Build base connect string // Build base connect string
var connectString = var connectString =
"id=" + encodeURIComponent($scope.id) "id=" + encodeURIComponent($scope.id)
+ "&authToken=" + encodeURIComponent(localStorageUtility.get('authToken')) + "&authToken=" + encodeURIComponent(authenticationService.getCurrentToken())
+ "&width=" + Math.floor(optimal_width) + "&width=" + Math.floor(optimal_width)
+ "&height=" + Math.floor(optimal_height) + "&height=" + Math.floor(optimal_height)
+ "&dpi=" + Math.floor(optimal_dpi) + "&dpi=" + Math.floor(optimal_dpi)

View File

@@ -23,4 +23,4 @@
/** /**
* The module for code relating to connections. * The module for code relating to connections.
*/ */
angular.module('connection', ['util']); angular.module('connection', ['auth']);

View File

@@ -23,8 +23,8 @@
/** /**
* The DAO for connection operations agains the REST API. * The DAO for connection operations agains the REST API.
*/ */
angular.module('connection').factory('connectionDAO', ['$http', 'localStorageUtility', angular.module('connection').factory('connectionDAO', ['$http', 'authenticationService',
function connectionDAO($http, localStorageUtility) { function connectionDAO($http, authenticationService) {
var service = {}; var service = {};
@@ -36,7 +36,7 @@ angular.module('connection').factory('connectionDAO', ['$http', 'localStorageUti
* @returns {promise} A promise for the HTTP call. * @returns {promise} A promise for the HTTP call.
*/ */
service.getConnection = function getConnection(id) { service.getConnection = function getConnection(id) {
return $http.get("api/connection/" + id + "?token=" + localStorageUtility.get('authToken')); return $http.get("api/connection/" + id + "?token=" + authenticationService.getCurrentToken());
}; };
/** /**
@@ -55,7 +55,7 @@ angular.module('connection').factory('connectionDAO', ['$http', 'localStorageUti
if(parentID !== undefined) if(parentID !== undefined)
parentIDParam = "&parentID=" + parentID; parentIDParam = "&parentID=" + parentID;
return $http.get("api/connection?token=" + localStorageUtility.get('authToken') + parentIDParam); return $http.get("api/connection?token=" + authenticationService.getCurrentToken() + parentIDParam);
}; };
/** /**
@@ -74,7 +74,7 @@ angular.module('connection').factory('connectionDAO', ['$http', 'localStorageUti
// This is a new connection // This is a new connection
if(!connectionToSave.identifier) { if(!connectionToSave.identifier) {
return $http.post("api/connection/?token=" + localStorageUtility.get('authToken'), connectionToSave).success( return $http.post("api/connection/?token=" + authenticationService.getCurrentToken(), connectionToSave).success(
function setConnectionID(connectionID){ function setConnectionID(connectionID){
// Set the identifier on the new connection // Set the identifier on the new connection
connection.identifier = connectionID; connection.identifier = connectionID;
@@ -83,7 +83,7 @@ angular.module('connection').factory('connectionDAO', ['$http', 'localStorageUti
} else { } else {
return $http.post( return $http.post(
"api/connection/" + connectionToSave.identifier + "api/connection/" + connectionToSave.identifier +
"?token=" + localStorageUtility.get('authToken'), "?token=" + authenticationService.getCurrentToken(),
connectionToSave); connectionToSave);
} }
}; };
@@ -100,7 +100,7 @@ angular.module('connection').factory('connectionDAO', ['$http', 'localStorageUti
return $http.put( return $http.put(
"api/connection/" + connection.identifier + "api/connection/" + connection.identifier +
"?token=" + localStorageUtility.get('authToken') + "?token=" + authenticationService.getCurrentToken() +
"&parentID=" + connection.parentIdentifier, "&parentID=" + connection.parentIdentifier,
connection); connection);
@@ -117,7 +117,7 @@ angular.module('connection').factory('connectionDAO', ['$http', 'localStorageUti
service.deleteConnection = function deleteConnection(connection) { service.deleteConnection = function deleteConnection(connection) {
return $http['delete']( return $http['delete'](
"api/connection/" + connection.identifier + "api/connection/" + connection.identifier +
"?token=" + localStorageUtility.get('authToken')); "?token=" + authenticationService.getCurrentToken());
}; };
return service; return service;

View File

@@ -23,4 +23,4 @@
/** /**
* The module for code relating to connection groups. * The module for code relating to connection groups.
*/ */
angular.module('connectionGroup', ['util', 'connection']); angular.module('connectionGroup', ['auth', 'util', 'connection']);

View File

@@ -23,8 +23,8 @@
/** /**
* The DAO for connection group operations agains the REST API. * The DAO for connection group operations agains the REST API.
*/ */
angular.module('connectionGroup').factory('connectionGroupDAO', ['$http', 'localStorageUtility', angular.module('connectionGroup').factory('connectionGroupDAO', ['$http', 'authenticationService',
function connectionGrouDAO($http, localStorageUtility) { function connectionGrouDAO($http, authenticationService) {
/** /**
* The ID of the root connection group. * The ID of the root connection group.
@@ -49,7 +49,7 @@ angular.module('connectionGroup').factory('connectionGroupDAO', ['$http', 'local
if(parentID !== undefined) if(parentID !== undefined)
parentIDParam = "&parentID=" + parentID; parentIDParam = "&parentID=" + parentID;
return $http.get("api/connectionGroup?token=" + localStorageUtility.get('authToken') + parentIDParam); return $http.get("api/connectionGroup?token=" + authenticationService.getCurrentToken() + parentIDParam);
}; };
/** /**
@@ -67,7 +67,7 @@ angular.module('connectionGroup').factory('connectionGroupDAO', ['$http', 'local
// 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 || ROOT_CONNECTION_GROUP_ID; connectionGroupID = connectionGroupID || ROOT_CONNECTION_GROUP_ID;
return $http.get("api/connectionGroup/" + connectionGroupID + "?token=" + localStorageUtility.get('authToken')); return $http.get("api/connectionGroup/" + connectionGroupID + "?token=" + authenticationService.getCurrentToken());
}; };
/** /**
@@ -81,7 +81,7 @@ angular.module('connectionGroup').factory('connectionGroupDAO', ['$http', 'local
service.saveConnectionGroup = function saveConnectionGroup(connectionGroup) { service.saveConnectionGroup = function saveConnectionGroup(connectionGroup) {
// This is a new connection group // This is a new connection group
if(!connectionGroup.identifier) { if(!connectionGroup.identifier) {
return $http.post("api/connectionGroup/?token=" + localStorageUtility.get('authToken'), connectionGroup).success( return $http.post("api/connectionGroup/?token=" + authenticationService.getCurrentToken(), connectionGroup).success(
function setConnectionGroupID(connectionGroupID){ function setConnectionGroupID(connectionGroupID){
// Set the identifier on the new connection // Set the identifier on the new connection
connectionGroup.identifier = connectionGroupID; connectionGroup.identifier = connectionGroupID;
@@ -90,7 +90,7 @@ angular.module('connectionGroup').factory('connectionGroupDAO', ['$http', 'local
} else { } else {
return $http.post( return $http.post(
"api/connectionGroup/" + connectionGroup.identifier + "api/connectionGroup/" + connectionGroup.identifier +
"?token=" + localStorageUtility.get('authToken'), "?token=" + authenticationService.getCurrentToken(),
connectionGroup); connectionGroup);
} }
}; };
@@ -107,7 +107,7 @@ angular.module('connectionGroup').factory('connectionGroupDAO', ['$http', 'local
return $http.put( return $http.put(
"api/connectionGroup/" + connectionGroup.identifier + "api/connectionGroup/" + connectionGroup.identifier +
"?token=" + localStorageUtility.get('authToken') + "?token=" + authenticationService.getCurrentToken() +
"&parentID=" + connectionGroup.parentIdentifier, "&parentID=" + connectionGroup.parentIdentifier,
connectionGroup); connectionGroup);
}; };
@@ -123,7 +123,7 @@ angular.module('connectionGroup').factory('connectionGroupDAO', ['$http', 'local
service.deleteConnectionGroup = function deleteConnectionGroup(connectionGroup) { service.deleteConnectionGroup = function deleteConnectionGroup(connectionGroup) {
return $http['delete']( return $http['delete'](
"api/connectionGroup/" + connectionGroup.identifier + "api/connectionGroup/" + connectionGroup.identifier +
"?token=" + localStorageUtility.get('authToken')); "?token=" + authenticationService.getCurrentToken());
}; };
return service; return service;

View File

@@ -23,4 +23,4 @@
/** /**
* A module for code relating to permissions. * A module for code relating to permissions.
*/ */
angular.module('permission', []); angular.module('permission', ['auth']);

View File

@@ -23,8 +23,8 @@
/** /**
* The DAO for permission operations agains the REST API. * The DAO for permission operations agains the REST API.
*/ */
angular.module('permission').factory('permissionDAO', ['$http', 'localStorageUtility', angular.module('permission').factory('permissionDAO', ['$http', 'authenticationService',
function permissionDAO($http, localStorageUtility) { function permissionDAO($http, authenticationService) {
var service = {}; var service = {};
@@ -37,7 +37,7 @@ angular.module('permission').factory('permissionDAO', ['$http', 'localStorageUti
* @returns {promise} A promise for the HTTP call. * @returns {promise} A promise for the HTTP call.
*/ */
service.getPermissions = function getPermissions(userID) { service.getPermissions = function getPermissions(userID) {
return $http.get("api/permission/" + userID + "/?token=" + localStorageUtility.get('authToken')); return $http.get("api/permission/" + userID + "/?token=" + authenticationService.getCurrentToken());
}; };
/** /**
@@ -50,7 +50,7 @@ angular.module('permission').factory('permissionDAO', ['$http', 'localStorageUti
* @returns {promise} A promise for the HTTP call. * @returns {promise} A promise for the HTTP call.
*/ */
service.addPermission = function addPermission(userID, permission) { service.addPermission = function addPermission(userID, permission) {
return $http.post("api/permission/" + userID + "/?token=" + localStorageUtility.get('authToken'), permission); return $http.post("api/permission/" + userID + "/?token=" + authenticationService.getCurrentToken(), permission);
}; };
@@ -65,7 +65,7 @@ angular.module('permission').factory('permissionDAO', ['$http', 'localStorageUti
* @returns {promise} A promise for the HTTP call. * @returns {promise} A promise for the HTTP call.
*/ */
service.removePermission = function removePermission(userID, permission) { service.removePermission = function removePermission(userID, permission) {
return $http.post("api/permission/remove/" + userID + "/?token=" + localStorageUtility.get('authToken'), permission); return $http.post("api/permission/remove/" + userID + "/?token=" + authenticationService.getCurrentToken(), permission);
}; };
@@ -103,7 +103,7 @@ angular.module('permission').factory('permissionDAO', ['$http', 'localStorageUti
// Make the HTTP call // Make the HTTP call
return $http({ return $http({
method : 'PATCH', method : 'PATCH',
url : "api/permission/?token=" + localStorageUtility.get('authToken'), url : "api/permission/?token=" + authenticationService.getCurrentToken(),
data : permissionPatch data : permissionPatch
}); });
} }

View File

@@ -23,8 +23,8 @@
/** /**
* The DAO for connection operations agains the REST API. * The DAO for connection operations agains the REST API.
*/ */
angular.module('user').factory('userDAO', ['$http', 'localStorageUtility', angular.module('user').factory('userDAO', ['$http', 'authenticationService',
function userDAO($http, localStorageUtility) { function userDAO($http, authenticationService) {
var service = {}; var service = {};
@@ -35,7 +35,7 @@ angular.module('user').factory('userDAO', ['$http', 'localStorageUtility',
* @returns {promise} A promise for the HTTP call. * @returns {promise} A promise for the HTTP call.
*/ */
service.getUsers = function getUsers() { service.getUsers = function getUsers() {
return $http.get("api/user?token=" + localStorageUtility.get('authToken')); return $http.get("api/user?token=" + authenticationService.getCurrentToken());
}; };
/** /**
@@ -47,7 +47,7 @@ angular.module('user').factory('userDAO', ['$http', 'localStorageUtility',
* @returns {promise} A promise for the HTTP call. * @returns {promise} A promise for the HTTP call.
*/ */
service.getUser = function getUser(userID) { service.getUser = function getUser(userID) {
return $http.get("api/user/" + userID + "/?token=" + localStorageUtility.get('authToken')); return $http.get("api/user/" + userID + "/?token=" + authenticationService.getCurrentToken());
}; };
/** /**
@@ -61,7 +61,7 @@ angular.module('user').factory('userDAO', ['$http', 'localStorageUtility',
service.deleteUser = function deleteUser(user) { service.deleteUser = function deleteUser(user) {
return $http['delete']( return $http['delete'](
"api/user/" + user.username + "api/user/" + user.username +
"?token=" + localStorageUtility.get('authToken')); "?token=" + authenticationService.getCurrentToken());
}; };
@@ -76,7 +76,7 @@ angular.module('user').factory('userDAO', ['$http', 'localStorageUtility',
service.createUser = function createUser(user) { service.createUser = function createUser(user) {
return $http.post( return $http.post(
"api/user/" "api/user/"
+ "?token=" + localStorageUtility.get('authToken'), + "?token=" + authenticationService.getCurrentToken(),
user user
); );
} }
@@ -92,7 +92,7 @@ angular.module('user').factory('userDAO', ['$http', 'localStorageUtility',
service.saveUser = function saveUser(user) { service.saveUser = function saveUser(user) {
return $http.post( return $http.post(
"api/user/" + user.username + "api/user/" + user.username +
"?token=" + localStorageUtility.get('authToken'), "?token=" + authenticationService.getCurrentToken(),
user); user);
}; };

View File

@@ -23,4 +23,4 @@
/** /**
* A module for code relating to users. * A module for code relating to users.
*/ */
angular.module('user', []); angular.module('user', ['auth']);