security.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. App.MainAdminSecurityController = Em.Controller.extend({
  20. name: 'mainAdminSecurityController',
  21. isSubmitDisabled: false,
  22. securityEnabled: false,
  23. dataIsLoaded: false,
  24. serviceUsers: [],
  25. tag: null,
  26. getAddSecurityWizardStatus: function () {
  27. return App.db.getSecurityWizardStatus();
  28. },
  29. setAddSecurityWizardStatus: function (status) {
  30. App.db.setSecurityWizardStatus(status);
  31. },
  32. setDisableSecurityStatus: function (status) {
  33. App.db.setDisableSecurityStatus(status);
  34. },
  35. getDisableSecurityStatus: function (status) {
  36. return App.db.getDisableSecurityStatus();
  37. },
  38. notifySecurityOff: false,
  39. notifySecurityAdd: false,
  40. notifySecurityOffPopup: function () {
  41. var self = this;
  42. if (!this.get('isSubmitDisabled')) {
  43. App.ModalPopup.show({
  44. header: Em.I18n.t('popup.confirmation.commonHeader'),
  45. primary: Em.I18n.t('ok'),
  46. onPrimary: function () {
  47. App.db.setSecurityDeployStages(undefined);
  48. self.setDisableSecurityStatus("RUNNING");
  49. App.router.transitionTo('disableSecurity');
  50. },
  51. bodyClass: Ember.View.extend({
  52. isMapReduceInstalled: App.Service.find().mapProperty('serviceName').contains('MAPREDUCE'),
  53. template: Ember.Handlebars.compile([
  54. '<div class="alert">',
  55. '{{t admin.security.disable.popup.body}}',
  56. '{{#if view.isMapReduceInstalled}}',
  57. '<br>',
  58. '{{t admin.security.disable.popup.body.warning}}',
  59. '{{/if}}',
  60. '</div>'
  61. ].join('\n'))
  62. })
  63. })
  64. }
  65. },
  66. getUpdatedSecurityStatus: function () {
  67. this.setSecurityStatus();
  68. return this.get('securityEnabled');
  69. },
  70. setSecurityStatus: function () {
  71. if (App.testMode) {
  72. this.set('securityEnabled', !App.testEnableSecurity);
  73. this.set('dataIsLoaded', true);
  74. } else {
  75. //get Security Status From Server
  76. App.ajax.send({
  77. name: 'admin.security_status',
  78. sender: this,
  79. success: 'getSecurityStatusFromServerSuccessCallback',
  80. error: 'errorCallback'
  81. });
  82. }
  83. },
  84. errorCallback: function () {
  85. this.set('dataIsLoaded', true);
  86. this.showSecurityErrorPopup();
  87. },
  88. getSecurityStatusFromServerSuccessCallback: function (data) {
  89. var configs = data.Clusters.desired_configs;
  90. if ('global' in configs) {
  91. this.set('tag', configs['global'].tag);
  92. this.getServiceConfigsFromServer();
  93. }
  94. else {
  95. this.showSecurityErrorPopup();
  96. }
  97. },
  98. getServiceConfigsFromServer: function () {
  99. App.ajax.send({
  100. name: 'admin.service_config',
  101. sender: this,
  102. data: {
  103. siteName: 'global',
  104. tagName: this.get('tag')
  105. },
  106. success: 'getServiceConfigsFromServerSuccessCallback',
  107. error: 'errorCallback'
  108. });
  109. },
  110. getServiceConfigsFromServerSuccessCallback: function (data) {
  111. console.log("TRACE: In success function for the GET getServiceConfigsFromServer call");
  112. var configs = data.items.findProperty('tag', this.get('tag')).properties;
  113. if (configs && (configs['security_enabled'] === 'true' || configs['security_enabled'] === true)) {
  114. this.set('securityEnabled', true);
  115. }
  116. else {
  117. this.set('securityEnabled', false);
  118. }
  119. this.loadUsers(configs);
  120. this.set('dataIsLoaded', true);
  121. },
  122. loadUsers: function (configs) {
  123. var serviceUsers = this.get('serviceUsers');
  124. serviceUsers.pushObject({
  125. id: 'puppet var',
  126. name: 'hdfs_user',
  127. value: configs['hdfs_user'] ? configs['hdfs_user'] : 'hdfs'
  128. });
  129. serviceUsers.pushObject({
  130. id: 'puppet var',
  131. name: 'mapred_user',
  132. value: configs['mapred_user'] ? configs['mapred_user'] : 'mapred'
  133. });
  134. serviceUsers.pushObject({
  135. id: 'puppet var',
  136. name: 'hbase_user',
  137. value: configs['hbase_user'] ? configs['hbase_user'] : 'hbase'
  138. });
  139. serviceUsers.pushObject({
  140. id: 'puppet var',
  141. name: 'hive_user',
  142. value: configs['hive_user'] ? configs['hive_user'] : 'hive'
  143. });
  144. serviceUsers.pushObject({
  145. id: 'puppet var',
  146. name: 'proxyuser_group',
  147. value: configs['proxyuser_group'] ? configs['proxyuser_group'] : 'users'
  148. });
  149. serviceUsers.pushObject({
  150. id: 'puppet var',
  151. name: 'smokeuser',
  152. value: configs['smokeuser'] ? configs['smokeuser'] : 'ambari-qa'
  153. });
  154. serviceUsers.pushObject({
  155. id: 'puppet var',
  156. name: 'zk_user',
  157. value: configs['zk_user'] ? configs['zk_user'] : 'zookeeper'
  158. });
  159. serviceUsers.pushObject({
  160. id: 'puppet var',
  161. name: 'oozie_user',
  162. value: configs['oozie_user'] ? configs['oozie_user'] : 'oozie'
  163. });
  164. serviceUsers.pushObject({
  165. id: 'puppet var',
  166. name: 'nagios_user',
  167. value: configs['nagios_user'] ? configs['nagios_user'] : 'nagios'
  168. });
  169. serviceUsers.pushObject({
  170. id: 'puppet var',
  171. name: 'user_group',
  172. value: configs['user_group'] ? configs['user_group'] : 'hadoop'
  173. });
  174. },
  175. showSecurityErrorPopup: function () {
  176. App.ModalPopup.show({
  177. header: Em.I18n.t('common.error'),
  178. secondary: false,
  179. onPrimary: function () {
  180. this.hide();
  181. },
  182. bodyClass: Ember.View.extend({
  183. template: Ember.Handlebars.compile('<p>{{t admin.security.status.error}}</p>')
  184. })
  185. });
  186. }
  187. });