step4_controller.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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: ['admin_principal', '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 {Em.Object[]} configCategories
  40. * @param {App.ServiceConfigProperty[]} configs
  41. * @returns {Em.Object}
  42. */
  43. createServiceConfig: function(configCategories, configs) {
  44. return App.ServiceConfig.create({
  45. displayName: 'Kerberos Descriptor',
  46. name: 'KERBEROS',
  47. serviceName: 'KERBEROS',
  48. configCategories: configCategories,
  49. configs: configs,
  50. showConfig: true,
  51. selected: true
  52. });
  53. },
  54. /**
  55. * Prepare step configs using stack descriptor properties.
  56. *
  57. * @param {App.ServiceConfigProperty[]} configs
  58. */
  59. setStepConfigs: function(configs) {
  60. var selectedService = App.StackService.find().findProperty('serviceName', 'KERBEROS');
  61. var configCategories = selectedService.get('configCategories');
  62. var configProperties = this.prepareConfigProperties(configs);
  63. if (this.get('wizardController.name') == 'addServiceController') {
  64. // config properties for installed services should be disabled on Add Service Wizard
  65. configProperties.forEach(function(item) {
  66. if (this.get('adminPropertyNames').contains(item.get('name'))) return;
  67. if (this.get('installedServiceNames').contains(item.get('serviceName')) || item.get('serviceName') == 'Cluster') {
  68. item.set('isEditable', false);
  69. }
  70. }, this);
  71. }
  72. this.get('stepConfigs').pushObject(this.createServiceConfig(configCategories, configProperties));
  73. this.set('selectedService', this.get('stepConfigs')[0]);
  74. },
  75. /**
  76. * Filter configs by installed services for Kerberos Wizard or by installed + selected services
  77. * for Add Service Wizard.
  78. * Set property value observer.
  79. * Set realm property with value from previous configuration step.
  80. * Set appropriate category for all configs.
  81. *
  82. * @param {App.ServiceCofigProperty[]} configs
  83. * @returns {App.ServiceConfigProperty[]}
  84. */
  85. prepareConfigProperties: function(configs) {
  86. var self = this;
  87. var storedServiceConfigs = this.get('wizardController').getDBProperty('serviceConfigProperties');
  88. var realmValue = storedServiceConfigs.findProperty('name', 'realm').value;
  89. var installedServiceNames = ['Cluster'].concat(App.Service.find().mapProperty('serviceName'));
  90. var adminProps = [];
  91. var configProperties = configs.slice(0);
  92. if (this.get('wizardController.name') == 'addServiceController') {
  93. installedServiceNames = installedServiceNames.concat(this.get('selectedServiceNames'));
  94. this.get('adminPropertyNames').forEach(function(item) {
  95. var property = storedServiceConfigs.filterProperty('filename', 'krb5-conf.xml').findProperty('name', item);
  96. if (!!property) {
  97. var _prop = App.ServiceConfigProperty.create($.extend({}, property, { value: '', defaultValue: '', serviceName: 'Cluster', displayName: item }));
  98. _prop.validate();
  99. adminProps.push(_prop);
  100. }
  101. });
  102. configProperties = adminProps.concat(configProperties);
  103. }
  104. configProperties = configProperties.filter(function(item) {
  105. return installedServiceNames.contains(item.get('serviceName'));
  106. });
  107. configProperties.findProperty('name', 'realm').set('value', realmValue);
  108. configProperties.findProperty('name', 'realm').set('defaultValue', realmValue);
  109. configProperties.setEach('isSecureConfig', false);
  110. configProperties.forEach(function(property, item, allConfigs) {
  111. if (['spnego_keytab', 'spnego_principal'].contains(property.get('name'))) {
  112. property.addObserver('value', self, 'spnegoPropertiesObserver');
  113. }
  114. if (property.get('observesValueFrom')) {
  115. var observedValue = allConfigs.findProperty('name', property.get('observesValueFrom')).get('value');
  116. property.set('value', observedValue);
  117. property.set('defaultValue', observedValue);
  118. }
  119. if (property.get('serviceName') == 'Cluster') property.set('category', 'General');
  120. else property.set('category', 'Advanced');
  121. });
  122. return configProperties;
  123. },
  124. /**
  125. * Sync up values between inherited property and its reference.
  126. *
  127. * @param {App.ServiceConfigProperty} configProperty
  128. */
  129. spnegoPropertiesObserver: function(configProperty) {
  130. var self = this;
  131. this.get('stepConfigs')[0].get('configs').forEach(function(config) {
  132. if (config.get('observesValueFrom') == configProperty.get('name')) {
  133. Em.run.once(self, function() {
  134. config.set('value', configProperty.get('value'));
  135. config.set('defaultValue', configProperty.get('value'));
  136. });
  137. }
  138. });
  139. },
  140. submit: function() {
  141. this.saveConfigurations();
  142. App.router.send('next');
  143. },
  144. saveConfigurations: function() {
  145. var kerberosDescriptor = this.get('kerberosDescriptor');
  146. var configs = this.get('stepConfigs')[0].get('configs');
  147. this.updateKerberosDescriptor(kerberosDescriptor, configs);
  148. this.get('wizardController').setDBProperty('kerberosDescriptorConfigs', kerberosDescriptor);
  149. this.set('wizardController.content.kerberosDescriptorConfigs', kerberosDescriptor);
  150. }
  151. });