security.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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.showConfirmationPopup(function () {
  44. App.db.setSecurityDeployStages(undefined);
  45. self.setDisableSecurityStatus("RUNNING");
  46. App.router.transitionTo('disableSecurity');
  47. }, Em.I18n.t('admin.security.disable.popup.body'));
  48. }
  49. },
  50. getUpdatedSecurityStatus: function() {
  51. this.setSecurityStatus();
  52. return this.get('securityEnabled');
  53. },
  54. setSecurityStatus: function () {
  55. if (App.testMode) {
  56. this.set('securityEnabled', !App.testEnableSecurity);
  57. this.set('dataIsLoaded', true);
  58. } else {
  59. //get Security Status From Server
  60. App.ajax.send({
  61. name: 'admin.security_status',
  62. sender: this,
  63. success: 'getSecurityStatusFromServerSuccessCallback',
  64. error: 'errorCallback'
  65. });
  66. }
  67. },
  68. errorCallback: function() {
  69. this.set('dataIsLoaded', true);
  70. this.showSecurityErrorPopup();
  71. },
  72. getSecurityStatusFromServerSuccessCallback: function (data) {
  73. var configs = data.Clusters.desired_configs;
  74. if ('global' in configs) {
  75. this.set('tag', configs['global'].tag);
  76. this.getServiceConfigsFromServer();
  77. }
  78. else {
  79. this.showSecurityErrorPopup();
  80. }
  81. },
  82. getServiceConfigsFromServer: function () {
  83. App.ajax.send({
  84. name: 'admin.service_config',
  85. sender: this,
  86. data: {
  87. siteName: 'global',
  88. tagName: this.get('tag')
  89. },
  90. success: 'getServiceConfigsFromServerSuccessCallback',
  91. error: 'errorCallback'
  92. });
  93. },
  94. getServiceConfigsFromServerSuccessCallback: function (data) {
  95. console.log("TRACE: In success function for the GET getServiceConfigsFromServer call");
  96. var configs = data.items.findProperty('tag', this.get('tag')).properties;
  97. if (configs && (configs['security_enabled'] === 'true' ||configs['security_enabled'] === true)) {
  98. this.set('securityEnabled', true);
  99. }
  100. else {
  101. this.set('securityEnabled', false);
  102. }
  103. this.loadUsers(configs);
  104. this.set('dataIsLoaded', true);
  105. },
  106. loadUsers: function (configs) {
  107. var serviceUsers = this.get('serviceUsers');
  108. serviceUsers.pushObject({
  109. id: 'puppet var',
  110. name: 'hdfs_user',
  111. value: configs['hdfs_user'] ? configs['hdfs_user'] : 'hdfs'
  112. });
  113. serviceUsers.pushObject({
  114. id: 'puppet var',
  115. name: 'mapred_user',
  116. value: configs['mapred_user'] ? configs['mapred_user'] : 'mapred'
  117. });
  118. serviceUsers.pushObject({
  119. id: 'puppet var',
  120. name: 'hbase_user',
  121. value: configs['hbase_user'] ? configs['hbase_user'] : 'hbase'
  122. });
  123. serviceUsers.pushObject({
  124. id: 'puppet var',
  125. name: 'hive_user',
  126. value: configs['hive_user'] ? configs['hive_user'] : 'hive'
  127. });
  128. serviceUsers.pushObject({
  129. id: 'puppet var',
  130. name: 'proxyuser_group',
  131. value: configs['proxyuser_group'] ? configs['proxyuser_group'] : 'users'
  132. });
  133. serviceUsers.pushObject({
  134. id: 'puppet var',
  135. name: 'smokeuser',
  136. value: configs['smokeuser'] ? configs['smokeuser'] : 'ambari-qa'
  137. });
  138. serviceUsers.pushObject({
  139. id: 'puppet var',
  140. name: 'zk_user',
  141. value: configs['zk_user'] ? configs['zk_user'] : 'zookeeper'
  142. });
  143. serviceUsers.pushObject({
  144. id: 'puppet var',
  145. name: 'oozie_user',
  146. value: configs['oozie_user'] ? configs['oozie_user'] : 'oozie'
  147. });
  148. serviceUsers.pushObject({
  149. id: 'puppet var',
  150. name: 'nagios_user',
  151. value: configs['nagios_user'] ? configs['nagios_user'] : 'nagios'
  152. });
  153. serviceUsers.pushObject({
  154. id: 'puppet var',
  155. name: 'user_group',
  156. value: configs['user_group'] ? configs['user_group'] : 'hadoop'
  157. });
  158. },
  159. showSecurityErrorPopup: function () {
  160. App.ModalPopup.show({
  161. header: Em.I18n.t('common.error'),
  162. secondary: false,
  163. onPrimary: function () {
  164. this.hide();
  165. },
  166. bodyClass: Ember.View.extend({
  167. template: Ember.Handlebars.compile('<p>{{t admin.security.status.error}}</p>')
  168. })
  169. });
  170. }
  171. });