Browse Source

AMBARI-13375. Kerberos: Add option to store credentials for KDC Credentials popup.

Alex Antonenko 9 years ago
parent
commit
375205079b

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

@@ -1031,6 +1031,7 @@ Em.I18n.translations = {
 
 
   'admin.kerberos.credentials.store.hint.supported': 'When checked, Ambari will store the KDC Admin credentials so they are not required to be re-entered during future changes of services, hosts, and components.',
   'admin.kerberos.credentials.store.hint.supported': 'When checked, Ambari will store the KDC Admin credentials so they are not required to be re-entered during future changes of services, hosts, and components.',
   'admin.kerberos.credentials.store.hint.not.supported': 'Ambari is not configured for storing credentials',
   'admin.kerberos.credentials.store.hint.not.supported': 'Ambari is not configured for storing credentials',
+  'admin.kerberos.credentials.store.label': 'Save Admin Credentials',
   'admin.kerberos.wizard.configuration.note': 'This is the initial configuration created by Enable Kerberos wizard.',
   'admin.kerberos.wizard.configuration.note': 'This is the initial configuration created by Enable Kerberos wizard.',
   'admin.kerberos.wizard.header':'Enable Kerberos Wizard',
   'admin.kerberos.wizard.header':'Enable Kerberos Wizard',
   'admin.kerberos.button.enable': 'Enable Kerberos',
   'admin.kerberos.button.enable': 'Enable Kerberos',

+ 6 - 7
ambari-web/app/mixins/common/kdc_credentials_controller_mixin.js

@@ -26,7 +26,7 @@ App.KDCCredentialsControllerMixin = Em.Mixin.create({
    *
    *
    * @type {string}
    * @type {string}
    */
    */
-  credentialAlias: 'kdc.admin.credential',
+  credentialAlias: credentialsUtils.ALIAS.KDC_CREDENTIALS,
 
 
   /**
   /**
    * Returns <code>true</code> if persisted secure storage available.
    * Returns <code>true</code> if persisted secure storage available.
@@ -51,7 +51,7 @@ App.KDCCredentialsControllerMixin = Em.Mixin.create({
       recommendedValue: 'false',
       recommendedValue: 'false',
       supportsFinal: false,
       supportsFinal: false,
       recommendedIsFinal: false,
       recommendedIsFinal: false,
-      displayName: 'Save Admin credentials',
+      displayName: Em.I18n.t('admin.kerberos.credentials.store.label'),
       category: 'Kadmin',
       category: 'Kadmin',
       isRequired: false,
       isRequired: false,
       isRequiredByAgent: false,
       isRequiredByAgent: false,
@@ -82,11 +82,10 @@ App.KDCCredentialsControllerMixin = Em.Mixin.create({
    */
    */
   createKDCCredentials: function(configs) {
   createKDCCredentials: function(configs) {
     var self = this;
     var self = this;
-    var resource = {
-      type: this._getStorageTypeValue(configs),
-      key: configs.findProperty('name', 'admin_password').get('value'),
-      principal:  configs.findProperty('name', 'admin_principal').get('value')
-    };
+    var resource = credentialsUtils.createCredentialResource(
+      configs.findProperty('name', 'admin_principal').get('value'),
+      configs.findProperty('name', 'admin_password').get('value'),
+      this._getStorageTypeValue(configs));
     return credentialsUtils.createCredentials(App.get('clusterName'), this.get('credentialAlias'), resource).fail(function() {
     return credentialsUtils.createCredentials(App.get('clusterName'), this.get('credentialAlias'), resource).fail(function() {
       return self.updateKDCCredentials(resource);
       return self.updateKDCCredentials(resource);
     });
     });

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

@@ -32,4 +32,18 @@
       {{view Ember.TextField type="password" valueBinding="view.parentView.password" class="form-control"}}
       {{view Ember.TextField type="password" valueBinding="view.parentView.password" class="form-control"}}
     </div>
     </div>
   </div>
   </div>
+  <div class="control-group">
+    <span class="control-label"></span>
+    <div class="controls ">
+      {{#if App.supports.storeKDCCredentials}}
+        <label>
+          {{view Ember.Checkbox checkedBinding="view.parentView.storeCredentials" disabledBinding="view.parentView.checkboxDisabled" classNames="pull-left"}}
+          <span {{bindAttr class=":mls view.parentView.checkboxDisabled:muted"}}>
+            {{t admin.kerberos.credentials.store.label}}
+            <a class="icon-question-sign icon-blue" rel="tooltip" href="javascript:void(null);" data-toggle="tooltip" {{bindAttr data-original-title="view.parentView.hintMessage"}}><a/>
+          </span>
+        </label>
+      {{/if}}
+    </div>
+  </div>
 </form>
 </form>

+ 20 - 0
ambari-web/app/utils/credentials.js

@@ -29,6 +29,10 @@ module.exports = {
     TEMPORARY_PATH: 'storage.temporary'
     TEMPORARY_PATH: 'storage.temporary'
   },
   },
 
 
+  ALIAS: {
+    KDC_CREDENTIALS: 'kdc.admin.credential'
+  },
+
   /**
   /**
    * Store credentials to server
    * Store credentials to server
    *
    *
@@ -221,5 +225,21 @@ module.exports = {
       dfd.reject(error);
       dfd.reject(error);
     });
     });
     return dfd.promise();
     return dfd.promise();
+  },
+
+  /**
+   * Generate payload for storing credential.
+   *
+   * @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
+   */
+  createCredentialResource: function(principal, key, type) {
+    return {
+      principal: principal,
+      key: key,
+      type: type
+    };
   }
   }
 };
 };

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

@@ -17,6 +17,7 @@
  */
  */
 
 
 var App = require('app');
 var App = require('app');
+var credentialsUtils = require('utils/credentials');
 
 
 /**
 /**
  * @param {Object} ajaxOpt - callbek funciton when clicking save
  * @param {Object} ajaxOpt - callbek funciton when clicking save
@@ -29,24 +30,88 @@ App.showInvalidKDCPopup = function (ajaxOpt, message) {
     header: Em.I18n.t('popup.invalid.KDC.header'),
     header: Em.I18n.t('popup.invalid.KDC.header'),
     principal: "",
     principal: "",
     password: "",
     password: "",
+
+    /**
+     * Store Admin credentials checkbox value
+     *
+     * @type {boolean}
+     */
+    storeCredentials: false,
+
+    /**
+     * Status of persistent storage. Returns <code>true</code> if persistent storage is available.
+     * @type {boolean}
+     */
+    storePersisted: false,
+
+    /**
+     * Disable checkbox if persistent storage not available
+     *
+     * @type {boolean}
+     */
+    checkboxDisabled: Ember.computed.not('storePersisted'),
+
+    /**
+     * Returns storage type used to save credentials e.g. <b>persistent</b>, <b>temporary</b> (default)
+     *
+     * @type {string}
+     */
+    storageType: function() {
+      return this.get('storeCredentials') ? credentialsUtils.STORE_TYPES.PERSISTENT : credentialsUtils.STORE_TYPES.TEMPORARY;
+    }.property('storeCredentials'),
+
+    /**
+     * Message to display in tooltip regarding persistent storage state.
+     *
+     * @type {string}
+     */
+    hintMessage: function() {
+      return this.get('storePersisted') ?
+        Em.I18n.t('admin.kerberos.credentials.store.hint.supported') :
+        Em.I18n.t('admin.kerberos.credentials.store.hint.not.supported');
+    }.property('storePersisted'),
+
     bodyClass: Em.View.extend({
     bodyClass: Em.View.extend({
       warningMsg: message + Em.I18n.t('popup.invalid.KDC.msg'),
       warningMsg: message + Em.I18n.t('popup.invalid.KDC.msg'),
       templateName: require('templates/common/modal_popups/invalid_KDC_popup')
       templateName: require('templates/common/modal_popups/invalid_KDC_popup')
     }),
     }),
+
+    willInsertElement: function() {
+      if (App.get('supports.storeKDCCredentials')) {
+        var self = this;
+        credentialsUtils.isStorePersisted(App.get('clusterName')).then(function(isPersisted) {
+          Em.run.next(function() {
+            self.set('storePersisted', isPersisted);
+          });
+        });
+      }
+    },
+
+    didInsertElement: function() {
+      this._super();
+      App.tooltip(this.$('[rel="tooltip"]'));
+    },
+
     onClose: function() {
     onClose: function() {
       this.hide();
       this.hide();
       if (ajaxOpt.kdcCancelHandler) {
       if (ajaxOpt.kdcCancelHandler) {
         ajaxOpt.kdcCancelHandler();
         ajaxOpt.kdcCancelHandler();
       }
       }
     },
     },
+
     onSecondary: function() {
     onSecondary: function() {
       this.hide();
       this.hide();
       if (ajaxOpt.kdcCancelHandler) {
       if (ajaxOpt.kdcCancelHandler) {
         ajaxOpt.kdcCancelHandler();
         ajaxOpt.kdcCancelHandler();
       }
       }
     },
     },
+
     onPrimary: function () {
     onPrimary: function () {
       this.hide();
       this.hide();
+      if (App.get('supports.storeKDCCredentials')) {
+        var resource = credentialsUtils.createCredentialResource(this.get('principal'), this.get('password'), this.get('storageType'));
+        credentialsUtils.updateCredentials(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(this.get('principal'), this.get('password'), ajaxOpt);
     }
     }
   });
   });