Browse Source

AMBARI-5214: Ambari invalidates user names with underscore in it's value. (jaimin)

Jaimin Jetly 11 years ago
parent
commit
30d52d2588

+ 4 - 0
ambari-web/app/data/service_configs.js

@@ -23,11 +23,13 @@ require('utils/configs/defaults_providers/tez_defaults_provider');
 require('utils/configs/defaults_providers/hive_defaults_provider');
 require('utils/configs/defaults_providers/storm_defaults_provider');
 require('utils/configs/defaults_providers/oozie_defaults_provider');
+require('utils/configs/defaults_providers/user_defaults_provider');
 require('utils/configs/validators/yarn_configs_validator');
 require('utils/configs/validators/hive_configs_validator');
 require('utils/configs/validators/tez_configs_validator');
 require('utils/configs/validators/mapreduce2_configs_validator');
 require('utils/configs/validators/storm_configs_validator');
+require('utils/configs/validators/user_configs_validator');
 
 module.exports = [
   {
@@ -280,6 +282,8 @@ module.exports = [
   {
     serviceName: 'MISC',
     displayName: 'Misc',
+    configsValidator: App.userConfigsValidator,
+    defaultsProviders: [App.userDefaultsProvider.create()],
     configCategories: [
       App.ServiceConfigCategory.create({ name: 'General', displayName : 'General'}),
       App.ServiceConfigCategory.create({ name: 'Users and Groups', displayName : 'Users and Groups'})

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

@@ -275,7 +275,7 @@ Em.I18n.translations = {
   'graphs.timeRange.month': 'Last 1 month',
   'graphs.timeRange.year': 'Last 1 year',
 
-  'users.userName.validationFail': 'Only lowercase letters and numbers are allowed; must start with a letter',
+  'users.userName.validationFail': 'Only lowercase letters and numbers are recommended; must start with a letter',
   'host.spacesValidation': 'Can\'t contain whitespaces',
   'host.trimspacesValidation': 'Can\'t contain leading or trailing whitespaces',
 

+ 1 - 0
ambari-web/app/models/form.js

@@ -125,6 +125,7 @@ App.FormField = Em.Object.extend({ // try to realize this as view
   displayType:'string', // string, digits, number, directories, textarea, checkbox
   disableRequiredOnPresent:false,
   errorMessage:'',
+  warnMessage:'',
   form:false,
   isRequired:true, // by default a config property is required
   unit:'',

+ 0 - 6
ambari-web/app/models/service_config.js

@@ -720,12 +720,6 @@ App.ServiceConfigProperty = Ember.Object.extend({
           break;
         case 'custom':
           break;
-        case 'user':
-          if (!validator.isValidUserName(value)) {
-            this.set('errorMessage', Em.I18n.t('users.userName.validationFail'));
-            isError = true;
-          }
-          break;
         case 'email':
           if (!validator.isValidEmail(value)) {
             this.set('errorMessage', 'Must be a valid email address');

+ 13 - 5
ambari-web/app/models/user.js

@@ -139,11 +139,6 @@ App.CreateUserForm = App.Form.extend({
       var userNameField = this.getField('userName');
       var userName = userNameField.get('value');
 
-      if (!validator.isValidUserName(userName)) {
-        userNameField.set('errorMessage', this.t('users.userName.validationFail'));
-        isValid = false;
-      }
-
       if (users.mapProperty('userName').contains(userName)) {
         userNameField.set('errorMessage', this.t('admin.users.createError.userNameExists'));
         return isValid = false;
@@ -153,6 +148,19 @@ App.CreateUserForm = App.Form.extend({
     return isValid;
   },
 
+  isWarn: function() {
+    var isWarn = false;
+    var userNameField = this.getField('userName');
+    userNameField.set('warnMessage', '');
+    var userName = userNameField.get('value');
+
+    if (this.isValid() && !validator.isValidUserName(userName)) {
+      userNameField.set('warnMessage', this.t('users.userName.validationFail'));
+      isWarn = true;
+    }
+    return isWarn;
+  },
+
   save: function () {
 
     var object = this.get('object');

+ 7 - 2
ambari-web/app/templates/main/admin/user/create.hbs

@@ -19,11 +19,16 @@
 <form class="form-horizontal" autocomplete="off">
   {{#each field in view.userForm.fields}}
   {{#unless field.isHidden}}
-  <div {{bindAttr class="field.errorMessage:error :control-group"}}>
+  <div {{bindAttr class="field.errorMessage:error field.warnMessage:warning :control-group"}}>
     <label class="control-label" for="input{{unbound field.name}}">{{unbound field.displayName}}</label>
     <div class="controls">
         {{view field.viewClass valueBinding="field.value" disabledBinding="field.disabled"}}
-      <span class="help-inline">{{field.errorMessage}}</span>
+      {{#if field.errorMessage}}
+        <span class="help-inline">{{field.errorMessage}}</span>
+      {{/if}}
+      {{#if field.warnMessage}}
+        <span class="help-inline">{{field.warnMessage}}</span>
+      {{/if}}
     </div>
   </div>
   {{/unless}}

+ 54 - 0
ambari-web/app/utils/configs/defaults_providers/user_defaults_provider.js

@@ -0,0 +1,54 @@
+/**
+ * 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');
+require('utils/configs/defaults_providers/defaultsProvider');
+
+App.userDefaultsProvider = App.DefaultsProvider.extend({
+
+  clusterData: null,
+
+  /**
+   * List of the configs that should be calculated
+   */
+  configsTemplate: {
+    'hdfs_user': null,
+    'mapred_user': null,
+    'yarn_user': null,
+    'hbase_user': null,
+    'hive_user': null,
+    'hcat_user': null,
+    'webhcat_user': null,
+    'oozie_user': null,
+    'falcon_user': null,
+    'storm_user': null,
+    'zk_user': null,
+    'gmetad_user': null,
+    'gmond_user': null,
+    'nagios_user': null,
+    'smokeuser': null
+  },
+
+  // @todo fill with correct values
+  getDefaults: function (localDB) {
+    this._super();
+    var configs = {};
+    jQuery.extend(configs, this.get('configsTemplate'));
+    return configs;
+  }
+});
+

+ 1 - 1
ambari-web/app/utils/configs/validators/tez_configs_validator.js

@@ -24,7 +24,7 @@ App.TezConfigsValidator = App.ServiceConfigsValidator.create({
    */
   configValidators: {
     'tez.am.resource.memory.mb': 'tezAMResourceMb',
-    'tez.am.java.opts': 'tezAMJavaOpts',
+    'tez.am.java.opts': 'tezAMJavaOpts'
   },
 
   tezAMResourceMb: function(config) {

+ 55 - 0
ambari-web/app/utils/configs/validators/user_configs_validator.js

@@ -0,0 +1,55 @@
+/**
+ * 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');
+var validator = require('utils/validator');
+require('utils/configs/validators/service_configs_validator');
+
+App.userConfigsValidator = App.ServiceConfigsValidator.create({
+  /**
+   * List of the configs that should be validated
+   */
+  configValidators: {
+    'hdfs_user': 'validateUserValue',
+    'mapred_user': 'validateUserValue',
+    'yarn_user': 'validateUserValue',
+    'hbase_user': 'validateUserValue',
+    'hive_user': 'validateUserValue',
+    'hcat_user': 'validateUserValue',
+    'webhcat_user': 'validateUserValue',
+    'oozie_user': 'validateUserValue',
+    'falcon_user': 'validateUserValue',
+    'storm_user': 'validateUserValue',
+    'zk_user': 'validateUserValue',
+    'gmetad_user': 'validateUserValue',
+    'gmond_user': 'validateUserValue',
+    'nagios_user': 'validateUserValue',
+    'smokeuser': 'validateUserValue'
+  },
+
+  validateUserValue: function(config) {
+    var recomendedDefault = this.get('recommendedDefaults')[config.get('name')];
+    var defaultValue = Em.isNone(recomendedDefault) ? config.get('defaultValue') : recomendedDefault;
+    Em.assert('validateUserValue: User\'s default value can\'t be null or undefined', !Em.isNone(defaultValue));
+    var currentValue = config.get('value');
+    if (!validator.isValidUserName(currentValue)) {
+      return Em.I18n.t('users.userName.validationFail');
+    }
+    return null;
+  }
+});

+ 1 - 0
ambari-web/app/views/main/admin/user/create.js

@@ -90,6 +90,7 @@ App.MainAdminUserCreateView = Em.View.extend({
     }
     if (this.get('isPasswordDirty')) {
       this.get('userForm').isValid();
+      this.get('userForm').isWarn();
     }
   }.observes('userForm.fields.@each.value'),