kerberos.js 13 KB

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