Browse Source

AMBARI-9178 Implement admin principal session expiration handling. (ababiichuk)

aBabiichuk 10 years ago
parent
commit
1f257e39d6

+ 28 - 0
ambari-web/app/controllers/global/cluster_controller.js

@@ -414,5 +414,33 @@ App.ClusterController = Em.Controller.extend({
 
   getHostNamesError: function () {
     console.error('failed to load hostNames');
+  },
+
+
+  /**
+   * puts kerberos admin credentials in the live cluster session
+   * and resend ajax request
+   * @param adminPrincipalValue
+   * @param adminPasswordValue
+   * @param ajaxOpt
+   * @returns {$.ajax}
+   */
+  createKerberosAdminSession: function (adminPrincipalValue, adminPasswordValue, ajaxOpt) {
+    return App.ajax.send({
+      name: 'common.cluster.update',
+      sender: this,
+      data: {
+        clusterName: App.get('clusterName'),
+        data: [{
+          session_attributes: {
+            kerberos_admin: {principal: adminPrincipalValue, password: adminPasswordValue}
+          }
+        }]
+      }
+    }).success(function () {
+      if (ajaxOpt) {
+        $.ajax(ajaxOpt);
+      }
+    });
   }
 });

+ 1 - 1
ambari-web/app/controllers/main/admin/kerberos/step4_controller.js

@@ -201,6 +201,6 @@ App.KerberosWizardStep4Controller = App.WizardStep7Controller.extend(App.AddSecu
       configs = configs.concat(_stepConfig.get('configs'));
     });
     this.updateKerberosDescriptor(kerberosDescriptor, configs);
-    this.get('wizardController').saveKerberosDescriptorConfigs(kerberosDescriptor);
+    App.get('router.kerberosWizardController').saveKerberosDescriptorConfigs(kerberosDescriptor);
   }
 });

+ 5 - 0
ambari-web/app/messages.js

@@ -322,6 +322,11 @@ Em.I18n.translations = {
   'popup.clusterCheck.Security.title': 'Security Requirements Not Met',
   'popup.clusterCheck.Security.alert': 'You must meet the following requirements before you can enable security.',
 
+  'popup.invalid.KDC.header': 'Admin session expiration error',
+  'popup.invalid.KDC.msg': 'Missing or invalid KDC administrator credentials. Please enter admin principal and password',
+  'popup.invalid.KDC.admin.principal': 'Admin principal',
+  'popup.invalid.KDC.admin.password': 'Admin password',
+
   'login.header':'Sign in',
   'login.username':'Username',
   'login.loginButton':'Sign in',

+ 1 - 1
ambari-web/app/routes/add_kerberos_routes.js

@@ -300,7 +300,7 @@ module.exports = App.WizardRoute.extend({
         localdb: App.db.data
       }, {
         alwaysCallback: function () {
-          self.hide();
+          controller.get('popup').hide();
           App.router.transitionTo('adminKerberos.index');
         }
       });

+ 35 - 0
ambari-web/app/templates/common/modal_popups/invalid_KDC_popup.hbs

@@ -0,0 +1,35 @@
+{{!
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+}}
+
+<div class="alert alert-warning">
+  {{view.warningMsg}}
+</div>
+<form class="form-horizontal">
+  <div class="control-group">
+    <label class="control-label">{{t popup.invalid.KDC.admin.principal}}</label>
+    <div class="controls">
+      {{view Ember.TextField valueBinding="view.parentView.principal" class="form-control"}}
+    </div>
+  </div>
+  <div class="control-group">
+    <label class="control-label">{{t popup.invalid.KDC.admin.password}}</label>
+    <div class="controls">
+      {{view Ember.TextField type="password" valueBinding="view.parentView.password" class="form-control"}}
+    </div>
+  </div>
+</form>

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

@@ -2218,6 +2218,10 @@ var formatRequest = function (data) {
   return opt;
 };
 
+var specialMsg = {
+  "missingKDC": "java.lang.IllegalArgumentException: Missing KDC administrator credentials.",
+  "invalidKDC": "java.lang.IllegalArgumentException: Invalid KDC administrator credentials."
+};
 /**
  * Wrapper for all ajax requests
  *
@@ -2278,7 +2282,9 @@ var ajax = Em.Object.extend({
       }
     };
     opt.error = function (request, ajaxOptions, error) {
-      if (config.error) {
+      if (this.isKDCError(request)) {
+        this.defaultErrorKDCHandler(opt);
+      } else if (config.error) {
         config.sender[config.error](request, ajaxOptions, error, opt, params);
       } else {
         this.defaultErrorHandler(request, opt.url, opt.type);
@@ -2331,6 +2337,27 @@ var ajax = Em.Object.extend({
         })
       }));
     }
+  },
+
+  /**
+   * defines if it's admin session expiration error
+   * @param jqXHR
+   * @returns {boolean}
+   */
+  isKDCError: function(jqXHR) {
+    try {
+      var message = $.parseJSON(jqXHR.responseText).message;
+    } catch (err) {}
+    return jqXHR.status === 400 && message && (message.contains(specialMsg.missingKDC) || message.contains(specialMsg.invalidKDC))
+  },
+
+  /**
+   * default handler for admin session expiration error
+   * @param opt
+   * @returns {*}
+   */
+  defaultErrorKDCHandler: function(opt) {
+    return App.showInvalidKDCPopup(opt);
   }
 
 });

+ 1 - 0
ambari-web/app/views.js

@@ -32,6 +32,7 @@ require('views/common/modal_popups/confirmation_popup');
 require('views/common/modal_popups/prompt_popup');
 require('views/common/modal_popups/reload_popup');
 require('views/common/modal_popups/cluster_check_popup');
+require('views/common/modal_popups/invalid_KDC_popup');
 require('views/common/editable_list');
 require('views/common/rolling_restart_view');
 require('views/common/select_custom_date_view');

+ 41 - 0
ambari-web/app/views/common/modal_popups/invalid_KDC_popup.js

@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+/**
+ * @param {Object} ajaxOpt - callbek funciton when clicking save
+ * @param {Object} message - warning message
+ * @return {*}
+ */
+App.showInvalidKDCPopup = function (ajaxOpt, message) {
+  return App.ModalPopup.show({
+    primary: Em.I18n.t('common.save'),
+    header: Em.I18n.t('popup.invalid.KDC.header'),
+    principal: "",
+    password: "",
+    bodyClass: Em.View.extend({
+      warningMsg: message || Em.I18n.t('popup.invalid.KDC.msg'),
+      templateName: require('templates/common/modal_popups/invalid_KDC_popup')
+    }),
+    onPrimary: function () {
+      this.hide();
+      App.get('router.clusterController').createKerberosAdminSession(this.get('principal'), this.get('password'), ajaxOpt);
+    }
+  });
+};

+ 27 - 0
ambari-web/test/controllers/global/cluster_controller_test.js

@@ -317,4 +317,31 @@ describe('App.clusterController', function () {
     });
   });
 
+  describe("#createKerberosAdminSession()", function() {
+    before(function () {
+      sinon.stub(App.ajax, 'send', function() {
+        return {success: Em.K}
+      });
+    });
+    after(function () {
+      App.ajax.send.restore();
+    });
+    it("make ajax call", function() {
+      controller.createKerberosAdminSession("admin", "pass", {});
+      expect(App.ajax.send.getCall(0).args[0]).to.eql({
+        name: 'common.cluster.update',
+        sender: controller,
+        data: {
+          clusterName: App.get('clusterName'),
+          data: [{
+            session_attributes: {
+              kerberos_admin: {principal: "admin", password: "pass"}
+            }
+          }]
+        }
+      });
+    });
+  });
+
+
 });