step4_controller.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. if (this.get('wizardController.skipConfigureIdentitiesStep')) {
  30. App.router.send('next');
  31. return;
  32. }
  33. var self = this;
  34. this.clearStep();
  35. this.getDescriptorConfigs().then(function(properties) {
  36. self.setStepConfigs(properties);
  37. self.set('isRecommendedLoaded', true);
  38. });
  39. },
  40. /**
  41. * Create service config object for Kerberos service.
  42. *
  43. * @param {App.ServiceConfigProperty[]} configs
  44. * @returns {Em.Object}
  45. */
  46. createServiceConfig: function(configs) {
  47. // Identity configs related to user principal
  48. var clusterConfigs = configs.filterProperty('serviceName','Cluster');
  49. var nonClusterConfigs = configs.rejectProperty('serviceName','Cluster');
  50. var categoryForClusterConfigs = [
  51. App.ServiceConfigCategory.create({ name: 'Global', displayName: 'Global'}),
  52. App.ServiceConfigCategory.create({ name: 'Ambari Principals', displayName: 'Ambari Principals'})
  53. ];
  54. var categoryForNonClusterConfigs = this.createCategoryForServices();
  55. return [
  56. App.ServiceConfig.create({
  57. displayName: 'General',
  58. name: 'GENERAL',
  59. serviceName: 'KERBEROS_GENERAL',
  60. configCategories: categoryForClusterConfigs,
  61. configs: clusterConfigs,
  62. showConfig: true
  63. }),
  64. App.ServiceConfig.create({
  65. displayName: 'Advanced',
  66. name: 'ADVANCED',
  67. serviceName: 'KERBEROS_ADVANCED',
  68. configCategories: categoryForNonClusterConfigs,
  69. configs: nonClusterConfigs,
  70. showConfig: true
  71. })
  72. ];
  73. },
  74. /**
  75. * creates categories for advanced secure configs
  76. * @returns {[App.ServiceConfigCategory]}
  77. */
  78. createCategoryForServices: function() {
  79. var services = [];
  80. if (this.get('wizardController.name') == 'addServiceController') {
  81. services = App.StackService.find().filter(function(item) {
  82. return item.get('isInstalled') || item.get('isSelected');
  83. });
  84. } else {
  85. services = App.Service.find();
  86. }
  87. return services.map(function(item) {
  88. return App.ServiceConfigCategory.create({ name: item.get('serviceName'), displayName: item.get('displayName'), collapsedByDefault: true});
  89. });
  90. },
  91. /**
  92. * Prepare step configs using stack descriptor properties.
  93. *
  94. * @param {App.ServiceConfigProperty[]} configs
  95. */
  96. setStepConfigs: function(configs) {
  97. var configProperties = this.prepareConfigProperties(configs);
  98. if (this.get('wizardController.name') == 'addServiceController') {
  99. // config properties for installed services should be disabled on Add Service Wizard
  100. configProperties.forEach(function(item) {
  101. if (this.get('adminPropertyNames').mapProperty('name').contains(item.get('name'))) return;
  102. if (this.get('installedServiceNames').contains(item.get('serviceName')) || item.get('serviceName') == 'Cluster') {
  103. item.set('isEditable', false);
  104. }
  105. }, this);
  106. }
  107. this.get('stepConfigs').pushObjects(this.createServiceConfig(configProperties));
  108. this.set('selectedService', this.get('stepConfigs')[0]);
  109. },
  110. /**
  111. * Filter configs by installed services for Kerberos Wizard or by installed + selected services
  112. * for Add Service Wizard.
  113. * Set property value observer.
  114. * Set realm property with value from previous configuration step.
  115. * Set appropriate category for all configs.
  116. *
  117. * @param {App.ServiceConfigProperty[]} configs
  118. * @returns {App.ServiceConfigProperty[]}
  119. */
  120. prepareConfigProperties: function(configs) {
  121. var self = this;
  122. var storedServiceConfigs = this.get('wizardController').getDBProperty('serviceConfigProperties');
  123. var installedServiceNames = ['Cluster'].concat(App.Service.find().mapProperty('serviceName'));
  124. var adminProps = [];
  125. var configProperties = configs.slice(0);
  126. var siteProperties = App.config.get('preDefinedSiteProperties');
  127. if (this.get('wizardController.name') == 'addServiceController') {
  128. installedServiceNames = installedServiceNames.concat(this.get('selectedServiceNames'));
  129. this.get('adminPropertyNames').forEach(function(item) {
  130. var property = storedServiceConfigs.filterProperty('filename', 'krb5-conf.xml').findProperty('name', item.name);
  131. if (!!property) {
  132. var _prop = App.ServiceConfigProperty.create($.extend({}, property, { name: item.name, value: '', defaultValue: '', serviceName: 'Cluster', displayName: item.displayName}));
  133. _prop.validate();
  134. adminProps.push(_prop);
  135. }
  136. });
  137. configProperties = adminProps.concat(configProperties);
  138. }
  139. configProperties = configProperties.filter(function(item) {
  140. return installedServiceNames.contains(item.get('serviceName'));
  141. });
  142. if (this.get('wizardController.name') != 'addServiceController') {
  143. var realmValue = storedServiceConfigs.findProperty('name', 'realm').value;
  144. configProperties.findProperty('name', 'realm').set('value', realmValue);
  145. configProperties.findProperty('name', 'realm').set('defaultValue', realmValue);
  146. }
  147. configProperties.setEach('isSecureConfig', false);
  148. configProperties.forEach(function(property, item, allConfigs) {
  149. if (['spnego_keytab', 'spnego_principal'].contains(property.get('name'))) {
  150. property.addObserver('value', self, 'spnegoPropertiesObserver');
  151. }
  152. if (property.get('observesValueFrom')) {
  153. var observedValue = allConfigs.findProperty('name', property.get('observesValueFrom')).get('value');
  154. property.set('value', observedValue);
  155. property.set('defaultValue', observedValue);
  156. }
  157. if (property.get('serviceName') == 'Cluster') {
  158. property.set('category', 'Global');
  159. }
  160. else {
  161. property.set('category', property.get('serviceName'));
  162. }
  163. // All user identity should be grouped under "Ambari Principals" category
  164. if (property.get('identityType') == 'user') property.set('category', 'Ambari Principals');
  165. var siteProperty = siteProperties.findProperty('name', property.get('name'));
  166. if (siteProperty) {
  167. if (siteProperty.category === property.get('category')) {
  168. property.set('displayName',siteProperty.displayName);
  169. if (siteProperty.index) {
  170. property.set('index', siteProperty.index);
  171. }
  172. }
  173. }
  174. });
  175. return configProperties;
  176. },
  177. /**
  178. * Sync up values between inherited property and its reference.
  179. *
  180. * @param {App.ServiceConfigProperty} configProperty
  181. */
  182. spnegoPropertiesObserver: function(configProperty) {
  183. var self = this;
  184. var stepConfig = this.get('stepConfigs').findProperty('name', 'ADVANCED');
  185. stepConfig.get('configs').forEach(function(config) {
  186. if (config.get('observesValueFrom') == configProperty.get('name')) {
  187. Em.run.once(self, function() {
  188. config.set('value', configProperty.get('value'));
  189. config.set('defaultValue', configProperty.get('value'));
  190. });
  191. }
  192. });
  193. },
  194. submit: function() {
  195. this.saveConfigurations();
  196. App.router.send('next');
  197. },
  198. saveConfigurations: function() {
  199. var kerberosDescriptor = this.get('kerberosDescriptor');
  200. var configs = [];
  201. this.get('stepConfigs').forEach(function(_stepConfig){
  202. configs = configs.concat(_stepConfig.get('configs'));
  203. });
  204. this.updateKerberosDescriptor(kerberosDescriptor, configs);
  205. App.get('router.kerberosWizardController').saveKerberosDescriptorConfigs(kerberosDescriptor);
  206. }
  207. });