knox.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 : 'KNOX',
  21. getDependentConfigChanges : function(changedConfig, selectedServices, allConfigs, securityEnabled) {
  22. var affectedProperties = [];
  23. var newValue = changedConfig.get("value");
  24. var rangerPluginEnablePropertyName = "ranger-knox-plugin-enabled";
  25. var affectedPropertyName = changedConfig.get("name");
  26. if (affectedPropertyName == rangerPluginEnablePropertyName) {
  27. var topologyXmlContent = this.getConfig(allConfigs, 'content', 'topology.xml', 'KNOX');
  28. if (topologyXmlContent != null) {
  29. var topologyXmlContentString = topologyXmlContent.get('value');
  30. var newTopologyXmlContentString = null;
  31. var authEnabled = newValue == "Yes";
  32. var authXml = /<provider>[\s]*<role>[\s]*authorization[\s]*<\/role>[\s\S]*?<\/provider>/.exec(topologyXmlContentString);
  33. if (authXml != null && authXml.length > 0) {
  34. var nameArray = /<name>\s*(.*?)\s*<\/name>/.exec(authXml[0]);
  35. if (nameArray != null && nameArray.length > 1) {
  36. if (authEnabled && 'AclsAuthz' == nameArray[1]) {
  37. var newName = nameArray[0].replace('AclsAuthz', 'XASecurePDPKnox');
  38. var newAuthXml = authXml[0].replace(nameArray[0], newName);
  39. newTopologyXmlContentString = topologyXmlContentString.replace(authXml[0], newAuthXml);
  40. } else if (!authEnabled && 'XASecurePDPKnox' == nameArray[1]) {
  41. var newName = nameArray[0].replace('XASecurePDPKnox', 'AclsAuthz');
  42. var newAuthXml = authXml[0].replace(nameArray[0], newName);
  43. newTopologyXmlContentString = topologyXmlContentString.replace(authXml[0], newAuthXml);
  44. }
  45. }
  46. }
  47. if (newTopologyXmlContentString != null) {
  48. affectedProperties.push({
  49. serviceName : "KNOX",
  50. sourceServiceName : "KNOX",
  51. propertyName : 'content',
  52. propertyDisplayName : 'content',
  53. newValue : newTopologyXmlContentString,
  54. curValue : topologyXmlContent.get('value'),
  55. changedPropertyName : rangerPluginEnablePropertyName,
  56. removed : false,
  57. filename : 'topology.xml'
  58. });
  59. }
  60. }
  61. }
  62. return affectedProperties;
  63. }
  64. });