kerberos.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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. }).always(function() {
  234. // check for kerberos descriptor artifact
  235. if (self.get('securityEnabled')) {
  236. self.loadClusterDescriptorConfigs().then(function() {
  237. dfd.resolve();
  238. }, function() {
  239. // if kerberos descriptor doesn't exist in cluster artifacts we have to kerberize cluster.
  240. // Show `Enable kerberos` button and set unsecure status.
  241. self.set('securityEnabled', false);
  242. dfd.resolve();
  243. });
  244. } else {
  245. dfd.resolve();
  246. }
  247. });
  248. }
  249. return dfd.promise();
  250. },
  251. getSecurityStatusSuccessCallback: function(data) {
  252. this.set('dataIsLoaded', true);
  253. var securityType = data.Clusters.security_type;
  254. this.set('securityEnabled', securityType === 'KERBEROS');
  255. },
  256. errorCallback: function (jqXHR) {
  257. this.set('dataIsLoaded', true);
  258. // Show the error popup if the API call received a response from the server.
  259. // jqXHR.status will be empty when browser cancels the request. Refer to AMBARI-5921 for more info
  260. if (!!jqXHR.status) {
  261. this.showSecurityErrorPopup();
  262. }
  263. },
  264. showSecurityErrorPopup: function () {
  265. App.ModalPopup.show({
  266. header: Em.I18n.t('common.error'),
  267. secondary: false,
  268. bodyClass: Ember.View.extend({
  269. template: Ember.Handlebars.compile('<p>{{t admin.security.status.error}}</p>')
  270. })
  271. });
  272. },
  273. /**
  274. * Override <code>App.KerberosWizardStep4Controller</code>
  275. *
  276. * @param {App.ServiceConfigProperty[]} properties
  277. */
  278. setStepConfigs: function (properties) {
  279. this.get('stepConfigs').clear();
  280. this._super(properties);
  281. },
  282. /**
  283. * Override <code>App.KerberosWizardStep4Controller</code>
  284. *
  285. * @param {App.ServiceConfigProperty[]} configs
  286. * @returns {App.ServiceConfigProperty[]}
  287. */
  288. prepareConfigProperties: function(configs) {
  289. var configProperties = configs.slice(0);
  290. var siteProperties = App.config.get('preDefinedSiteProperties');
  291. var installedServiceNames = ['Cluster'].concat(App.Service.find().mapProperty('serviceName'));
  292. configProperties = configProperties.filter(function(item) {
  293. return installedServiceNames.contains(item.get('serviceName'));
  294. });
  295. configProperties.setEach('isSecureConfig', false);
  296. configProperties.forEach(function(property, item, allConfigs) {
  297. if (property.get('observesValueFrom')) {
  298. var observedValue = allConfigs.findProperty('name', property.get('observesValueFrom')).get('value');
  299. property.set('value', observedValue);
  300. property.set('recommendedValue', observedValue);
  301. }
  302. if (property.get('serviceName') == 'Cluster') {
  303. property.set('category', 'Global');
  304. } else {
  305. property.set('category', property.get('serviceName'));
  306. }
  307. // All user identity should be grouped under "Ambari Principals" category
  308. if (property.get('identityType') == 'user') property.set('category', 'Ambari Principals');
  309. var siteProperty = siteProperties.findProperty('name', property.get('name'));
  310. if (siteProperty) {
  311. if (siteProperty.category === property.get('category')) {
  312. property.set('displayName',siteProperty.displayName);
  313. if (siteProperty.index) {
  314. property.set('index', siteProperty.index);
  315. }
  316. }
  317. if (siteProperty.displayType) {
  318. property.set('displayType', siteProperty.displayType);
  319. }
  320. }
  321. });
  322. configProperties.setEach('isEditable', false);
  323. return configProperties;
  324. },
  325. getKDCSessionState: function(callback) {
  326. if (this.get('securityEnabled')) {
  327. App.ajax.send({
  328. name: 'kerberos.session.state',
  329. sender: this,
  330. data: {
  331. callback: callback
  332. },
  333. success: 'checkState'
  334. })
  335. } else {
  336. callback();
  337. }
  338. },
  339. getSecurityType: function (callback) {
  340. if (this.get('securityEnabled')) {
  341. App.ajax.send({
  342. name: 'admin.security.cluster_configs.kerberos',
  343. sender: this,
  344. data: {
  345. clusterName: App.get('clusterName'),
  346. additionalCallback: callback
  347. },
  348. success: 'getSecurityTypeSuccess'
  349. })
  350. } else if (Em.typeOf(callback)=== 'function') {
  351. callback();
  352. }
  353. },
  354. getSecurityTypeSuccess: function (data, opt, params) {
  355. this.set('kdc_type', data.items && Em.get(data.items[0], 'properties.kdc_type') ? Em.get(data.items[0], 'properties.kdc_type') : 'none' );
  356. if (Em.typeOf(params.additionalCallback) === 'function') {
  357. params.additionalCallback();
  358. }
  359. },
  360. isManualKerberos: function () {
  361. return this.get('kdc_type') === 'none';
  362. }.property('kdc_type'),
  363. checkState: function(data, opt, params) {
  364. var res = Em.get(data, 'Services.attributes.kdc_validation_result');
  365. var message = Em.get(data, 'Services.attributes.kdc_validation_failure_details');
  366. if (res.toUpperCase() === "OK") {
  367. params.callback();
  368. } else {
  369. App.showInvalidKDCPopup(opt, App.format.kdcErrorMsg(message, false));
  370. }
  371. }
  372. });