Browse Source

AMBARI-14063. Missing KDC administrator credentials after adding Kerberos with checkbox "Save Admin Credentials" checked

Alex Antonenko 9 năm trước cách đây
mục cha
commit
e69c96f74e

+ 13 - 5
ambari-web/app/controllers/global/cluster_controller.js

@@ -18,6 +18,7 @@
 
 var App = require('app');
 var stringUtils = require('utils/string_utils');
+var credentialUtils = require('utils/credentials');
 
 App.ClusterController = Em.Controller.extend(App.ReloadPopupMixin, {
   name: 'clusterController',
@@ -396,12 +397,19 @@ App.ClusterController = Em.Controller.extend(App.ReloadPopupMixin, {
   /**
    * puts kerberos admin credentials in the live cluster session
    * and resend ajax request
-   * @param adminPrincipalValue
-   * @param adminPasswordValue
-   * @param ajaxOpt
+   * @param {credentialResourceObject} credentialResource
+   * @param {object} ajaxOpt
    * @returns {$.ajax}
    */
-  createKerberosAdminSession: function (adminPrincipalValue, adminPasswordValue, ajaxOpt) {
+  createKerberosAdminSession: function (credentialResource, ajaxOpt) {
+    if (App.get('supports.storeKDCCredentials')) {
+      return credentialUtils.createOrUpdateCredentials(App.get('clusterName'), credentialUtils.ALIAS.KDC_CREDENTIALS, credentialResource).then(function() {
+        if (ajaxOpt) {
+          $.ajax(ajaxOpt);
+        }
+      });
+    }
+
     return App.ajax.send({
       name: 'common.cluster.update',
       sender: this,
@@ -409,7 +417,7 @@ App.ClusterController = Em.Controller.extend(App.ReloadPopupMixin, {
         clusterName: App.get('clusterName'),
         data: [{
           session_attributes: {
-            kerberos_admin: {principal: adminPrincipalValue, password: adminPasswordValue}
+            kerberos_admin: {principal: credentialResource.principal, password: credentialResource.key}
           }
         }]
       }

+ 4 - 3
ambari-web/app/controllers/main/admin/kerberos/step2_controller.js

@@ -138,9 +138,6 @@ App.KerberosWizardStep2Controller = App.WizardStep7Controller.extend(App.KDCCred
     var self = this;
     this.get('wizardController').deleteKerberosService().always(function () {
       self.configureKerberos();
-      if (App.get('supports.storeKDCCredentials') && !self.get('wizardController.skipClientInstall')) {
-        self.createKDCCredentials(self.get('stepConfigs.0.configs'));
-      }
     });
   },
 
@@ -248,6 +245,10 @@ App.KerberosWizardStep2Controller = App.WizardStep7Controller.extend(App.KDCCred
    */
   createKerberosAdminSession: function (configs) {
     configs = configs || this.get('stepConfigs')[0].get('configs');
+    if (App.get('supports.storeKDCCredentials') && !this.get('wizardController.skipClientInstall')) {
+      return this.createKDCCredentials(configs);
+    }
+
     var adminPrincipalValue = configs.findProperty('name', 'admin_principal').value;
     var adminPasswordValue = configs.findProperty('name', 'admin_password').value;
     return App.ajax.send({

+ 15 - 3
ambari-web/app/utils/credentials.js

@@ -18,6 +18,14 @@
 var App = require('app');
 
 /** @module utils.credentials **/
+
+/**
+ * Credential Resource format.
+ * @typedef {object} credentialResourceObject
+ * @property {string} principal user principal name
+ * @property {string} key user password
+ * @property {string} type type of credential store e.g. <b>persistent</b> or <b>temporary</b>
+ */
 module.exports = {
 
   STORE_TYPES: {
@@ -39,7 +47,7 @@ module.exports = {
    * @member utils.credentials
    * @param {string} clusterName cluster name
    * @param {string} alias credential alias name e.g. "kdc.admin.credentials"
-   * @param {object} resource resource info to set e.g.
+   * @param {credentialResourceObject} resource resource info to set e.g.
    * <code>
    * {
    *   principal: "USERNAME",
@@ -78,9 +86,10 @@ module.exports = {
 
   /**
    * @see createCredentials
+   * @member utils.credentials
    * @param {string} clusterName
    * @param {string} alias
-   * @param {object} resource
+   * @param {credentialResourceObject} resource
    * @returns {$.Deferred} promise object
    */
   createOrUpdateCredentials: function(clusterName, alias, resource) {
@@ -247,6 +256,7 @@ module.exports = {
   /**
    * Get store type value for specified cluster and store type e.g. <b>persistent</b> or <b>temporary</b>
    *
+   * @member utils.credentials
    * @param {string} clusterName
    * @param {string} type store type e.g. <b>persistent</b> or <b>temporary</b>
    * @returns {$.Deferred} promise object
@@ -264,10 +274,11 @@ module.exports = {
   /**
    * Generate payload for storing credential.
    *
+   * @member utils.credentials
    * @param {string} principal principal name
    * @param {string} key secret key
    * @param {string} type storage type e.g. <b>persisted</b>, <b>temporary</b>
-   * @returns {object} resource template
+   * @returns {credentialResourceObject} resource template
    */
   createCredentialResource: function(principal, key, type) {
     return {
@@ -280,6 +291,7 @@ module.exports = {
   /**
    * Check that KDC credentials stored as <b>persisted</b> and not <b>temporary</b> from specified credentials list.
    *
+   * @member utils.credentials
    * @param {object[]} credentials credentials list retrieved from API @see credentials
    * @returns {boolean} <code>true</code> if credentials are persisted
    */

+ 1 - 4
ambari-web/app/views/common/modal_popups/invalid_KDC_popup.js

@@ -93,11 +93,8 @@ App.showInvalidKDCPopup = function (ajaxOpt, message) {
 
     onPrimary: function () {
       this.hide();
-      if (App.get('supports.storeKDCCredentials')) {
         var resource = credentialsUtils.createCredentialResource(this.get('principal'), this.get('password'), this.get('storageType'));
-        credentialsUtils.createOrUpdateCredentials(App.get('clusterName'), credentialsUtils.ALIAS.KDC_CREDENTIALS, resource);
-      }
-      App.get('router.clusterController').createKerberosAdminSession(this.get('principal'), this.get('password'), ajaxOpt);
+        App.get('router.clusterController').createKerberosAdminSession(resource, ajaxOpt);
     }
   });
 };

+ 37 - 5
ambari-web/test/controllers/global/cluster_controller_test.js

@@ -18,6 +18,7 @@
 
 
 var App = require('app');
+var credentialUtils = require('utils/credentials');
 require('controllers/global/cluster_controller');
 require('models/host_component');
 require('utils/http_client');
@@ -195,21 +196,33 @@ describe('App.clusterController', function () {
   });
 
   describe("#createKerberosAdminSession()", function() {
-    before(function () {
+    beforeEach(function () {
       sinon.stub(App.ajax, 'send', function() {
         return {success: Em.K}
       });
+      sinon.stub(credentialUtils, 'createOrUpdateCredentials', function() {
+        return $.Deferred().resolve().promise();
+      });
     });
-    after(function () {
+    afterEach(function () {
       App.ajax.send.restore();
+      credentialUtils.createOrUpdateCredentials.restore();
     });
-    it("make ajax call", function() {
-      controller.createKerberosAdminSession("admin", "pass", {});
+    it("KDC Store supports disabled, credentials updated via kdc session call", function() {
+      sinon.stub(App, 'get')
+        .withArgs('supports.storeKDCCredentials').returns(false)
+        .withArgs('clusterName').returns('test');
+      controller.createKerberosAdminSession({
+        principal: 'admin',
+        key: 'pass',
+        type: 'persistent'
+      }, {});
+      App.get.restore();
       expect(App.ajax.send.getCall(0).args[0]).to.eql({
         name: 'common.cluster.update',
         sender: controller,
         data: {
-          clusterName: App.get('clusterName'),
+          clusterName: 'test',
           data: [{
             session_attributes: {
               kerberos_admin: {principal: "admin", password: "pass"}
@@ -218,6 +231,25 @@ describe('App.clusterController', function () {
         }
       });
     });
+    it("KDC Store supports enabled, credentials updated via credentials storage call", function() {
+      sinon.stub(App, 'get')
+        .withArgs('supports.storeKDCCredentials').returns(true)
+        .withArgs('clusterName').returns('test');
+      controller.createKerberosAdminSession({
+        principal: 'admin',
+        key: 'pass',
+        type: 'persistent'
+      }, {});
+      App.get.restore();
+      expect(App.ajax.send.called).to.be.eql(false);
+      expect(credentialUtils.createOrUpdateCredentials.getCall(0).args).to.eql([
+        'test', 'kdc.admin.credential', {
+          principal: 'admin',
+          key: 'pass',
+          type: 'persistent'
+        }
+      ]);
+    });
   });
 
   describe('#checkDetailedRepoVersion()', function () {