step2_controller.js 11 KB

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