You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by yu...@apache.org on 2015/06/27 02:54:02 UTC

ambari git commit: AMBARI-12153. Ambari Web should automatically log the user in if valid HTTP authorization header is present (Single Sign On). (yusaku)

Repository: ambari
Updated Branches:
  refs/heads/trunk e4012e958 -> f09c55528


AMBARI-12153. Ambari Web should automatically log the user in if valid HTTP authorization header is present (Single Sign On). (yusaku)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f09c5552
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f09c5552
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f09c5552

Branch: refs/heads/trunk
Commit: f09c555282a91646468de37a7c30449ba7221340
Parents: e4012e9
Author: Yusaku Sako <yu...@hortonworks.com>
Authored: Fri Jun 26 17:20:39 2015 -0700
Committer: Yusaku Sako <yu...@hortonworks.com>
Committed: Fri Jun 26 17:20:39 2015 -0700

----------------------------------------------------------------------
 ambari-web/app/router.js | 53 ++++++++++++++++++++++++++++++-------------
 1 file changed, 37 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f09c5552/ambari-web/app/router.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/router.js b/ambari-web/app/router.js
index 9ea8f54..38dae93 100644
--- a/ambari-web/app/router.js
+++ b/ambari-web/app/router.js
@@ -132,27 +132,48 @@ App.Router = Em.Router.extend({
     var dfd = $.Deferred();
     var self = this;
     var auth = App.db.getAuthenticated();
-    var authResp = (auth && auth === true);
-    if (authResp) {
-      App.ajax.send({
-        name: 'router.login.clusters',
-        sender: this,
-        success: 'onAuthenticationSuccess',
-        error: 'onAuthenticationError'
-      }).complete(function () {
+    App.ajax.send({
+      name: 'router.login.clusters',
+      sender: this,
+      success: 'onAuthenticationSuccess',
+      error: 'onAuthenticationError'
+    }).complete(function (xhr) {
+      if (xhr.isResolved()) {
+        // if server knows the user and user authenticated by UI
+        if (auth && auth === true) {
           dfd.resolve(self.get('loggedIn'));
-        });
-    } else {
-      this.set('loggedIn', false);
-      dfd.resolve(false);
-    }
+          // if server knows the user but UI don't, check the response header
+          // and try to authorize
+        } else if (xhr.getResponseHeader('User')) {
+          var user = xhr.getResponseHeader('User');
+          App.ajax.send({
+            name: 'router.login',
+            sender: self,
+            data: {
+              usr: user,
+              loginName: encodeURIComponent(user)
+            },
+            success: 'loginSuccessCallback',
+            error: 'loginErrorCallback'
+          });
+        } else {
+          self.setAuthenticated(false);
+          dfd.resolve(false);
+        }
+      } else {
+        self.setAuthenticated(false);
+        dfd.resolve(false);
+      }
+    });
     return dfd.promise();
   },
 
   onAuthenticationSuccess: function (data) {
-    this.setAuthenticated(true);
-    if (data.items.length) {
-      this.setClusterInstalled(data);
+    if (App.db.getAuthenticated() === true) {
+      this.setAuthenticated(true);
+      if (data.items.length) {
+        this.setClusterInstalled(data);
+      }
     }
   },