GUAC-971: Re-authenticate with server for each page visited.

This commit is contained in:
Michael Jumper
2015-01-05 13:54:57 -08:00
parent 83bf9d32c1
commit 98d5c19b1d

View File

@@ -29,51 +29,109 @@ angular.module('index').config(['$routeProvider', '$locationProvider',
// Disable HTML5 mode (use # for routing) // Disable HTML5 mode (use # for routing)
$locationProvider.html5Mode(false); $locationProvider.html5Mode(false);
/**
* Attempts to re-authenticate with the Guacamole server, sending any
* query parameters in the URL, along with the current auth token, and
* updating locally stored token if necessary.
*
* @param {Service} $injector
* The Angular $injector service.
*
* @returns {Promise}
* A promise which resolves successfully only after an attempt to
* re-authenticate has been made.
*/
var updateCurrentToken = ['$injector', function updateCurrentToken($injector) {
// Required services
var $location = $injector.get('$location');
var $q = $injector.get('$q');
var authenticationService = $injector.get('authenticationService');
// Promise for authentication attempt
var authAttempt = $q.defer();
// Re-authenticate including any parameters in URL
authenticationService.updateCurrentToken($location.search())
['finally'](function authenticationAttemptComplete() {
authAttempt.resolve();
});
// Return promise that will resolve regardless of success/failure
return authAttempt.promise;
}];
// Configure each possible route
$routeProvider $routeProvider
// Home screen
.when('/', { .when('/', {
title : 'APP.NAME', title : 'APP.NAME',
bodyClassName : 'home', bodyClassName : 'home',
templateUrl : 'app/home/templates/home.html', templateUrl : 'app/home/templates/home.html',
controller: 'homeController' controller : 'homeController',
resolve : { updateCurrentToken: updateCurrentToken }
}) })
// Management screen
.when('/manage/', { .when('/manage/', {
title : 'APP.NAME', title : 'APP.NAME',
bodyClassName : 'manage', bodyClassName : 'manage',
templateUrl : 'app/manage/templates/manage.html', templateUrl : 'app/manage/templates/manage.html',
controller: 'manageController' controller : 'manageController',
resolve : { updateCurrentToken: updateCurrentToken }
}) })
// Connection editor
.when('/manage/connections/:id?', { .when('/manage/connections/:id?', {
title : 'APP.NAME', title : 'APP.NAME',
bodyClassName : 'manage', bodyClassName : 'manage',
templateUrl : 'app/manage/templates/manageConnection.html', templateUrl : 'app/manage/templates/manageConnection.html',
controller: 'manageConnectionController' controller : 'manageConnectionController',
resolve : { updateCurrentToken: updateCurrentToken }
}) })
// Connection group editor
.when('/manage/connectionGroups/:id?', { .when('/manage/connectionGroups/:id?', {
title : 'APP.NAME', title : 'APP.NAME',
bodyClassName : 'manage', bodyClassName : 'manage',
templateUrl : 'app/manage/templates/manageConnectionGroup.html', templateUrl : 'app/manage/templates/manageConnectionGroup.html',
controller: 'manageConnectionGroupController' controller : 'manageConnectionGroupController',
resolve : { updateCurrentToken: updateCurrentToken }
}) })
// User editor
.when('/manage/users/:id', { .when('/manage/users/:id', {
title : 'APP.NAME', title : 'APP.NAME',
bodyClassName : 'manage', bodyClassName : 'manage',
templateUrl : 'app/manage/templates/manageUser.html', templateUrl : 'app/manage/templates/manageUser.html',
controller: 'manageUserController' controller : 'manageUserController',
resolve : { updateCurrentToken: updateCurrentToken }
}) })
// Login screen
.when('/login/', { .when('/login/', {
title : 'APP.NAME', title : 'APP.NAME',
bodyClassName : 'login', bodyClassName : 'login',
templateUrl : 'app/login/templates/login.html', templateUrl : 'app/login/templates/login.html',
controller: 'loginController' controller : 'loginController',
resolve : { updateCurrentToken: updateCurrentToken }
}) })
// Client view
.when('/client/:type/:id/:params?', { .when('/client/:type/:id/:params?', {
bodyClassName : 'client', bodyClassName : 'client',
templateUrl : 'app/client/templates/client.html', templateUrl : 'app/client/templates/client.html',
controller: 'clientController' controller : 'clientController',
resolve : { updateCurrentToken: updateCurrentToken }
}) })
// Redirect to home screen if page not found
.otherwise({ .otherwise({
redirectTo : '/' redirectTo : '/'
}); });
}]); }]);