step2_controller.js 12 KB

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