Browse Source

AMBARI-13904 Ranger Admins users password for Ambari is required to be filled by end user. (ababiichuk)

aBabiichuk 9 years ago
parent
commit
5a98a3f954

+ 15 - 0
ambari-web/app/utils/configs/config_initializer.js

@@ -18,6 +18,7 @@
 
 var App = require('app');
 require('utils/configs/config_initializer_class');
+var stringUtils = require('utils/string_utils');
 
 /**
  * Regexp for host with port ('hostName:1234')
@@ -264,6 +265,7 @@ App.ConfigInitializer = App.ConfigInitializerClass.create({
   },
 
   uniqueInitializers: {
+    'ranger_admin_password': '_setRangerAdminPassword',
     'hive_database': '_initHiveDatabaseValue',
     'templeton.hive.properties': '_initTempletonHiveProperties',
     'hbase.zookeeper.quorum': '_initHBaseZookeeperQuorum',
@@ -294,6 +296,19 @@ App.ConfigInitializer = App.ConfigInitializerClass.create({
     slashes: '_defaultWinReplaceWithAdditionalSlashes'
   },
 
+  /**
+   * Some strange method that should define <code>ranger_admin_password</code>
+   * TODO DELETE as soon as <code>ranger_admin_password</code> will be defined in stack!
+   *
+   * @param {configProperty} configProperty
+   * @private
+   */
+  _setRangerAdminPassword: function(configProperty) {
+    var value = 'P1!q' + stringUtils.getRandomString(12);
+    Em.setProperties(configProperty, {'value': value, 'recommendedValue': value, 'retypedPassword': value});
+    return configProperty;
+  },
+
   /**
    * Initializer for configs with value equal to hostName with needed component
    * Value example: 'hostName'

+ 18 - 0
ambari-web/app/utils/string_utils.js

@@ -226,5 +226,23 @@ module.exports = {
    */
   escapeRegExp: function (str) {
     return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
+  },
+
+  /**
+   * Generates random string using upper and lower letters and digits
+   *
+   * @param {number} len
+   * @param {String} [allowed]
+   * @returns {String}
+   * @method getRandomString
+   */
+  getRandomString: function(len, allowed) {
+    Em.assert('len should be defined and more than 0', len > 0);
+    var text = '';
+    allowed = typeof allowed === 'string' ? allowed : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+    for( var i=0; i < len; i++ ) {
+      text += allowed.charAt(Math.floor(Math.random() * allowed.length));
+    }
+    return text;
   }
 };