kerberos.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. getAddSecurityWizardStatus: function () {
  26. return App.db.getSecurityWizardStatus();
  27. },
  28. setAddSecurityWizardStatus: function (status) {
  29. App.db.setSecurityWizardStatus(status);
  30. },
  31. setDisableSecurityStatus: function (status) {
  32. App.db.setDisableSecurityStatus(status);
  33. },
  34. getDisableSecurityStatus: function (status) {
  35. return App.db.getDisableSecurityStatus();
  36. },
  37. notifySecurityOff: false,
  38. notifySecurityAdd: false,
  39. notifySecurityOffPopup: function () {
  40. var self = this;
  41. App.ModalPopup.show({
  42. header: Em.I18n.t('popup.confirmation.commonHeader'),
  43. primary: Em.I18n.t('ok'),
  44. onPrimary: function () {
  45. App.db.setSecurityDeployCommands(undefined);
  46. self.setDisableSecurityStatus("RUNNING");
  47. App.router.transitionTo('disableSecurity');
  48. this.hide();
  49. },
  50. bodyClass: Ember.View.extend({
  51. templateName: require('templates/main/admin/security/notify_security_off_popup')
  52. })
  53. });
  54. },
  55. /**
  56. * Show confirmation popup and after confirmation send request to regenerate keytabs
  57. * @method regenerateKeytabs
  58. * @return {App.ModalPopup}
  59. */
  60. regenerateKeytabs: function () {
  61. var self = this;
  62. return App.ModalPopup.show({
  63. /**
  64. * True - regenerate keytabs only for missing hosts and components, false - regenerate for all hosts and components
  65. * @type {boolean}
  66. */
  67. regenerateKeytabsOnlyForMissing: false,
  68. header: Em.I18n.t('admin.kerberos.button.regenerateKeytabs'),
  69. bodyClass: Em.View.extend({
  70. templateName: require('templates/main/admin/kerberos/regenerate_keytabs_popup_body')
  71. }),
  72. onPrimary: function () {
  73. this._super();
  74. self.regenerateKeytabsRequest(this.get('regenerateKeytabsOnlyForMissing'));
  75. }
  76. });
  77. },
  78. /**
  79. * Send request to regenerate keytabs
  80. * @param {boolean} missingOnly determines type of regeneration - missing|all
  81. * @returns {$.ajax}
  82. */
  83. regenerateKeytabsRequest: function (missingOnly) {
  84. return App.ajax.send({
  85. name: "admin.kerberos_security.regenerate_keytabs",
  86. sender: this,
  87. data: {
  88. type: missingOnly ? 'missing' : 'all'
  89. },
  90. success: "regenerateKeytabsSuccess"
  91. });
  92. },
  93. /**
  94. * Success callback of <code>regenerateKeytabs</code>
  95. * show background operations popup if appropriate option is set
  96. */
  97. regenerateKeytabsSuccess: function () {
  98. App.router.get('applicationController').dataLoading().done(function (initValue) {
  99. if (initValue) {
  100. App.router.get('backgroundOperationsController').showPopup();
  101. }
  102. });
  103. },
  104. getUpdatedSecurityStatus: function () {
  105. this.getSecurityStatus();
  106. return this.get('securityEnabled');
  107. },
  108. /**
  109. * performs cluster check before kerbefos security
  110. * wizard starts if <code>preKerberizeCheck<code> supports is true
  111. * otherwise runs <code>startKerberosWizard<code>
  112. * @method checkAndStartKerberosWizard
  113. */
  114. checkAndStartKerberosWizard: function() {
  115. if (App.get('supports.preKerberizeCheck')) {
  116. App.ajax.send({
  117. name: "admin.kerberos_security.checks",
  118. sender: this,
  119. success: "runSecurityCheckSuccess"
  120. });
  121. } else {
  122. this.startKerberosWizard();
  123. }
  124. },
  125. /**
  126. * success callback of <code>checkAndStartKerberosWizard()</code>
  127. * if there are some fails - it shows popup else open security wizard
  128. * @param data {object}
  129. * @param opt {object}
  130. * @param params {object}
  131. * @returns {App.ModalPopup|undefined}
  132. */
  133. runSecurityCheckSuccess: function (data, opt, params) {
  134. //TODO correct check
  135. if (data.items.someProperty('UpgradeChecks.status', "FAIL")) {
  136. var header = Em.I18n.t('popup.clusterCheck.Security.header').format(params.label);
  137. var title = Em.I18n.t('popup.clusterCheck.Security.title');
  138. var alert = Em.I18n.t('popup.clusterCheck.Security.alert');
  139. App.showClusterCheckPopup(data, header, title, alert);
  140. } else {
  141. this.startKerberosWizard();
  142. }
  143. },
  144. startKerberosWizard: function () {
  145. this.setAddSecurityWizardStatus('RUNNING');
  146. App.router.transitionTo('adminKerberos.adminAddKerberos');
  147. },
  148. /**
  149. * Loads the security status from server (security_enabled property in cluster-env configuration)
  150. */
  151. loadSecurityStatusFromServer: function () {
  152. if (App.get('testMode')) {
  153. this.set('securityEnabled', !App.get('testEnableSecurity'));
  154. this.set('dataIsLoaded', true);
  155. } else {
  156. //get Security Status From Server
  157. return this.getSecurityStatus();
  158. }
  159. },
  160. /**
  161. * Load security status from server.
  162. * @returns {$.Deferred}
  163. */
  164. getSecurityStatus: function () {
  165. if (App.get('testMode')) {
  166. this.set('securityEnabled', !App.get('testEnableSecurity'));
  167. this.set('dataIsLoaded', true);
  168. } else {
  169. //get Security Status From Server
  170. return App.ajax.send({
  171. name: 'admin.security_status',
  172. sender: this,
  173. success: 'getSecurityStatusSuccessCallback',
  174. error: 'errorCallback'
  175. });
  176. }
  177. },
  178. getSecurityStatusSuccessCallback: function(data) {
  179. this.set('dataIsLoaded', true);
  180. var securityType = data.Clusters.security_type;
  181. this.set('securityEnabled', securityType === 'KERBEROS');
  182. },
  183. errorCallback: function (jqXHR) {
  184. this.set('dataIsLoaded', true);
  185. // Show the error popup if the API call received a response from the server.
  186. // jqXHR.status will be empty when browser cancels the request. Refer to AMBARI-5921 for more info
  187. if (!!jqXHR.status) {
  188. this.showSecurityErrorPopup();
  189. }
  190. },
  191. showSecurityErrorPopup: function () {
  192. App.ModalPopup.show({
  193. header: Em.I18n.t('common.error'),
  194. secondary: false,
  195. bodyClass: Ember.View.extend({
  196. template: Ember.Handlebars.compile('<p>{{t admin.security.status.error}}</p>')
  197. })
  198. });
  199. },
  200. /**
  201. * Override <code>App.KerberosWizardStep4Controller</code>
  202. *
  203. * @param {App.ServiceConfigProperty[]} properties
  204. */
  205. setStepConfigs: function (properties) {
  206. this.get('stepConfigs').clear();
  207. this._super(properties);
  208. },
  209. /**
  210. * Override <code>App.KerberosWizardStep4Controller</code>
  211. *
  212. * @param {App.ServiceConfigProperty[]} configs
  213. * @returns {App.ServiceConfigProperty[]}
  214. */
  215. prepareConfigProperties: function(configs) {
  216. var configProperties = configs.slice(0);
  217. var siteProperties = App.config.get('preDefinedSiteProperties');
  218. var installedServiceNames = ['Cluster'].concat(App.Service.find().mapProperty('serviceName'));
  219. configProperties = configProperties.filter(function(item) {
  220. return installedServiceNames.contains(item.get('serviceName'));
  221. });
  222. configProperties.setEach('isSecureConfig', false);
  223. configProperties.forEach(function(property, item, allConfigs) {
  224. if (property.get('observesValueFrom')) {
  225. var observedValue = allConfigs.findProperty('name', property.get('observesValueFrom')).get('value');
  226. property.set('value', observedValue);
  227. property.set('defaultValue', observedValue);
  228. }
  229. if (property.get('serviceName') == 'Cluster') {
  230. property.set('category', 'Global');
  231. } else {
  232. property.set('category', property.get('serviceName'));
  233. }
  234. // All user identity should be grouped under "Ambari Principals" category
  235. if (property.get('identityType') == 'user') property.set('category', 'Ambari Principals');
  236. var siteProperty = siteProperties.findProperty('name', property.get('name'));
  237. if (siteProperty) {
  238. if (siteProperty.category === property.get('category')) {
  239. property.set('displayName',siteProperty.displayName);
  240. if (siteProperty.index) {
  241. property.set('index', siteProperty.index);
  242. }
  243. }
  244. }
  245. });
  246. configProperties.setEach('isEditable', false);
  247. return configProperties;
  248. }
  249. });