step4_controller.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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.getDescriptorConfigs().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. /**
  71. * creates categories for advanced secure configs
  72. * @returns {[App.ServiceConfigCategory]}
  73. */
  74. createCategoryForServices: function() {
  75. var services = App.StackService.find().filter(function(s) {
  76. return s.get('isInstalled') || (s.get('isSelected') && this.get('wizardController.name') == 'addServiceController');
  77. }, this);
  78. return services.map(function(item) {
  79. return App.ServiceConfigCategory.create({ name: item.get('serviceName'), displayName: item.get('displayName'), collapsedByDefault: true});
  80. })
  81. },
  82. /**
  83. * Prepare step configs using stack descriptor properties.
  84. *
  85. * @param {App.ServiceConfigProperty[]} configs
  86. */
  87. setStepConfigs: function(configs) {
  88. var configProperties = this.prepareConfigProperties(configs);
  89. if (this.get('wizardController.name') == 'addServiceController') {
  90. // config properties for installed services should be disabled on Add Service Wizard
  91. configProperties.forEach(function(item) {
  92. if (this.get('adminPropertyNames').mapProperty('name').contains(item.get('name'))) return;
  93. if (this.get('installedServiceNames').contains(item.get('serviceName')) || item.get('serviceName') == 'Cluster') {
  94. item.set('isEditable', false);
  95. }
  96. }, this);
  97. }
  98. this.get('stepConfigs').pushObjects(this.createServiceConfig(configProperties));
  99. this.set('selectedService', this.get('stepConfigs')[0]);
  100. },
  101. /**
  102. * Filter configs by installed services for Kerberos Wizard or by installed + selected services
  103. * for Add Service Wizard.
  104. * Set property value observer.
  105. * Set realm property with value from previous configuration step.
  106. * Set appropriate category for all configs.
  107. *
  108. * @param {App.ServiceConfigProperty[]} configs
  109. * @returns {App.ServiceConfigProperty[]}
  110. */
  111. prepareConfigProperties: function(configs) {
  112. var self = this;
  113. var storedServiceConfigs = this.get('wizardController').getDBProperty('serviceConfigProperties');
  114. var installedServiceNames = ['Cluster'].concat(App.Service.find().mapProperty('serviceName'));
  115. var adminProps = [];
  116. var configProperties = configs.slice(0);
  117. var siteProperties = App.config.get('preDefinedSiteProperties');
  118. if (this.get('wizardController.name') == 'addServiceController') {
  119. installedServiceNames = installedServiceNames.concat(this.get('selectedServiceNames'));
  120. this.get('adminPropertyNames').forEach(function(item) {
  121. var property = storedServiceConfigs.filterProperty('filename', 'krb5-conf.xml').findProperty('name', item.name);
  122. if (!!property) {
  123. var _prop = App.ServiceConfigProperty.create($.extend({}, property, { name: item.name, value: '', defaultValue: '', serviceName: 'Cluster', displayName: item.displayName}));
  124. _prop.validate();
  125. adminProps.push(_prop);
  126. }
  127. });
  128. configProperties = adminProps.concat(configProperties);
  129. }
  130. configProperties = configProperties.filter(function(item) {
  131. return installedServiceNames.contains(item.get('serviceName'));
  132. });
  133. if (this.get('wizardController.name') != 'addServiceController') {
  134. var realmValue = storedServiceConfigs.findProperty('name', 'realm').value;
  135. configProperties.findProperty('name', 'realm').set('value', realmValue);
  136. configProperties.findProperty('name', 'realm').set('defaultValue', realmValue);
  137. }
  138. configProperties.setEach('isSecureConfig', false);
  139. configProperties.forEach(function(property, item, allConfigs) {
  140. if (['spnego_keytab', 'spnego_principal'].contains(property.get('name'))) {
  141. property.addObserver('value', self, 'spnegoPropertiesObserver');
  142. }
  143. if (property.get('observesValueFrom')) {
  144. var observedValue = allConfigs.findProperty('name', property.get('observesValueFrom')).get('value');
  145. property.set('value', observedValue);
  146. property.set('defaultValue', observedValue);
  147. }
  148. if (property.get('serviceName') == 'Cluster') {
  149. property.set('category', 'Global');
  150. }
  151. else {
  152. property.set('category', property.get('serviceName'));
  153. }
  154. // All user identity should be grouped under "Ambari Principals" category
  155. if (property.get('identityType') == 'user') property.set('category', 'Ambari Principals');
  156. var siteProperty = siteProperties.findProperty('name', property.get('name'));
  157. if (siteProperty) {
  158. if (siteProperty.category === property.get('category')) {
  159. property.set('displayName',siteProperty.displayName);
  160. if (siteProperty.index) {
  161. property.set('index', siteProperty.index);
  162. }
  163. }
  164. }
  165. });
  166. return configProperties;
  167. },
  168. /**
  169. * Sync up values between inherited property and its reference.
  170. *
  171. * @param {App.ServiceConfigProperty} configProperty
  172. */
  173. spnegoPropertiesObserver: function(configProperty) {
  174. var self = this;
  175. var stepConfig = this.get('stepConfigs').findProperty('name', 'ADVANCED');
  176. stepConfig.get('configs').forEach(function(config) {
  177. if (config.get('observesValueFrom') == configProperty.get('name')) {
  178. Em.run.once(self, function() {
  179. config.set('value', configProperty.get('value'));
  180. config.set('defaultValue', configProperty.get('value'));
  181. });
  182. }
  183. });
  184. },
  185. submit: function() {
  186. this.saveConfigurations();
  187. App.router.send('next');
  188. },
  189. saveConfigurations: function() {
  190. var kerberosDescriptor = this.get('kerberosDescriptor');
  191. var configs = [];
  192. this.get('stepConfigs').forEach(function(_stepConfig){
  193. configs = configs.concat(_stepConfig.get('configs'));
  194. });
  195. this.updateKerberosDescriptor(kerberosDescriptor, configs);
  196. App.get('router.kerberosWizardController').saveKerberosDescriptorConfigs(kerberosDescriptor);
  197. }
  198. });