You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by at...@apache.org on 2015/10/13 14:31:49 UTC
ambari git commit: AMBARI-13400 ambari does not redirect the user to
the tez ui if log in is required. (atkach)
Repository: ambari
Updated Branches:
refs/heads/branch-2.1 ba40d1024 -> 600d1dc6d
AMBARI-13400 ambari does not redirect the user to the tez ui if log in is required. (atkach)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/600d1dc6
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/600d1dc6
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/600d1dc6
Branch: refs/heads/branch-2.1
Commit: 600d1dc6d3646a746bd3b40b09553accd700185c
Parents: ba40d10
Author: Andrii Tkach <at...@hortonworks.com>
Authored: Tue Oct 13 14:32:30 2015 +0300
Committer: Andrii Tkach <at...@hortonworks.com>
Committed: Tue Oct 13 15:31:19 2015 +0300
----------------------------------------------------------------------
ambari-web/app/router.js | 83 ++++++++++++++++++++++++-------------
ambari-web/app/routes/main.js | 3 +-
ambari-web/app/utils/db.js | 2 +-
ambari-web/test/router_test.js | 46 ++++++++++++++++++++
4 files changed, 103 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/600d1dc6/ambari-web/app/router.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/router.js b/ambari-web/app/router.js
index 5f11216..f6ffc41 100644
--- a/ambari-web/app/router.js
+++ b/ambari-web/app/router.js
@@ -122,7 +122,10 @@ App.Router = Em.Router.extend({
return currentStep;
},
- loggedIn: !!App.db.getAuthenticated(),
+ /**
+ * @type {boolean}
+ */
+ loggedIn: App.db.getAuthenticated(),
loginName: function() {
return this.getLoginName();
@@ -140,7 +143,7 @@ App.Router = Em.Router.extend({
}).complete(function (xhr) {
if (xhr.isResolved()) {
// if server knows the user and user authenticated by UI
- if (auth && auth === true) {
+ if (auth) {
dfd.resolve(self.get('loggedIn'));
// if server knows the user but UI don't, check the response header
// and try to authorize
@@ -160,6 +163,10 @@ App.Router = Em.Router.extend({
self.setAuthenticated(false);
dfd.resolve(false);
}
+ } else {
+ //if provisioning state unreachable then consider user as unauthenticated
+ self.setAuthenticated(false);
+ dfd.resolve(false);
}
});
return dfd.promise();
@@ -345,26 +352,7 @@ App.Router = Em.Router.extend({
}
App.set('isPermissionDataLoaded', true);
if (transitionToApp) {
- var preferredPath = router.get('preferedPath');
- // If the preferred path is relative, allow a redirect to it.
- // If the path is not relative, silently ignore it - if the path is an absolute URL, the user
- // may be routed to a different server where the [possibility exists for a phishing attack.
- if (!Em.isNone(preferredPath)) {
- if (preferredPath.startsWith('/') || preferredPath.startsWith('#')) {
- console.log("INFO: Routing to preferred path: " + preferredPath);
- }
- else {
- console.log("WARNING: Ignoring preferred path since it is not a relative URL: " + preferredPath);
- preferredPath = null;
- }
-
- // Unset preferedPath
- router.set('preferedPath', null);
- }
-
- if (!Em.isNone(preferredPath)) {
- window.location = preferredPath;
- } else {
+ if (!router.restorePreferedPath()) {
router.getSection(function (route) {
router.transitionTo(route);
loginController.postLogin(true, true);
@@ -484,6 +472,47 @@ App.Router = Em.Router.extend({
},
/**
+ * save prefered path
+ * @param {string} path
+ * @param {string} key
+ */
+ savePreferedPath: function(path, key) {
+ if (key) {
+ if (path.contains(key)) {
+ this.set('preferedPath', path.slice(path.indexOf(key) + key.length));
+ }
+ } else {
+ this.set('preferedPath', path);
+ }
+ },
+
+ /**
+ * If path exist route to it, otherwise return false
+ * @returns {boolean}
+ */
+ restorePreferedPath: function() {
+ var preferredPath = this.get('preferedPath');
+ var isRestored = false;
+
+ if (preferredPath) {
+ // If the preferred path is relative, allow a redirect to it.
+ // If the path is not relative, silently ignore it - if the path is an absolute URL, the user
+ // may be routed to a different server where the possibility exists for a phishing attack.
+ if ((preferredPath.startsWith('/') || preferredPath.startsWith('#')) && !preferredPath.contains('#/login')) {
+ console.log("INFO: Routing to preferred path: " + preferredPath);
+ window.location = preferredPath;
+ isRestored = true;
+ } else {
+ console.log("WARNING: Ignoring preferred path since it is not a relative URL: " + preferredPath);
+ }
+ // Unset preferedPath
+ this.set('preferedPath', null);
+ }
+
+ return isRestored;
+ },
+
+ /**
* initialize isAdmin if user is administrator
*/
initAdmin: function(){
@@ -519,11 +548,8 @@ App.Router = Em.Router.extend({
* If the user is already logged in, redirect to where the user was previously
*/
enter: function (router, context) {
+ var location = router.location.location.hash;
router.getAuthenticated().done(function (loggedIn) {
- var location = router.location.location.hash;
- //key to parse URI for prefered path to route
- var key = '?targetURI=';
-
if (loggedIn) {
Ember.run.next(function () {
console.log(router.getLoginName() + ' already authenticated. Redirecting...');
@@ -532,9 +558,8 @@ App.Router = Em.Router.extend({
});
});
} else {
- if (location.contains(key)) {
- router.set('preferedPath', location.slice(location.indexOf(key) + key.length));
- }
+ //key to parse URI for prefered path to route
+ router.savePreferedPath(location, '?targetURI=');
}
});
},
http://git-wip-us.apache.org/repos/asf/ambari/blob/600d1dc6/ambari-web/app/routes/main.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/routes/main.js b/ambari-web/app/routes/main.js
index 7188248..29cb535 100644
--- a/ambari-web/app/routes/main.js
+++ b/ambari-web/app/routes/main.js
@@ -25,6 +25,7 @@ module.exports = Em.Route.extend(App.RouterRedirections, {
App.db.updateStorage();
console.log('in /main:enter');
var self = this;
+ var location = router.location.location.hash;
router.getAuthenticated().done(function (loggedIn) {
if (loggedIn) {
var applicationController = App.router.get('applicationController');
@@ -67,7 +68,7 @@ module.exports = Em.Route.extend(App.RouterRedirections, {
// TODO: redirect to last known state
});
} else {
- router.set('preferedPath', router.location.location.hash);
+ router.savePreferedPath(location);
Em.run.next(function () {
router.transitionTo('login');
});
http://git-wip-us.apache.org/repos/asf/ambari/blob/600d1dc6/ambari-web/app/utils/db.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/db.js b/ambari-web/app/utils/db.js
index d90f46a..f66cf55 100644
--- a/ambari-web/app/utils/db.js
+++ b/ambari-web/app/utils/db.js
@@ -593,7 +593,7 @@ App.db.getLoginName = function () {
App.db.getAuthenticated = function () {
console.log('Trace: Entering db:getAuthenticated function');
App.db.data = localStorage.getObject('ambari');
- return App.db.data.app.authenticated;
+ return Boolean(App.db.data.app.authenticated);
};
App.db.getFilterConditions = function(name) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/600d1dc6/ambari-web/test/router_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/router_test.js b/ambari-web/test/router_test.js
index 1a1e43c..9122b54 100644
--- a/ambari-web/test/router_test.js
+++ b/ambari-web/test/router_test.js
@@ -162,4 +162,50 @@ describe('App.Router', function () {
});
});
});
+
+ describe("#savePreferedPath()", function() {
+ beforeEach(function () {
+ router.set('preferedPath', null);
+ });
+ it("has no key", function() {
+ router.savePreferedPath('path');
+ expect(router.get('preferedPath')).to.equal('path');
+ });
+ it("path does not contain key", function() {
+ router.savePreferedPath('path', 'key');
+ expect(router.get('preferedPath')).to.be.null;
+ });
+ it("path contains key", function() {
+ router.savePreferedPath('key=path', 'key=');
+ expect(router.get('preferedPath')).to.equal('path');
+ });
+ });
+
+ describe("#restorePreferedPath()", function() {
+ it("preferedPath is null", function() {
+ router.set('preferedPath', null);
+ expect(router.restorePreferedPath()).to.be.false;
+ expect(router.get('preferedPath')).to.be.null;
+ });
+ it("preferedPath is '/relativeURL'", function() {
+ router.set('preferedPath', '/relativeURL');
+ expect(router.restorePreferedPath()).to.be.true;
+ expect(router.get('preferedPath')).to.be.null;
+ });
+ it("preferedPath is '#/relativeURL'", function() {
+ router.set('preferedPath', '#/relativeURL');
+ expect(router.restorePreferedPath()).to.be.true;
+ expect(router.get('preferedPath')).to.be.null;
+ });
+ it("preferedPath is '#/login'", function() {
+ router.set('preferedPath', '#/login');
+ expect(router.restorePreferedPath()).to.be.false;
+ expect(router.get('preferedPath')).to.be.null;
+ });
+ it("preferedPath is 'http://absoluteURL'", function() {
+ router.set('preferedPath', 'http://absoluteURL');
+ expect(router.restorePreferedPath()).to.be.false;
+ expect(router.get('preferedPath')).to.be.null;
+ });
+ });
});