hbase.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. require('utils/configs/modification_handlers/modification_handler');
  19. module.exports = App.ServiceConfigModificationHandler.create({
  20. serviceId : 'HBASE',
  21. updateConfigClasses : function(configClasses, authEnabled, affectedProperties, addOldValue) {
  22. if (configClasses != null) {
  23. var xaAuthCoProcessorClass = App.get('isHadoop23Stack') ? "org.apache.ranger.authorization.hbase.RangerAuthorizationCoprocessor"
  24. : "com.xasecure.authorization.hbase.XaSecureAuthorizationCoprocessor";
  25. var nonXAClass = 'org.apache.hadoop.hbase.security.access.AccessController';
  26. var currentClassesList = configClasses.get('value').trim().length > 0 ? configClasses.get('value').trim().split(',') : [];
  27. var newClassesList = null, xaClassIndex, nonXaClassIndex;
  28. if (authEnabled) {
  29. var nonXaClassIndex = currentClassesList.indexOf(nonXAClass);
  30. if (nonXaClassIndex > -1) {
  31. currentClassesList.splice(nonXaClassIndex, 1);
  32. newClassesList = currentClassesList;
  33. }
  34. var xaClassIndex = currentClassesList.indexOf(xaAuthCoProcessorClass);
  35. if (xaClassIndex < 0) {
  36. currentClassesList.push(xaAuthCoProcessorClass);
  37. newClassesList = currentClassesList;
  38. }
  39. } else {
  40. var xaClassIndex = currentClassesList.indexOf(xaAuthCoProcessorClass);
  41. if (xaClassIndex > -1) {
  42. currentClassesList.splice(xaClassIndex, 1);
  43. newClassesList = currentClassesList;
  44. }
  45. if (addOldValue) {
  46. var nonXaClassIndex = currentClassesList.indexOf(nonXAClass);
  47. if (nonXaClassIndex < 0) {
  48. currentClassesList.push(nonXAClass);
  49. newClassesList = currentClassesList;
  50. }
  51. }
  52. }
  53. if (newClassesList != null) {
  54. affectedProperties.push({
  55. serviceName : "HBASE",
  56. sourceServiceName : "HBASE",
  57. propertyName : configClasses.get('name'),
  58. propertyDisplayName : configClasses.get('name'),
  59. newValue : newClassesList.join(','),
  60. curValue : configClasses.get('value'),
  61. changedPropertyName : 'ranger-hbase-plugin-enabled',
  62. removed : false,
  63. filename : 'hbase-site.xml'
  64. });
  65. }
  66. }
  67. },
  68. getDependentConfigChanges : function(changedConfig, selectedServices, allConfigs, securityEnabled) {
  69. var affectedProperties = [];
  70. var newValue = changedConfig.get("value");
  71. var hbaseAuthEnabledPropertyName = "ranger-hbase-plugin-enabled";
  72. var affectedPropertyName = changedConfig.get("name");
  73. if (affectedPropertyName == hbaseAuthEnabledPropertyName) {
  74. var configAuthEnabled = this.getConfig(allConfigs, 'hbase.security.authorization', 'hbase-site.xml', 'HBASE');
  75. var configMasterClasses = this.getConfig(allConfigs, 'hbase.coprocessor.master.classes', 'hbase-site.xml', 'HBASE');
  76. var configRegionClasses = this.getConfig(allConfigs, 'hbase.coprocessor.region.classes', 'hbase-site.xml', 'HBASE');
  77. var authEnabled = newValue == "Yes";
  78. var newAuthEnabledValue = authEnabled ? "true" : "false";
  79. var newRpcProtectionValue = authEnabled ? "privacy" : "authentication";
  80. // Add HBase-Ranger configs
  81. this.updateConfigClasses(configMasterClasses, authEnabled, affectedProperties, configAuthEnabled.get('value') == 'true');
  82. this.updateConfigClasses(configRegionClasses, authEnabled, affectedProperties, configAuthEnabled.get('value') == 'true');
  83. if (authEnabled && newAuthEnabledValue !== configAuthEnabled.get('value')) {
  84. affectedProperties.push({
  85. serviceName : "HBASE",
  86. sourceServiceName : "HBASE",
  87. propertyName : 'hbase.security.authorization',
  88. propertyDisplayName : 'hbase.security.authorization',
  89. newValue : newAuthEnabledValue,
  90. curValue : configAuthEnabled.get('value'),
  91. changedPropertyName : hbaseAuthEnabledPropertyName,
  92. removed : false,
  93. filename : 'hbase-site.xml'
  94. });
  95. }
  96. }
  97. return affectedProperties;
  98. }
  99. });