You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by vn...@apache.org on 2018/04/20 09:13:17 UTC
[1/5] guacamole-client git commit: GUACAMOLE-549: Add service for
manipulating items within localStorage.
Repository: guacamole-client
Updated Branches:
refs/heads/master aac9d8795 -> 456ad7f28
GUACAMOLE-549: Add service for manipulating items within localStorage.
Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/11d356a7
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/11d356a7
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/11d356a7
Branch: refs/heads/master
Commit: 11d356a70b83668d668af9fdecf337af0009ed81
Parents: aac9d87
Author: Michael Jumper <mj...@apache.org>
Authored: Wed Apr 18 20:42:27 2018 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Wed Apr 18 21:15:11 2018 -0700
----------------------------------------------------------------------
.../app/storage/services/localStorageService.js | 145 +++++++++++++++++++
1 file changed, 145 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/11d356a7/guacamole/src/main/webapp/app/storage/services/localStorageService.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/storage/services/localStorageService.js b/guacamole/src/main/webapp/app/storage/services/localStorageService.js
new file mode 100644
index 0000000..a8c6846
--- /dev/null
+++ b/guacamole/src/main/webapp/app/storage/services/localStorageService.js
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Service for setting, removing, and retrieving localStorage keys. If access
+ * to localStorage is disabled, or the browser does not support localStorage,
+ * key values are temporarily stored in memory instead. If necessary, the same
+ * functionality is also available at the localStorageServiceProvider level.
+ */
+angular.module('storage').provider('localStorageService', [function localStorageServiceProvider() {
+
+ /**
+ * Reference to this provider.
+ *
+ * @type localStorageServiceProvider
+ */
+ var provider = this;
+
+ /**
+ * Internal cache of key/value pairs stored within localStorage, updated
+ * lazily as keys are retrieved, updated, or removed. If localStorage is
+ * not actually available, then this cache will be the sole storage
+ * location for these key/value pairs.
+ *
+ * @type Object.<String, String>
+ */
+ var storedItems = {};
+
+ /**
+ * Stores the given value within localStorage under the given key. If access
+ * to localStorage is not provided/implemented by the browser, the key/value
+ * pair will be stored internally (in memory) only, with the stored value
+ * remaining retrievable via getItem() until the browser tab/window is
+ * closed.
+ *
+ * @param {String} key
+ * The arbitrary, unique key under which the value should be stored.
+ *
+ * @param {Object} value
+ * The object to store under the given key. This may be any object that
+ * can be serialized as JSON, and will automatically be serialized as
+ * JSON prior to storage.
+ */
+ provider.setItem = function setItem(key, value) {
+
+ // Store given value internally
+ var data = JSON.stringify(value);
+ storedItems[key] = data;
+
+ // Additionally store value within localStorage if allowed
+ try {
+ if (window.localStorage)
+ localStorage.setItem(key, data);
+ }
+ catch (ignore) {}
+
+ };
+
+ /**
+ * Removes the item having the given key from localStorage. If access to
+ * localStorage is not provided/implemented by the browser, the item is
+ * removed solely from internal, in-memory storage. If no such item exists,
+ * this function has no effect.
+ *
+ * @param {String} key
+ * The arbitrary, unique key of the item to remove from localStorage.
+ */
+ provider.removeItem = function removeItem(key) {
+
+ // Evict key from internal storage
+ delete storedItems[key];
+
+ // Remove key from localStorage if allowed
+ try {
+ if (window.localStorage)
+ localStorage.removeItem(key);
+ }
+ catch (ignore) {}
+
+ };
+
+ /**
+ * Retrieves the value currently stored within localStorage for the item
+ * having the given key. If access to localStorage is not
+ * provided/implemented by the browser, the item is retrieved from
+ * internal, in-memory storage. The retrieved value is automatically
+ * deserialized from JSON prior to being returned.
+ *
+ * @param {String} key
+ * The arbitrary, unique key of the item to retrieve from localStorage.
+ *
+ * @returns {Object}
+ * The value stored within localStorage under the given key,
+ * automatically deserialized from JSON, or null if no such item is
+ * present.
+ */
+ provider.getItem = function getItem(key) {
+
+ // Attempt to refresh internal storage from localStorage
+ try {
+ if (window.localStorage)
+ storedItems[key] = localStorage.getItem(key);
+ }
+ catch (ignore) {}
+
+ // Pull and parse value from internal storage, if present
+ var data = storedItems[key];
+ if (data)
+ return JSON.parse(data);
+
+ // No value defined for given key
+ return null;
+
+ };
+
+ // Factory method required by provider
+ this.$get = ['$injector', function localStorageServiceFactory($injector) {
+
+ // Pass through all get/set/remove calls to the provider
+ // implementations of the same
+ return {
+ setItem : provider.setItem,
+ removeItem : provider.removeItem,
+ getItem : provider.getItem
+ };
+
+ }];
+
+}]);
[5/5] guacamole-client git commit: GUACAMOLE-549: Merge migrate to
localStorage for storage of auth token.
Posted by vn...@apache.org.
GUACAMOLE-549: Merge migrate to localStorage for storage of auth token.
Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/456ad7f2
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/456ad7f2
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/456ad7f2
Branch: refs/heads/master
Commit: 456ad7f28ee7a506c2e62cbfca01648b49149c67
Parents: aac9d87 884a9c0
Author: Nick Couchman <vn...@apache.org>
Authored: Fri Apr 20 05:12:28 2018 -0400
Committer: Nick Couchman <vn...@apache.org>
Committed: Fri Apr 20 05:12:28 2018 -0400
----------------------------------------------------------------------
guacamole/pom.xml | 6 -
.../src/main/webapp/app/auth/authModule.js | 4 +-
.../app/auth/service/authenticationService.js | 22 +--
.../main/webapp/app/history/historyModule.js | 4 +-
.../webapp/app/history/services/guacHistory.js | 33 ++---
.../app/settings/services/preferenceService.js | 37 ++---
.../main/webapp/app/settings/settingsModule.js | 3 +-
.../app/storage/services/localStorageService.js | 145 +++++++++++++++++++
guacamole/src/main/webapp/index.html | 1 -
9 files changed, 192 insertions(+), 63 deletions(-)
----------------------------------------------------------------------
[2/5] guacamole-client git commit: GUACAMOLE-549: Migrate recent
connection history to localStorageService.
Posted by vn...@apache.org.
GUACAMOLE-549: Migrate recent connection history to localStorageService.
Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/831e4e09
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/831e4e09
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/831e4e09
Branch: refs/heads/master
Commit: 831e4e0989a96f304d848f67de2fb178e8d736f6
Parents: 11d356a
Author: Michael Jumper <mj...@apache.org>
Authored: Wed Apr 18 20:43:04 2018 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Thu Apr 19 12:45:43 2018 -0700
----------------------------------------------------------------------
.../main/webapp/app/history/historyModule.js | 4 ++-
.../webapp/app/history/services/guacHistory.js | 33 +++++++++-----------
2 files changed, 17 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/831e4e09/guacamole/src/main/webapp/app/history/historyModule.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/history/historyModule.js b/guacamole/src/main/webapp/app/history/historyModule.js
index ce2ab73..c7ec7e1 100644
--- a/guacamole/src/main/webapp/app/history/historyModule.js
+++ b/guacamole/src/main/webapp/app/history/historyModule.js
@@ -20,4 +20,6 @@
/**
* The module for code relating to connection history.
*/
-angular.module('history', []);
+angular.module('history', [
+ 'storage'
+]);
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/831e4e09/guacamole/src/main/webapp/app/history/services/guacHistory.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/history/services/guacHistory.js b/guacamole/src/main/webapp/app/history/services/guacHistory.js
index b47f9f5..74046ef 100644
--- a/guacamole/src/main/webapp/app/history/services/guacHistory.js
+++ b/guacamole/src/main/webapp/app/history/services/guacHistory.js
@@ -20,7 +20,14 @@
/**
* A service for reading and manipulating the Guacamole connection history.
*/
-angular.module('history').factory('guacHistory', ['HistoryEntry', function guacHistory(HistoryEntry) {
+angular.module('history').factory('guacHistory', ['$injector',
+ function guacHistory($injector) {
+
+ // Required types
+ var HistoryEntry = $injector.get('HistoryEntry');
+
+ // Required services
+ var localStorageService = $injector.get('localStorageService');
var service = {};
@@ -73,27 +80,15 @@ angular.module('history').factory('guacHistory', ['HistoryEntry', function guacH
if (service.recentConnections.length > IDEAL_LENGTH)
service.recentConnections.length = IDEAL_LENGTH;
- // Save updated history, ignore inability to use localStorage
- try {
- if (localStorage)
- localStorage.setItem(GUAC_HISTORY_STORAGE_KEY, JSON.stringify(service.recentConnections));
- }
- catch (ignore) {}
+ // Save updated history
+ localStorageService.setItem(GUAC_HISTORY_STORAGE_KEY, service.recentConnections);
};
- // Get stored connection history, ignore inability to use localStorage
- try {
-
- if (localStorage) {
- var storedHistory = JSON.parse(localStorage.getItem(GUAC_HISTORY_STORAGE_KEY) || "[]");
- if (storedHistory instanceof Array)
- service.recentConnections = storedHistory;
-
- }
-
- }
- catch (ignore) {}
+ // Init stored connection history from localStorage
+ var storedHistory = localStorageService.getItem(GUAC_HISTORY_STORAGE_KEY) || [];
+ if (storedHistory instanceof Array)
+ service.recentConnections = storedHistory;
return service;
[3/5] guacamole-client git commit: GUACAMOLE-549: Migrate
storage/retrieval of local preferences to localStorageService.
Posted by vn...@apache.org.
GUACAMOLE-549: Migrate storage/retrieval of local preferences to localStorageService.
Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/1686e6f1
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/1686e6f1
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/1686e6f1
Branch: refs/heads/master
Commit: 1686e6f149fb6d3ea80217ed18792d22ded45e6f
Parents: 831e4e0
Author: Michael Jumper <mj...@apache.org>
Authored: Wed Apr 18 20:43:30 2018 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Thu Apr 19 12:49:19 2018 -0700
----------------------------------------------------------------------
.../app/settings/services/preferenceService.js | 37 ++++++++------------
.../main/webapp/app/settings/settingsModule.js | 3 +-
2 files changed, 16 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/1686e6f1/guacamole/src/main/webapp/app/settings/services/preferenceService.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/settings/services/preferenceService.js b/guacamole/src/main/webapp/app/settings/services/preferenceService.js
index 9af4281..bcd8633 100644
--- a/guacamole/src/main/webapp/app/settings/services/preferenceService.js
+++ b/guacamole/src/main/webapp/app/settings/services/preferenceService.js
@@ -21,7 +21,11 @@
* A service for setting and retrieving browser-local preferences. Preferences
* may be any JSON-serializable type.
*/
-angular.module('settings').provider('preferenceService', function preferenceServiceProvider() {
+angular.module('settings').provider('preferenceService', ['$injector',
+ function preferenceServiceProvider($injector) {
+
+ // Required providers
+ var localStorageServiceProvider = $injector.get('localStorageServiceProvider');
/**
* Reference to the provider itself.
@@ -128,24 +132,18 @@ angular.module('settings').provider('preferenceService', function preferenceServ
};
- // Get stored preferences, ignore inability to use localStorage
- try {
-
- if (localStorage) {
- var preferencesJSON = localStorage.getItem(GUAC_PREFERENCES_STORAGE_KEY);
- if (preferencesJSON)
- angular.extend(provider.preferences, JSON.parse(preferencesJSON));
- }
-
- }
- catch (ignore) {}
+ // Get stored preferences from localStorage
+ var storedPreferences = localStorageServiceProvider.getItem(GUAC_PREFERENCES_STORAGE_KEY);
+ if (storedPreferences)
+ angular.extend(provider.preferences, storedPreferences);
// Factory method required by provider
this.$get = ['$injector', function preferenceServiceFactory($injector) {
// Required services
- var $rootScope = $injector.get('$rootScope');
- var $window = $injector.get('$window');
+ var $rootScope = $injector.get('$rootScope');
+ var $window = $injector.get('$window');
+ var localStorageService = $injector.get('localStorageService');
var service = {};
@@ -168,14 +166,7 @@ angular.module('settings').provider('preferenceService', function preferenceServ
* Persists the current values of all preferences, if possible.
*/
service.save = function save() {
-
- // Save updated preferences, ignore inability to use localStorage
- try {
- if (localStorage)
- localStorage.setItem(GUAC_PREFERENCES_STORAGE_KEY, JSON.stringify(service.preferences));
- }
- catch (ignore) {}
-
+ localStorageService.setItem(GUAC_PREFERENCES_STORAGE_KEY, service.preferences);
};
// Persist settings when window is unloaded
@@ -195,4 +186,4 @@ angular.module('settings').provider('preferenceService', function preferenceServ
}];
-});
+}]);
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/1686e6f1/guacamole/src/main/webapp/app/settings/settingsModule.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/settings/settingsModule.js b/guacamole/src/main/webapp/app/settings/settingsModule.js
index 7adc0d1..62ad1c8 100644
--- a/guacamole/src/main/webapp/app/settings/settingsModule.js
+++ b/guacamole/src/main/webapp/app/settings/settingsModule.js
@@ -26,5 +26,6 @@ angular.module('settings', [
'list',
'navigation',
'notification',
- 'rest'
+ 'rest',
+ 'storage'
]);
[4/5] guacamole-client git commit: GUACAMOLE-549: Store auth token
within localStorage rather than cookie.
Posted by vn...@apache.org.
GUACAMOLE-549: Store auth token within localStorage rather than cookie.
Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/884a9c0e
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/884a9c0e
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/884a9c0e
Branch: refs/heads/master
Commit: 884a9c0ee987f9cb49a69ceb17eb0e2267eed058
Parents: 1686e6f
Author: Michael Jumper <mj...@apache.org>
Authored: Wed Apr 18 20:44:08 2018 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Thu Apr 19 12:49:19 2018 -0700
----------------------------------------------------------------------
guacamole/pom.xml | 6 ------
.../src/main/webapp/app/auth/authModule.js | 4 +++-
.../app/auth/service/authenticationService.js | 22 ++++++++++----------
guacamole/src/main/webapp/index.html | 1 -
4 files changed, 14 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/884a9c0e/guacamole/pom.xml
----------------------------------------------------------------------
diff --git a/guacamole/pom.xml b/guacamole/pom.xml
index 9fa9fce..12d6c5c 100644
--- a/guacamole/pom.xml
+++ b/guacamole/pom.xml
@@ -329,12 +329,6 @@
</dependency>
<dependency>
<groupId>org.webjars.bower</groupId>
- <artifactId>angular-cookies</artifactId>
- <version>1.3.16</version>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>org.webjars.bower</groupId>
<artifactId>angular-route</artifactId>
<version>1.3.16</version>
<scope>runtime</scope>
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/884a9c0e/guacamole/src/main/webapp/app/auth/authModule.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/auth/authModule.js b/guacamole/src/main/webapp/app/auth/authModule.js
index ff8851e..7faaf87 100644
--- a/guacamole/src/main/webapp/app/auth/authModule.js
+++ b/guacamole/src/main/webapp/app/auth/authModule.js
@@ -20,4 +20,6 @@
/**
* The module for authentication and management of tokens.
*/
-angular.module('auth', ['ngCookies']);
+angular.module('auth', [
+ 'storage'
+]);
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/884a9c0e/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 74f0570..2b64a5b 100644
--- a/guacamole/src/main/webapp/app/auth/service/authenticationService.js
+++ b/guacamole/src/main/webapp/app/auth/service/authenticationService.js
@@ -46,10 +46,10 @@ angular.module('auth').factory('authenticationService', ['$injector',
var Error = $injector.get('Error');
// Required services
- var $cookieStore = $injector.get('$cookieStore');
- var $http = $injector.get('$http');
- var $q = $injector.get('$q');
- var $rootScope = $injector.get('$rootScope');
+ var $http = $injector.get('$http');
+ var $q = $injector.get('$q');
+ var $rootScope = $injector.get('$rootScope');
+ var localStorageService = $injector.get('localStorageService');
var service = {};
@@ -62,12 +62,12 @@ angular.module('auth').factory('authenticationService', ['$injector',
var cachedResult = null;
/**
- * The unique identifier of the local cookie which stores the result of the
- * last authentication attempt.
+ * The unique identifier of the local storage key which stores the result
+ * of the last authentication attempt.
*
* @type String
*/
- var AUTH_COOKIE_ID = "GUAC_AUTH";
+ var AUTH_STORAGE_KEY = 'GUAC_AUTH';
/**
* Retrieves the last successful authentication result. If the user has not
@@ -85,7 +85,7 @@ angular.module('auth').factory('authenticationService', ['$injector',
return cachedResult;
// Return explicit null if no auth data is currently stored
- var data = $cookieStore.get(AUTH_COOKIE_ID);
+ var data = localStorageService.getItem(AUTH_STORAGE_KEY);
if (!data)
return null;
@@ -107,7 +107,7 @@ angular.module('auth').factory('authenticationService', ['$injector',
// Clear the currently-stored result if the last attempt failed
if (!data) {
cachedResult = null;
- $cookieStore.remove(AUTH_COOKIE_ID);
+ localStorageService.removeItem(AUTH_STORAGE_KEY);
}
// Otherwise store the authentication attempt directly
@@ -116,9 +116,9 @@ angular.module('auth').factory('authenticationService', ['$injector',
// Always store in cache
cachedResult = data;
- // Store cookie ONLY if not anonymous
+ // Persist result past tab/window closure ONLY if not anonymous
if (data.username !== AuthenticationResult.ANONYMOUS_USERNAME)
- $cookieStore.put(AUTH_COOKIE_ID, data);
+ localStorageService.setItem(AUTH_STORAGE_KEY, data);
}
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/884a9c0e/guacamole/src/main/webapp/index.html
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/index.html b/guacamole/src/main/webapp/index.html
index 376245f..14321de 100644
--- a/guacamole/src/main/webapp/index.html
+++ b/guacamole/src/main/webapp/index.html
@@ -62,7 +62,6 @@
<!-- AngularJS -->
<script type="text/javascript" src="webjars/angular/1.3.16/angular.min.js"></script>
- <script type="text/javascript" src="webjars/angular-cookies/1.3.16/angular-cookies.min.js"></script>
<script type="text/javascript" src="webjars/angular-route/1.3.16/angular-route.min.js"></script>
<script type="text/javascript" src="webjars/angular-touch/1.3.16/angular-touch.min.js"></script>