ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ababiic...@apache.org
Subject [1/2] ambari git commit: AMBARI-9178 Implement admin principal session expiration handling. (ababiichuk)
Date Fri, 16 Jan 2015 16:30:58 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk a71f942ed -> b52e2543f


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


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

Branch: refs/heads/trunk
Commit: 1f257e39d668166a098b51a3d267e31fb36ca2ed
Parents: a71f942
Author: aBabiichuk <ababiichuk@cybervisiontech.com>
Authored: Fri Jan 16 17:35:51 2015 +0200
Committer: aBabiichuk <ababiichuk@cybervisiontech.com>
Committed: Fri Jan 16 18:29:41 2015 +0200

----------------------------------------------------------------------
 .../controllers/global/cluster_controller.js    | 28 +++++++++++++
 .../main/admin/kerberos/step4_controller.js     |  2 +-
 ambari-web/app/messages.js                      |  5 +++
 ambari-web/app/routes/add_kerberos_routes.js    |  2 +-
 .../common/modal_popups/invalid_KDC_popup.hbs   | 35 +++++++++++++++++
 ambari-web/app/utils/ajax/ajax.js               | 29 +++++++++++++-
 ambari-web/app/views.js                         |  1 +
 .../common/modal_popups/invalid_KDC_popup.js    | 41 ++++++++++++++++++++
 .../global/cluster_controller_test.js           | 27 +++++++++++++
 9 files changed, 167 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1f257e39/ambari-web/app/controllers/global/cluster_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/global/cluster_controller.js b/ambari-web/app/controllers/global/cluster_controller.js
index 0227f39..728422d 100644
--- a/ambari-web/app/controllers/global/cluster_controller.js
+++ b/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);
+      }
+    });
   }
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/1f257e39/ambari-web/app/controllers/main/admin/kerberos/step4_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/kerberos/step4_controller.js b/ambari-web/app/controllers/main/admin/kerberos/step4_controller.js
index 79707dd..ac83f02 100644
--- a/ambari-web/app/controllers/main/admin/kerberos/step4_controller.js
+++ b/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);
   }
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/1f257e39/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index f7aa362..bfb6250 100644
--- a/ambari-web/app/messages.js
+++ b/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',

http://git-wip-us.apache.org/repos/asf/ambari/blob/1f257e39/ambari-web/app/routes/add_kerberos_routes.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/routes/add_kerberos_routes.js b/ambari-web/app/routes/add_kerberos_routes.js
index 11962af..a70cd31 100644
--- a/ambari-web/app/routes/add_kerberos_routes.js
+++ b/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');
         }
       });

http://git-wip-us.apache.org/repos/asf/ambari/blob/1f257e39/ambari-web/app/templates/common/modal_popups/invalid_KDC_popup.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/common/modal_popups/invalid_KDC_popup.hbs b/ambari-web/app/templates/common/modal_popups/invalid_KDC_popup.hbs
new file mode 100644
index 0000000..557088e
--- /dev/null
+++ b/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>

http://git-wip-us.apache.org/repos/asf/ambari/blob/1f257e39/ambari-web/app/utils/ajax/ajax.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ajax/ajax.js b/ambari-web/app/utils/ajax/ajax.js
index 9e459d2..2e199b5 100644
--- a/ambari-web/app/utils/ajax/ajax.js
+++ b/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);
   }
 
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/1f257e39/ambari-web/app/views.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views.js b/ambari-web/app/views.js
index 1991b06..364f57d 100644
--- a/ambari-web/app/views.js
+++ b/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');

http://git-wip-us.apache.org/repos/asf/ambari/blob/1f257e39/ambari-web/app/views/common/modal_popups/invalid_KDC_popup.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/modal_popups/invalid_KDC_popup.js b/ambari-web/app/views/common/modal_popups/invalid_KDC_popup.js
new file mode 100644
index 0000000..b5f09f3
--- /dev/null
+++ b/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);
+    }
+  });
+};

http://git-wip-us.apache.org/repos/asf/ambari/blob/1f257e39/ambari-web/test/controllers/global/cluster_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/global/cluster_controller_test.js b/ambari-web/test/controllers/global/cluster_controller_test.js
index 1130370..2f8341a 100644
--- a/ambari-web/test/controllers/global/cluster_controller_test.js
+++ b/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"}
+            }
+          }]
+        }
+      });
+    });
+  });
+
+
 });


Mime
View raw message