step4_controller.js 8.1 KB

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