mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +00:00
GUACAMOLE-78: Store anonymous users' authentication results in memory only. Do not persist via cookie.
This commit is contained in:
@@ -53,6 +53,14 @@ angular.module('auth').factory('authenticationService', ['$injector',
|
|||||||
|
|
||||||
var service = {};
|
var service = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The most recent authentication result, or null if no authentication
|
||||||
|
* result is cached.
|
||||||
|
*
|
||||||
|
* @type AuthenticationResult
|
||||||
|
*/
|
||||||
|
var cachedResult = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The unique identifier of the local cookie which stores the result of the
|
* The unique identifier of the local cookie which stores the result of the
|
||||||
* last authentication attempt.
|
* last authentication attempt.
|
||||||
@@ -72,12 +80,17 @@ angular.module('auth').factory('authenticationService', ['$injector',
|
|||||||
*/
|
*/
|
||||||
var getAuthenticationResult = function getAuthenticationResult() {
|
var getAuthenticationResult = function getAuthenticationResult() {
|
||||||
|
|
||||||
|
// Use cached result, if any
|
||||||
|
if (cachedResult)
|
||||||
|
return cachedResult;
|
||||||
|
|
||||||
// Return explicit null if no auth data is currently stored
|
// Return explicit null if no auth data is currently stored
|
||||||
var data = $cookieStore.get(AUTH_COOKIE_ID);
|
var data = $cookieStore.get(AUTH_COOKIE_ID);
|
||||||
if (!data)
|
if (!data)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return new AuthenticationResult(data);
|
// Update cache and return retrieved auth result
|
||||||
|
return (cachedResult = new AuthenticationResult(data));
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -92,12 +105,22 @@ angular.module('auth').factory('authenticationService', ['$injector',
|
|||||||
var setAuthenticationResult = function setAuthenticationResult(data) {
|
var setAuthenticationResult = function setAuthenticationResult(data) {
|
||||||
|
|
||||||
// Clear the currently-stored result if the last attempt failed
|
// Clear the currently-stored result if the last attempt failed
|
||||||
if (!data)
|
if (!data) {
|
||||||
|
cachedResult = null;
|
||||||
$cookieStore.remove(AUTH_COOKIE_ID);
|
$cookieStore.remove(AUTH_COOKIE_ID);
|
||||||
|
}
|
||||||
|
|
||||||
// Otherwise store the authentication attempt directly
|
// Otherwise store the authentication attempt directly
|
||||||
else
|
else {
|
||||||
$cookieStore.put(AUTH_COOKIE_ID, data);
|
|
||||||
|
// Always store in cache
|
||||||
|
cachedResult = data;
|
||||||
|
|
||||||
|
// Store cookie ONLY if not anonymous
|
||||||
|
if (data.username !== AuthenticationResult.ANONYMOUS_USERNAME)
|
||||||
|
$cookieStore.put(AUTH_COOKIE_ID, data);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user