Browse Source

AMBARI-1959. Cannot login to Ambari after login failure. (yusaku)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1469129 13f79535-47bb-0310-9956-ffa450edef68
Yusaku Sako 12 years ago
parent
commit
88573cbd4a
3 changed files with 47 additions and 16 deletions
  1. 2 0
      CHANGES.txt
  2. 26 15
      ambari-web/app/router.js
  3. 19 1
      ambari-web/app/utils/ajax.js

+ 2 - 0
CHANGES.txt

@@ -749,6 +749,8 @@ Trunk (unreleased changes):
 
  BUG FIXES
 
+ AMBARI-1959. Cannot login to Ambari after login failure. (yusaku)
+
  AMBARI-1957. Hosts table: whether the alert filter is in effect or not is
  not clear. (yusaku)
 

+ 26 - 15
ambari-web/app/router.js

@@ -88,8 +88,29 @@ App.Router = Em.Router.extend({
   getAuthenticated: function () {
     var auth = App.db.getAuthenticated();
     var authResp = (auth && auth === true);
-    this.set('loggedIn', authResp);
-    return authResp;
+    if (authResp) {
+      App.ajax.send({
+        name: 'router.authentication',
+        sender: this,
+        success: 'onAuthenticationSuccess',
+        error: 'onAuthenticationError'
+      });
+    } else {
+      this.set('loggedIn', false);
+    }
+    return this.get('loggedIn');
+  },
+
+  onAuthenticationSuccess: function (data) {
+    this.set('loggedIn', true);
+  },
+
+  onAuthenticationError: function (data) {
+    if (data.status === 403) {
+      this.set('loggedIn', false);
+    } else {
+      console.log('error in getAuthenticated');
+    }
   },
 
   setAuthenticated: function (authenticated) {
@@ -122,17 +143,6 @@ App.Router = Em.Router.extend({
     return App.db.getUser();
   },
 
-  resetAuth: function (authenticated) {
-    if (!authenticated) {
-      App.db.cleanUp();
-      this.set('loggedIn', false);
-      this.set('loginController.loginName', '');
-      this.set('loginController.password', '');
-      this.transitionTo('login');
-    }
-    return authenticated;
-  },
-
   login: function () {
     var controller = this.get('loginController');
     var loginName = controller.get('loginName').toLowerCase();
@@ -288,12 +298,13 @@ App.Router = Em.Router.extend({
     // since it's a computed property but we are not setting it as a dependent of App.db.
     App.db.cleanUp();
     App.set('isAdmin', false);
+    this.set('loggedIn', false);
     this.clearAllSteps();
     console.log("Log off: " + App.router.getClusterName());
     this.set('loginController.loginName', '');
     this.set('loginController.password', '');
-
-    if (!App.testMode) {
+    // When logOff is called by Sign Out button, context contains event object. As it is only case we should send logoff request, we are checking context below.
+    if (!App.testMode && context) {
       App.ajax.send({
         name: 'router.logoff',
         sender: this,

+ 19 - 1
ambari-web/app/utils/ajax.js

@@ -657,7 +657,16 @@ var urls = {
   },
   'router.login': {
     'real': '/users/{loginName}',
-    'mock': '/data/users/user_{usr}.json'
+    'mock': '/data/users/user_{usr}.json',
+    'format': function (data, opt) {
+      var statusCode = jQuery.extend({}, require('data/statusCodes'));
+      statusCode['403'] = function () {
+        console.log("Error code 403: Forbidden.");
+      }
+      return {
+        statusCode: statusCode
+      };
+    }
   },
   'router.login2': {
     'real': '/clusters',
@@ -665,6 +674,15 @@ var urls = {
   },
   'router.logoff': {
     'real': '/logout'
+  },
+  'router.authentication': {
+    'real': '/clusters',
+    'mock': '/data/clusters/info.json',
+    'format': function (data, opt) {
+      return {
+        async: false
+      };
+    }
   }
 };
 /**