kerberos.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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/main/admin/kerberos/step4_controller');
  20. App.MainAdminKerberosController = App.KerberosWizardStep4Controller.extend({
  21. name: 'mainAdminKerberosController',
  22. securityEnabled: false,
  23. defaultKerberosLoaded: false,
  24. dataIsLoaded: false,
  25. isRecommendedLoaded: true,
  26. kdc_type: '',
  27. kdcTypesValues: {
  28. 'mit-kdc' : Em.I18n.t('admin.kerberos.wizard.step1.option.kdc'),
  29. 'active-directory': Em.I18n.t('admin.kerberos.wizard.step1.option.ad'),
  30. 'none' : Em.I18n.t('admin.kerberos.wizard.step1.option.manual')
  31. },
  32. getAddSecurityWizardStatus: function () {
  33. return App.db.getSecurityWizardStatus();
  34. },
  35. setAddSecurityWizardStatus: function (status) {
  36. App.db.setSecurityWizardStatus(status);
  37. },
  38. setDisableSecurityStatus: function (status) {
  39. App.db.setDisableSecurityStatus(status);
  40. },
  41. getDisableSecurityStatus: function (status) {
  42. return App.db.getDisableSecurityStatus();
  43. },
  44. notifySecurityOff: false,
  45. notifySecurityAdd: false,
  46. notifySecurityOffPopup: function () {
  47. var self = this;
  48. App.ModalPopup.show({
  49. header: Em.I18n.t('popup.confirmation.commonHeader'),
  50. primary: Em.I18n.t('ok'),
  51. onPrimary: function () {
  52. App.db.setSecurityDeployCommands(undefined);
  53. self.setDisableSecurityStatus("RUNNING");
  54. App.router.transitionTo('disableSecurity');
  55. this.hide();
  56. },
  57. bodyClass: Ember.View.extend({
  58. templateName: require('templates/main/admin/kerberos/notify_security_off_popup')
  59. })
  60. });
  61. },
  62. /**
  63. * Show confirmation popup for regenerate keytabs
  64. * @method regenerateKeytabs
  65. * @return {App.ModalPopup}
  66. */
  67. regenerateKeytabs: function () {
  68. var self = this;
  69. return App.ModalPopup.show({
  70. /**
  71. * True - regenerate keytabs only for missing hosts and components, false - regenerate for all hosts and components
  72. * @type {boolean}
  73. */
  74. regenerateKeytabsOnlyForMissing: false,
  75. header: Em.I18n.t('admin.kerberos.button.regenerateKeytabs'),
  76. bodyClass: Em.View.extend({
  77. templateName: require('templates/main/admin/kerberos/regenerate_keytabs_popup_body')
  78. }),
  79. onPrimary: function () {
  80. this._super();
  81. return self.restartServicesAfterRegenerate(this.get('regenerateKeytabsOnlyForMissing'));
  82. }
  83. });
  84. },
  85. /**
  86. * Show confirmation popup for restarting all services and after confirmation regenerate keytabs
  87. *
  88. * @param regenerateKeytabsOnlyForMissing {Boolean}
  89. * @returns {*}
  90. */
  91. restartServicesAfterRegenerate: function (regenerateKeytabsOnlyForMissing) {
  92. var self = this;
  93. return App.ModalPopup.show({
  94. /**
  95. * True - automatically restart services, false - user will have to restart required services manually
  96. * @type {boolean}
  97. */
  98. restartComponents: false,
  99. header: Em.I18n.t('admin.kerberos.button.regenerateKeytabs'),
  100. bodyClass: Em.View.extend({
  101. templateName: require('templates/main/admin/kerberos/restart_services_after_regenerate_body')
  102. }),
  103. onPrimary: function () {
  104. this._super();
  105. self.regenerateKeytabsRequest(regenerateKeytabsOnlyForMissing, this.get('restartComponents'));
  106. }
  107. });
  108. },
  109. /**
  110. * Send request to regenerate keytabs
  111. * @param {boolean} missingOnly determines type of regeneration - missing|all
  112. * @param {boolean} withAutoRestart determines if the system should automatically restart all services or not after regeneration
  113. * @returns {$.ajax}
  114. */
  115. regenerateKeytabsRequest: function (missingOnly, withAutoRestart) {
  116. missingOnly = missingOnly || false;
  117. return App.ajax.send({
  118. name: "admin.kerberos_security.regenerate_keytabs",
  119. sender: this,
  120. data: {
  121. type: missingOnly ? 'missing' : 'all',
  122. withAutoRestart: withAutoRestart || false
  123. },
  124. success: "regenerateKeytabsSuccess"
  125. });
  126. },
  127. /**
  128. * Success callback of <code>regenerateKeytabs</code>
  129. * show background operations popup if appropriate option is set
  130. *
  131. * @param data
  132. * @param opt
  133. * @param params
  134. * @param request
  135. */
  136. regenerateKeytabsSuccess: function (data, opt, params, request) {
  137. var self = this;
  138. App.router.get('applicationController').dataLoading().done(function (initValue) {
  139. if (initValue) {
  140. App.router.get('backgroundOperationsController').showPopup();
  141. }
  142. self.set('needsRestartAfterRegenerate', params.withAutoRestart);
  143. });
  144. },
  145. /**
  146. * Do request to server for restarting all services
  147. * @method restartAllServices
  148. * @return {$.ajax}
  149. */
  150. restartAllServices: function () {
  151. if (!App.router.get('backgroundOperationsController.allOperationsCount')) {
  152. if (this.get('needsRestartAfterRegenerate')) {
  153. this.set('needsRestartAfterRegenerate', false);
  154. App.router.get('mainServiceController').restartAllServices();
  155. }
  156. }
  157. }.observes('controllers.backgroundOperationsController.allOperationsCount'),
  158. getUpdatedSecurityStatus: function () {
  159. this.getSecurityStatus();
  160. return this.get('securityEnabled');
  161. },
  162. /**
  163. * performs cluster check before kerbefos security
  164. * wizard starts if <code>preKerberizeCheck<code> supports is true
  165. * otherwise runs <code>startKerberosWizard<code>
  166. * @method checkAndStartKerberosWizard
  167. */
  168. checkAndStartKerberosWizard: function() {
  169. if (App.get('supports.preKerberizeCheck')) {
  170. App.ajax.send({
  171. name: "admin.kerberos_security.checks",
  172. sender: this,
  173. success: "runSecurityCheckSuccess"
  174. });
  175. } else {
  176. this.startKerberosWizard();
  177. }
  178. },
  179. /**
  180. * success callback of <code>checkAndStartKerberosWizard()</code>
  181. * if there are some fails - it shows popup else open security wizard
  182. * @param data {object}
  183. * @param opt {object}
  184. * @param params {object}
  185. */
  186. runSecurityCheckSuccess: function (data, opt, params) {
  187. //TODO correct check
  188. if (data.items.someProperty('UpgradeChecks.status', "FAIL")) {
  189. var header = Em.I18n.t('popup.clusterCheck.Security.header').format(params.label);
  190. var title = Em.I18n.t('popup.clusterCheck.Security.title');
  191. var alert = Em.I18n.t('popup.clusterCheck.Security.alert');
  192. App.showClusterCheckPopup(data, header, title, alert);
  193. } else {
  194. this.startKerberosWizard();
  195. }
  196. },
  197. startKerberosWizard: function () {
  198. this.setAddSecurityWizardStatus('RUNNING');
  199. App.router.get('kerberosWizardController').setDBProperty('onClosePath', 'main.admin.adminKerberos.index');
  200. App.router.transitionTo('adminKerberos.adminAddKerberos');
  201. },
  202. /**
  203. * Loads the security status from server (security_enabled property in cluster-env configuration)
  204. */
  205. loadSecurityStatusFromServer: function () {
  206. if (App.get('testMode')) {
  207. this.set('securityEnabled', !App.get('testEnableSecurity'));
  208. this.set('dataIsLoaded', true);
  209. } else {
  210. //get Security Status From Server
  211. this.getSecurityType();
  212. return this.getSecurityStatus();
  213. }
  214. },
  215. /**
  216. * Load security status from server.
  217. * @returns {$.Deferred}
  218. */
  219. getSecurityStatus: function () {
  220. var self = this;
  221. var dfd = $.Deferred();
  222. if (App.get('testMode')) {
  223. this.set('securityEnabled', !App.get('testEnableSecurity'));
  224. this.set('dataIsLoaded', true);
  225. dfd.resolve();
  226. } else {
  227. //get Security Status From Server
  228. App.ajax.send({
  229. name: 'admin.security_status',
  230. sender: this,
  231. success: 'getSecurityStatusSuccessCallback',
  232. error: 'errorCallback'
  233. })
  234. .always(this.getSecurityType.bind(this))
  235. .always(function() {
  236. // check for kerberos descriptor artifact
  237. if (self.get('securityEnabled')) {
  238. self.loadClusterDescriptorConfigs().then(function() {
  239. dfd.resolve();
  240. }, function() {
  241. // if kerberos descriptor doesn't exist in cluster artifacts get the default descriptor
  242. self.loadStackDescriptorConfigs().then(function() {
  243. self.set('defaultKerberosLoaded', true);
  244. dfd.resolve();
  245. }, function() {
  246. self.set('securityEnabled', false);
  247. dfd.resolve();
  248. });
  249. });
  250. } else {
  251. dfd.resolve();
  252. }
  253. });
  254. }
  255. return dfd.promise();
  256. },
  257. getSecurityStatusSuccessCallback: function(data) {
  258. this.set('dataIsLoaded', true);
  259. var securityType = data.Clusters.security_type;
  260. this.set('securityEnabled', securityType === 'KERBEROS');
  261. },
  262. errorCallback: function (jqXHR) {
  263. this.set('dataIsLoaded', true);
  264. // Show the error popup if the API call received a response from the server.
  265. // jqXHR.status will be empty when browser cancels the request. Refer to AMBARI-5921 for more info
  266. if (!!jqXHR.status) {
  267. this.showSecurityErrorPopup();
  268. }
  269. },
  270. showSecurityErrorPopup: function () {
  271. App.ModalPopup.show({
  272. header: Em.I18n.t('common.error'),
  273. secondary: false,
  274. bodyClass: Ember.View.extend({
  275. template: Ember.Handlebars.compile('<p>{{t admin.security.status.error}}</p>')
  276. })
  277. });
  278. },
  279. /**
  280. * Override <code>App.KerberosWizardStep4Controller</code>
  281. *
  282. * @param {App.ServiceConfigProperty[]} properties
  283. */
  284. setStepConfigs: function (properties) {
  285. this.get('stepConfigs').clear();
  286. this._super(properties);
  287. },
  288. /**
  289. * Override <code>App.KerberosWizardStep4Controller</code>
  290. *
  291. * @param {App.ServiceConfigProperty[]} configs
  292. * @returns {App.ServiceConfigProperty[]}
  293. */
  294. prepareConfigProperties: function(configs) {
  295. var configProperties = configs.slice(0);
  296. var siteProperties = App.config.get('preDefinedSiteProperties');
  297. var installedServiceNames = ['Cluster'].concat(App.Service.find().mapProperty('serviceName'));
  298. configProperties = configProperties.filter(function(item) {
  299. return installedServiceNames.contains(item.get('serviceName'));
  300. });
  301. configProperties.setEach('isSecureConfig', false);
  302. configProperties.forEach(function(property, item, allConfigs) {
  303. if (property.get('observesValueFrom')) {
  304. var observedValue = allConfigs.findProperty('name', property.get('observesValueFrom')).get('value');
  305. property.set('value', observedValue);
  306. property.set('recommendedValue', observedValue);
  307. }
  308. if (property.get('serviceName') == 'Cluster') {
  309. property.set('category', 'Global');
  310. } else {
  311. property.set('category', property.get('serviceName'));
  312. }
  313. // All user identity should be grouped under "Ambari Principals" category
  314. if (property.get('identityType') == 'user') property.set('category', 'Ambari Principals');
  315. var siteProperty = siteProperties.findProperty('name', property.get('name'));
  316. if (siteProperty) {
  317. if (siteProperty.category === property.get('category')) {
  318. property.set('displayName',siteProperty.displayName);
  319. if (siteProperty.index) {
  320. property.set('index', siteProperty.index);
  321. }
  322. }
  323. if (siteProperty.displayType) {
  324. property.set('displayType', siteProperty.displayType);
  325. }
  326. }
  327. });
  328. configProperties.setEach('isEditable', false);
  329. return configProperties;
  330. },
  331. getKDCSessionState: function(callback, kdcCancelHandler) {
  332. if (this.get('securityEnabled')) {
  333. App.ajax.send({
  334. name: 'kerberos.session.state',
  335. sender: this,
  336. data: {
  337. callback: callback
  338. },
  339. success: 'checkState',
  340. kdcCancelHandler: kdcCancelHandler
  341. })
  342. } else {
  343. callback();
  344. }
  345. },
  346. getSecurityType: function (callback) {
  347. if (this.get('securityEnabled')) {
  348. return App.ajax.send({
  349. name: 'admin.security.cluster_configs.kerberos',
  350. sender: this,
  351. data: {
  352. clusterName: App.get('clusterName'),
  353. additionalCallback: callback
  354. },
  355. success: 'getSecurityTypeSuccess'
  356. });
  357. } else if (Em.typeOf(callback)=== 'function') {
  358. callback();
  359. } else {
  360. return $.Deferred().resolve().promise;
  361. }
  362. },
  363. getSecurityTypeSuccess: function (data, opt, params) {
  364. var kdcType = data.items && data.items[0] &&
  365. Em.getWithDefault(Em.getWithDefault(data.items[0], 'configurations', {}).findProperty('type', 'kerberos-env') || {}, 'properties.kdc_type', 'none') || 'none';
  366. this.set('kdc_type', kdcType);
  367. if (Em.typeOf(params.additionalCallback) === 'function') {
  368. params.additionalCallback();
  369. }
  370. },
  371. isManualKerberos: function () {
  372. return this.get('kdc_type') === 'none';
  373. }.property('kdc_type'),
  374. checkState: function(data, opt, params) {
  375. var res = Em.get(data, 'Services.attributes.kdc_validation_result');
  376. var message = Em.get(data, 'Services.attributes.kdc_validation_failure_details');
  377. if (res.toUpperCase() === "OK") {
  378. params.callback();
  379. } else {
  380. App.showInvalidKDCPopup(opt, App.format.kdcErrorMsg(message, false));
  381. }
  382. }
  383. });