You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by jm...@apache.org on 2016/08/14 01:27:08 UTC

[5/8] incubator-guacamole-client git commit: GUACAMOLE-78: Store anonymous users' authentication results in memory only. Do not persist via cookie.

GUACAMOLE-78: Store anonymous users' authentication results in memory only. Do not persist via cookie.

Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/225736d2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/225736d2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/225736d2

Branch: refs/heads/master
Commit: 225736d2373c9035083b11198c08993f6e494d1c
Parents: 22b3e26
Author: Michael Jumper <mj...@apache.org>
Authored: Fri Aug 12 14:49:37 2016 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Fri Aug 12 14:49:37 2016 -0700

----------------------------------------------------------------------
 .../app/auth/service/authenticationService.js   | 31 +++++++++++++++++---
 1 file changed, 27 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/225736d2/guacamole/src/main/webapp/app/auth/service/authenticationService.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/auth/service/authenticationService.js b/guacamole/src/main/webapp/app/auth/service/authenticationService.js
index e6fc0d7..74f0570 100644
--- a/guacamole/src/main/webapp/app/auth/service/authenticationService.js
+++ b/guacamole/src/main/webapp/app/auth/service/authenticationService.js
@@ -54,6 +54,14 @@ angular.module('auth').factory('authenticationService', ['$injector',
     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
      * last authentication attempt.
      *
@@ -72,12 +80,17 @@ angular.module('auth').factory('authenticationService', ['$injector',
      */
     var getAuthenticationResult = function getAuthenticationResult() {
 
+        // Use cached result, if any
+        if (cachedResult)
+            return cachedResult;
+
         // Return explicit null if no auth data is currently stored
         var data = $cookieStore.get(AUTH_COOKIE_ID);
         if (!data)
             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) {
 
         // Clear the currently-stored result if the last attempt failed
-        if (!data)
+        if (!data) {
+            cachedResult = null;
             $cookieStore.remove(AUTH_COOKIE_ID);
+        }
 
         // Otherwise store the authentication attempt directly
-        else
-            $cookieStore.put(AUTH_COOKIE_ID, data);
+        else {
+
+            // Always store in cache
+            cachedResult = data;
+
+            // Store cookie ONLY if not anonymous
+            if (data.username !== AuthenticationResult.ANONYMOUS_USERNAME)
+                $cookieStore.put(AUTH_COOKIE_ID, data);
+
+        }
 
     };