From 7c542e8de8598e2c8d815a77dcdcf17af88e65b0 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 23 Apr 2015 12:00:37 -0700 Subject: [PATCH] GUAC-1161: Reject attempts to visit '/' unless '/' is actually the home page. Redirect to true home page otherwise. --- .../app/index/config/indexRouteConfig.js | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/guacamole/src/main/webapp/app/index/config/indexRouteConfig.js b/guacamole/src/main/webapp/app/index/config/indexRouteConfig.js index e8efc5676..ad350a1ef 100644 --- a/guacamole/src/main/webapp/app/index/config/indexRouteConfig.js +++ b/guacamole/src/main/webapp/app/index/config/indexRouteConfig.js @@ -74,8 +74,8 @@ angular.module('index').config(['$routeProvider', '$locationProvider', var $q = $injector.get('$q'); var userPageService = $injector.get('userPageService'); - // Promise for redirection attempt - var redirect = $q.defer(); + // Promise for routing attempt + var route = $q.defer(); // Re-authenticate including any parameters in URL $injector.invoke(updateCurrentToken) @@ -84,23 +84,29 @@ angular.module('index').config(['$routeProvider', '$locationProvider', // Redirect to home page userPageService.getHomePage() .then(function homePageRetrieved(homePage) { - $location.url(homePage.url); + + // If home page is the requested location, allow through + if ($location.path() === homePage.url) + route.resolve(); + + // Otherwise, reject and reroute + else { + $location.url(homePage.url); + route.reject(); + } + }) - // If retrieval of home page fails, assume '/' + // If retrieval of home page fails, assume requested page is OK ['catch'](function homePageFailed() { - $location.url('/'); - }) - - // Resolve promise in either case - ['finally'](function retrievalAttemptComplete() { - redirect.resolve(); + route.resolve(); }); }); - // Return promise that will resolve regardless of success/failure - return redirect.promise; + // Return promise that will resolve only if the requested page is the + // home page + return route.promise; }];