step4_controller.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('controllers/wizard/step7_controller');
  20. App.KerberosWizardStep4Controller = App.WizardStep7Controller.extend(App.AddSecurityConfigs, {
  21. name: 'kerberosWizardStep4Controller',
  22. adminPropertyNames: [{name: 'admin_principal', displayName: 'Admin principal'}, {name: 'admin_password', displayName: 'Admin password'}],
  23. clearStep: function() {
  24. this.set('isRecommendedLoaded', false);
  25. this.set('selectedService', null);
  26. this.set('stepConfigs', []);
  27. },
  28. loadStep: function() {
  29. var self = this;
  30. this.clearStep();
  31. this.getStackDescriptorConfigs().then(function(properties) {
  32. self.setStepConfigs(properties);
  33. self.set('isRecommendedLoaded', true);
  34. });
  35. },
  36. /**
  37. * Create service config object for Kerberos service.
  38. *
  39. * @param {App.ServiceConfigProperty[]} configs
  40. * @returns {Em.Object}
  41. */
  42. createServiceConfig: function(configs) {
  43. // Identity configs related to user principal
  44. var clusterConfigs = configs.filterProperty('serviceName','Cluster');
  45. var nonClusterConfigs = configs.rejectProperty('serviceName','Cluster');
  46. var categoryForClusterConfigs = [
  47. App.ServiceConfigCategory.create({ name: 'Global', displayName: 'Global'}),
  48. App.ServiceConfigCategory.create({ name: 'Ambari Principals', displayName: 'Ambari Principals'})
  49. ];
  50. var categoryForNonClusterConfigs = this.createCategoryForServices();
  51. return [
  52. App.ServiceConfig.create({
  53. displayName: 'General',
  54. name: 'GENERAL',
  55. serviceName: 'KERBEROS_GENERAL',
  56. configCategories: categoryForClusterConfigs,
  57. configs: clusterConfigs,
  58. showConfig: true
  59. }),
  60. App.ServiceConfig.create({
  61. displayName: 'Advanced',
  62. name: 'ADVANCED',
  63. serviceName: 'KERBEROS_ADVANCED',
  64. configCategories: categoryForNonClusterConfigs,
  65. configs: nonClusterConfigs,
  66. showConfig: true
  67. })
  68. ];
  69. },
  70. createCategoryForServices: function() {
  71. return App.Service.find().mapProperty('serviceName').map(function(item) {
  72. return App.ServiceConfigCategory.create({ name: item, displayName: App.Service.find().findProperty('serviceName',item).get('displayName'), collapsedByDefault: true});
  73. })
  74. },
  75. /**
  76. * Prepare step configs using stack descriptor properties.
  77. *
  78. * @param {App.ServiceConfigProperty[]} configs
  79. */
  80. setStepConfigs: function(configs) {
  81. var configProperties = this.prepareConfigProperties(configs);
  82. if (this.get('wizardController.name') == 'addServiceController') {
  83. // config properties for installed services should be disabled on Add Service Wizard
  84. configProperties.forEach(function(item) {
  85. if (this.get('adminPropertyNames').mapProperty('name').contains(item.get('name'))) return;
  86. if (this.get('installedServiceNames').contains(item.get('serviceName')) || item.get('serviceName') == 'Cluster') {
  87. item.set('isEditable', false);
  88. }
  89. }, this);
  90. }
  91. this.get('stepConfigs').pushObjects(this.createServiceConfig(configProperties));
  92. this.set('selectedService', this.get('stepConfigs')[0]);
  93. },
  94. /**
  95. * Filter configs by installed services for Kerberos Wizard or by installed + selected services
  96. * for Add Service Wizard.
  97. * Set property value observer.
  98. * Set realm property with value from previous configuration step.
  99. * Set appropriate category for all configs.
  100. *
  101. * @param {App.ServiceConfigProperty[]} configs
  102. * @returns {App.ServiceConfigProperty[]}
  103. */
  104. prepareConfigProperties: function(configs) {
  105. var self = this;
  106. var storedServiceConfigs = this.get('wizardController').getDBProperty('serviceConfigProperties');
  107. var realmValue = storedServiceConfigs.findProperty('name', 'realm').value;
  108. var installedServiceNames = ['Cluster'].concat(App.Service.find().mapProperty('serviceName'));
  109. var adminProps = [];
  110. var configProperties = configs.slice(0);
  111. var siteProperties = App.config.get('preDefinedSiteProperties');
  112. if (this.get('wizardController.name') == 'addServiceController') {
  113. installedServiceNames = installedServiceNames.concat(this.get('selectedServiceNames'));
  114. this.get('adminPropertyNames').forEach(function(item) {
  115. var property = storedServiceConfigs.filterProperty('filename', 'krb5-conf.xml').findProperty('name', item.name);
  116. if (!!property) {
  117. var _prop = App.ServiceConfigProperty.create($.extend({}, property, { name: item.name, value: '', defaultValue: '', serviceName: 'Cluster', displayName: item.displayName}));
  118. _prop.validate();
  119. adminProps.push(_prop);
  120. }
  121. });
  122. configProperties = adminProps.concat(configProperties);
  123. }
  124. configProperties = configProperties.filter(function(item) {
  125. return installedServiceNames.contains(item.get('serviceName'));
  126. });
  127. configProperties.findProperty('name', 'realm').set('value', realmValue);
  128. configProperties.findProperty('name', 'realm').set('defaultValue', realmValue);
  129. configProperties.setEach('isSecureConfig', false);
  130. configProperties.forEach(function(property, item, allConfigs) {
  131. if (['spnego_keytab', 'spnego_principal'].contains(property.get('name'))) {
  132. property.addObserver('value', self, 'spnegoPropertiesObserver');
  133. }
  134. if (property.get('observesValueFrom')) {
  135. var observedValue = allConfigs.findProperty('name', property.get('observesValueFrom')).get('value');
  136. property.set('value', observedValue);
  137. property.set('defaultValue', observedValue);
  138. }
  139. if (property.get('serviceName') == 'Cluster') {
  140. property.set('category', 'Global');
  141. }
  142. else {
  143. property.set('category', property.get('serviceName'));
  144. }
  145. // All user identity should be grouped under "Ambari Principals" category
  146. if (property.get('identityType') == 'user') property.set('category', 'Ambari Principals');
  147. var siteProperty = siteProperties.findProperty('name', property.get('name'));
  148. if (siteProperty) {
  149. if (siteProperty.category === property.get('category')) {
  150. property.set('displayName',siteProperty.displayName);
  151. if (siteProperty.index) {
  152. property.set('index', siteProperty.index);
  153. }
  154. }
  155. }
  156. });
  157. return configProperties;
  158. },
  159. /**
  160. * Sync up values between inherited property and its reference.
  161. *
  162. * @param {App.ServiceConfigProperty} configProperty
  163. */
  164. spnegoPropertiesObserver: function(configProperty) {
  165. var self = this;
  166. var stepConfig = this.get('stepConfigs').findProperty('name', 'ADVANCED');
  167. stepConfig.get('configs').forEach(function(config) {
  168. if (config.get('observesValueFrom') == configProperty.get('name')) {
  169. Em.run.once(self, function() {
  170. config.set('value', configProperty.get('value'));
  171. config.set('defaultValue', configProperty.get('value'));
  172. });
  173. }
  174. });
  175. },
  176. submit: function() {
  177. this.saveConfigurations();
  178. App.router.send('next');
  179. },
  180. saveConfigurations: function() {
  181. var kerberosDescriptor = this.get('kerberosDescriptor');
  182. var configs = [];
  183. this.get('stepConfigs').forEach(function(_stepConfig){
  184. configs = configs.concat(_stepConfig.get('configs'));
  185. });
  186. this.updateKerberosDescriptor(kerberosDescriptor, configs);
  187. App.get('router.kerberosWizardController').saveKerberosDescriptorConfigs(kerberosDescriptor);
  188. }
  189. });