step2_controller.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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.KerberosWizardStep2Controller = App.WizardStep7Controller.extend(App.KDCCredentialsControllerMixin, {
  21. name: "kerberosWizardStep2Controller",
  22. isKerberosWizard: true,
  23. selectedServiceNames: ['KERBEROS'],
  24. allSelectedServiceNames: ['KERBEROS'],
  25. componentName: 'KERBEROS_CLIENT',
  26. installedServiceNames: [],
  27. servicesInstalled: false,
  28. addMiscTabToPage: false,
  29. /**
  30. * @type {boolean} true if test connection to hosts is in progress
  31. */
  32. testConnectionInProgress: false,
  33. /**
  34. * Should Back-button be disabled
  35. * @type {boolean}
  36. */
  37. isBackBtnDisabled: function() {
  38. return this.get('testConnectionInProgress');
  39. }.property('testConnectionInProgress'),
  40. /**
  41. * Should Next-button be disabled
  42. * @type {boolean}
  43. */
  44. isSubmitDisabled: function () {
  45. if (!this.get('stepConfigs.length') || this.get('testConnectionInProgress') || this.get('submitButtonClicked')) return true;
  46. return (!this.get('stepConfigs').filterProperty('showConfig', true).everyProperty('errorCount', 0) || this.get("miscModalVisible"));
  47. }.property('stepConfigs.@each.errorCount', 'miscModalVisible', 'submitButtonClicked', 'testConnectionInProgress'),
  48. hostNames: function () {
  49. return App.get('allHostNames');
  50. }.property('App.allHostNames'),
  51. serviceConfigTags: [],
  52. clearStep: function () {
  53. this._super();
  54. this.set('configs', []);
  55. this.get('serviceConfigTags').clear();
  56. this.set('servicesInstalled', false);
  57. },
  58. isConfigsLoaded: function () {
  59. return this.get('wizardController.stackConfigsLoaded');
  60. }.property('wizardController.stackConfigsLoaded'),
  61. /**
  62. * On load function
  63. * @method loadStep
  64. */
  65. loadStep: function () {
  66. if (!App.StackService.find().someProperty('serviceName', 'KERBEROS') || !this.get('isConfigsLoaded')) {
  67. return;
  68. }
  69. this.clearStep();
  70. //STEP 2: Load on-site configs by service from local DB
  71. var storedConfigs = this.get('content.serviceConfigProperties');
  72. //STEP 3: Merge pre-defined configs with loaded on-site configs
  73. this.set('configs', App.cfgCollection.getAll());
  74. App.config.setPreDefinedServiceConfigs(this.get('addMiscTabToPage'));
  75. this.filterConfigs(this.get('configs'));
  76. if (App.get('supports.storeKDCCredentials') && !this.get('wizardController.skipClientInstall')) {
  77. this.initilizeKDCStoreProperties(this.get('configs'));
  78. }
  79. this.applyServicesConfigs(this.get('configs'), storedConfigs);
  80. },
  81. /**
  82. * Make Active Directory specific configs visible if user has selected AD option
  83. * @param configs
  84. */
  85. filterConfigs: function (configs) {
  86. var kdcType = this.get('content.kerberosOption');
  87. var adConfigNames = ['ldap_url', 'container_dn', 'ad_create_attributes_template'];
  88. var mitConfigNames = ['kdc_create_attributes'];
  89. var kerberosWizardController = this.controllers.get('kerberosWizardController');
  90. var manageIdentitiesConfig = configs.findProperty('name', 'manage_identities');
  91. if (kdcType === Em.I18n.t('admin.kerberos.wizard.step1.option.manual')) {
  92. if (kerberosWizardController.get('skipClientInstall')) {
  93. kerberosWizardController.overrideVisibility(configs, false, kerberosWizardController.get('exceptionsOnSkipClient'));
  94. }
  95. return;
  96. } else if (manageIdentitiesConfig) {
  97. manageIdentitiesConfig.isVisible = false;
  98. manageIdentitiesConfig.value = 'true';
  99. }
  100. adConfigNames.forEach(function (_configName) {
  101. var config = configs.findProperty('name', _configName);
  102. if (config) {
  103. config.isVisible = kdcType === Em.I18n.t('admin.kerberos.wizard.step1.option.ad');
  104. }
  105. }, this);
  106. mitConfigNames.forEach(function (_configName) {
  107. var config = configs.findProperty('name', _configName);
  108. if (config) {
  109. config.isVisible = kdcType === Em.I18n.t('admin.kerberos.wizard.step1.option.kdc');
  110. }
  111. }, this);
  112. },
  113. submit: function () {
  114. if (this.get('isSubmitDisabled')) return false;
  115. this.set('isSubmitDisabled', true);
  116. var self = this;
  117. this.deleteKerberosService().always(function () {
  118. self.configureKerberos();
  119. if (App.get('supports.storeKDCCredentials') && !self.get('wizardController.skipClientInstall')) {
  120. self.createKDCCredentials(self.get('stepConfigs.0.configs'));
  121. }
  122. });
  123. },
  124. configureKerberos: function () {
  125. var self = this;
  126. var wizardController = App.router.get(this.get('content.controllerName'));
  127. var callback = function () {
  128. self.createConfigurations().done(function () {
  129. self.createKerberosAdminSession().done(function () {
  130. App.router.send('next');
  131. });
  132. });
  133. };
  134. if (wizardController.get('skipClientInstall')) {
  135. callback();
  136. } else {
  137. wizardController.createKerberosResources(callback);
  138. }
  139. },
  140. /**
  141. * Delete Kerberos service if it exists
  142. */
  143. deleteKerberosService: function () {
  144. var serviceName = this.selectedServiceNames[0];
  145. if (App.cache.services.someProperty('ServiceInfo.service_name', 'KERBEROS')) {
  146. App.cache.services.removeAt(App.cache.services.indexOf(App.cache.services.findProperty('ServiceInfo.service_name', 'KERBEROS')));
  147. }
  148. if (App.Service.find().someProperty('serviceName', 'KERBEROS')) {
  149. App.serviceMapper.deleteRecord(App.Service.find('KERBEROS'));
  150. }
  151. return App.ajax.send({
  152. name: 'common.delete.service',
  153. sender: this,
  154. data: {
  155. serviceName: serviceName
  156. }
  157. });
  158. },
  159. createConfigurations: function () {
  160. var service = App.StackService.find().findProperty('serviceName', 'KERBEROS');
  161. var serviceConfigTags = [];
  162. var tag = 'version' + (new Date).getTime();
  163. Object.keys(service.get('configTypes')).forEach(function (type) {
  164. if (!serviceConfigTags.someProperty('type', type)) {
  165. var obj = this.createKerberosSiteObj(type, tag);
  166. obj.service_config_version_note = Em.I18n.t('admin.kerberos.wizard.configuration.note');
  167. serviceConfigTags.pushObject(obj);
  168. }
  169. }, this);
  170. var allConfigData = [];
  171. var serviceConfigData = [];
  172. Object.keys(service.get('configTypesRendered')).forEach(function (type) {
  173. var serviceConfigTag = serviceConfigTags.findProperty('type', type);
  174. if (serviceConfigTag) {
  175. serviceConfigData.pushObject(serviceConfigTag);
  176. }
  177. }, this);
  178. if (serviceConfigData.length) {
  179. allConfigData.pushObject(JSON.stringify({
  180. Clusters: {
  181. desired_config: serviceConfigData
  182. }
  183. }));
  184. }
  185. return App.ajax.send({
  186. name: 'common.across.services.configurations',
  187. sender: this,
  188. data: {
  189. data: '[' + allConfigData.toString() + ']'
  190. }
  191. });
  192. },
  193. createKerberosSiteObj: function (site, tag) {
  194. var properties = {};
  195. var content = this.get('stepConfigs')[0].get('configs');
  196. var configs = content.filterProperty('filename', site + '.xml');
  197. // properties that should be formated as hosts
  198. var hostProperties = ['kdc_host', 'realm'];
  199. configs.forEach(function (_configProperty) {
  200. // do not pass any globals whose name ends with _host or _hosts
  201. if (_configProperty.isRequiredByAgent !== false) {
  202. if (hostProperties.contains(_configProperty.name)) {
  203. properties[_configProperty.name] = App.config.trimProperty({displayType: 'host', value: _configProperty.value});
  204. } else {
  205. properties[_configProperty.name] = App.config.trimProperty(_configProperty);
  206. }
  207. }
  208. }, this);
  209. this.tweakKdcTypeValue(properties);
  210. this.tweakManualKdcProperties(properties);
  211. return {"type": site, "tag": tag, "properties": properties};
  212. },
  213. tweakKdcTypeValue: function (properties) {
  214. for (var prop in App.router.get('mainAdminKerberosController.kdcTypesValues')) {
  215. if (App.router.get('mainAdminKerberosController.kdcTypesValues').hasOwnProperty(prop)) {
  216. if (App.router.get('mainAdminKerberosController.kdcTypesValues')[prop] === properties['kdc_type']) {
  217. properties['kdc_type'] = prop;
  218. }
  219. }
  220. }
  221. },
  222. tweakManualKdcProperties: function (properties) {
  223. var kerberosWizardController = this.controllers.get('kerberosWizardController');
  224. if (properties['kdc_type'] === 'none' || kerberosWizardController.get('skipClientInstall')) {
  225. if (properties.hasOwnProperty('manage_identities')) {
  226. properties['manage_identities'] = 'false';
  227. }
  228. if (properties.hasOwnProperty('install_packages')) {
  229. properties['install_packages'] = 'false';
  230. }
  231. if (properties.hasOwnProperty('manage_krb5_conf')) {
  232. properties['manage_krb5_conf'] = 'false';
  233. }
  234. }
  235. },
  236. /**
  237. * puts kerberos admin credentials in the live cluster session
  238. * @returns {*} jqXHr
  239. */
  240. createKerberosAdminSession: function (configs) {
  241. configs = configs || this.get('stepConfigs')[0].get('configs');
  242. var adminPrincipalValue = configs.findProperty('name', 'admin_principal').value;
  243. var adminPasswordValue = configs.findProperty('name', 'admin_password').value;
  244. return App.ajax.send({
  245. name: 'common.cluster.update',
  246. sender: this,
  247. data: {
  248. clusterName: App.get('clusterName') || App.clusterStatus.get('clusterName'),
  249. data: [{
  250. session_attributes: {
  251. kerberos_admin: {principal: adminPrincipalValue, password: adminPasswordValue}
  252. }
  253. }]
  254. }
  255. });
  256. },
  257. /**
  258. * shows popup with to warn user
  259. * @param primary
  260. */
  261. showConnectionInProgressPopup: function(primary) {
  262. var primaryText = Em.I18n.t('common.exitAnyway');
  263. var msg = Em.I18n.t('services.service.config.connection.exitPopup.msg');
  264. App.showConfirmationPopup(primary, msg, null, null, primaryText)
  265. }
  266. });