You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by rm...@apache.org on 2015/10/22 02:02:54 UTC
[1/6] incubator-ranger git commit: RANGER-586: Ranger plugins should
not add dependent libraries to component's CLASSPATH
Repository: incubator-ranger
Updated Branches:
refs/heads/ranger-rmani [created] ebe83454b
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-storm-plugin-shim/src/main/java/org/apache/ranger/authorization/storm/authorizer/RangerStormAuthorizer.java
----------------------------------------------------------------------
diff --git a/ranger-storm-plugin-shim/src/main/java/org/apache/ranger/authorization/storm/authorizer/RangerStormAuthorizer.java b/ranger-storm-plugin-shim/src/main/java/org/apache/ranger/authorization/storm/authorizer/RangerStormAuthorizer.java
new file mode 100644
index 0000000..bce7d4a
--- /dev/null
+++ b/ranger-storm-plugin-shim/src/main/java/org/apache/ranger/authorization/storm/authorizer/RangerStormAuthorizer.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.authorization.storm.authorizer;
+
+
+
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.ranger.plugin.classloader.RangerPluginClassLoader;
+
+import backtype.storm.security.auth.IAuthorizer;
+import backtype.storm.security.auth.ReqContext;
+
+public class RangerStormAuthorizer implements IAuthorizer {
+ private static final Logger LOG = LoggerFactory.getLogger(RangerStormAuthorizer.class);
+
+ private static final String RANGER_PLUGIN_TYPE = "storm";
+ private static final String[] RANGER_PLUGIN_LIB_DIR = new String[] {"lib/ranger-storm-plugin"};
+ private static final String RANGER_STORM_AUTHORIZER_IMPL_CLASSNAME = "org.apache.ranger.authorization.storm.authorizer.RangerStormAuthorizerImpl";
+
+ private IAuthorizer rangerStormAuthorizerImpl = null;
+ private static RangerPluginClassLoader rangerPluginClassLoader = null;
+
+ public RangerStormAuthorizer() {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerStormAuthorizer.RangerStormAuthorizer()");
+ }
+
+ this.init();
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerStormAuthorizer.RangerStormAuthorizer()");
+ }
+ }
+
+ public void init(){
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerStormAuthorizer.init()");
+ }
+
+ try {
+
+ rangerPluginClassLoader = RangerPluginClassLoader.getInstance(RANGER_PLUGIN_TYPE, this.getClass());
+
+ @SuppressWarnings("unchecked")
+ Class<IAuthorizer> cls = (Class<IAuthorizer>) Class.forName(RANGER_STORM_AUTHORIZER_IMPL_CLASSNAME, true, rangerPluginClassLoader);
+
+ activatePluginClassLoader();
+
+ rangerStormAuthorizerImpl = cls.newInstance();
+ } catch (Exception e) {
+ // check what need to be done
+ LOG.error("Error Enabling RangerHdfsPluing", e);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerStormAuthorizer.init()");
+ }
+ }
+
+ @Override
+ public void prepare(Map storm_conf) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerStormAuthorizer.prepare()");
+ }
+
+ try {
+ activatePluginClassLoader();
+
+ rangerStormAuthorizerImpl.prepare(storm_conf);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerStormAuthorizer.prepare()");
+ }
+
+ }
+
+ @Override
+ public boolean permit(ReqContext context, String operation, Map topology_conf) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerStormAuthorizer.permit()");
+ }
+
+ boolean ret = false;
+
+ try {
+ activatePluginClassLoader();
+
+ ret = rangerStormAuthorizerImpl.permit(context, operation, topology_conf);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerStormAuthorizer.permit()");
+ }
+
+ return ret;
+ }
+
+
+ private void activatePluginClassLoader() {
+ if(rangerPluginClassLoader != null) {
+ rangerPluginClassLoader.activate();
+ }
+ }
+
+ private void deactivatePluginClassLoader() {
+ if(rangerPluginClassLoader != null) {
+ rangerPluginClassLoader.deactivate();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-yarn-plugin-shim/pom.xml
----------------------------------------------------------------------
diff --git a/ranger-yarn-plugin-shim/pom.xml b/ranger-yarn-plugin-shim/pom.xml
new file mode 100644
index 0000000..d461ca5
--- /dev/null
+++ b/ranger-yarn-plugin-shim/pom.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>security_plugins.ranger-yarn-plugin-shim</groupId>
+ <artifactId>ranger-yarn-plugin-shim</artifactId>
+ <name>YARN Security Plugin Shim</name>
+ <description>YARN Security Plugin Shim</description>
+ <packaging>jar</packaging>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <parent>
+ <groupId>org.apache.ranger</groupId>
+ <artifactId>ranger</artifactId>
+ <version>0.5.0</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <dependencies>
+ <dependency>
+ <groupId>security_plugins.ranger-plugins-common</groupId>
+ <artifactId>ranger-plugins-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugins-audit</groupId>
+ <artifactId>ranger-plugins-audit</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ranger</groupId>
+ <artifactId>credentialbuilder</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-yarn-common</artifactId>
+ <version>${hadoop.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-yarn-api</artifactId>
+ <version>${hadoop.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugin-classloader</groupId>
+ <artifactId>ranger-plugin-classloader</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-yarn-plugin-shim/src/main/java/org/apache/ranger/authorization/yarn/authorizer/RangerYarnAuthorizer.java
----------------------------------------------------------------------
diff --git a/ranger-yarn-plugin-shim/src/main/java/org/apache/ranger/authorization/yarn/authorizer/RangerYarnAuthorizer.java b/ranger-yarn-plugin-shim/src/main/java/org/apache/ranger/authorization/yarn/authorizer/RangerYarnAuthorizer.java
new file mode 100644
index 0000000..d9612b4
--- /dev/null
+++ b/ranger-yarn-plugin-shim/src/main/java/org/apache/ranger/authorization/yarn/authorizer/RangerYarnAuthorizer.java
@@ -0,0 +1,205 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.authorization.yarn.authorizer;
+
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.security.authorize.AccessControlList;
+import org.apache.hadoop.yarn.security.AccessType;
+import org.apache.hadoop.yarn.security.PrivilegedEntity;
+import org.apache.hadoop.yarn.security.YarnAuthorizationProvider;
+import org.apache.ranger.plugin.classloader.RangerPluginClassLoader;
+
+
+
+public class RangerYarnAuthorizer extends YarnAuthorizationProvider {
+ private static final Log LOG = LogFactory.getLog(RangerYarnAuthorizer.class);
+
+ private static final String RANGER_PLUGIN_TYPE = "yarn";
+ private static final String[] RANGER_PLUGIN_LIB_DIR = new String[] {"lib/ranger-yarn-plugin"};
+ private static final String RANGER_YARN_AUTHORIZER_IMPL_CLASSNAME = "org.apache.ranger.authorization.yarn.authorizer.RangerYarnAuthorizerImpl";
+
+ private YarnAuthorizationProvider yarnAuthorizationProviderImpl = null;
+ private static RangerPluginClassLoader rangerPluginClassLoader = null;
+
+ public RangerYarnAuthorizer() {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerYarnAuthorizer.RangerYarnAuthorizer()");
+ }
+
+ this.init();
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerYarnAuthorizer.RangerYarnAuthorizer()");
+ }
+ }
+
+ public void init(){
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerYarnAuthorizer.init()");
+ }
+
+ try {
+
+ rangerPluginClassLoader = RangerPluginClassLoader.getInstance(RANGER_PLUGIN_TYPE, this.getClass());
+
+ @SuppressWarnings("unchecked")
+ Class<YarnAuthorizationProvider> cls = (Class<YarnAuthorizationProvider>) Class.forName(RANGER_YARN_AUTHORIZER_IMPL_CLASSNAME, true, rangerPluginClassLoader);
+
+ activatePluginClassLoader();
+
+ yarnAuthorizationProviderImpl = cls.newInstance();
+ } catch (Exception e) {
+ // check what need to be done
+ LOG.error("Error Enabling RangerYarnPluing", e);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerYarnAuthorizer.init()");
+ }
+ }
+
+ @Override
+ public void init(Configuration conf) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerYarnAuthorizer.init()");
+ }
+
+ try {
+ activatePluginClassLoader();
+
+ yarnAuthorizationProviderImpl.init(conf);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerYarnAuthorizer.start()");
+ }
+ }
+
+ @Override
+ public boolean checkPermission(AccessType accessType, PrivilegedEntity target, UserGroupInformation user) {
+
+ boolean ret = false;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerYarnAuthorizer.checkPermission()");
+ }
+
+ try {
+ activatePluginClassLoader();
+
+ ret = yarnAuthorizationProviderImpl.checkPermission(accessType, target, user);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerYarnAuthorizer.checkPermission()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void setPermission(PrivilegedEntity target, Map<AccessType, AccessControlList> acls, UserGroupInformation ugi) {
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerYarnAuthorizer.setPermission()");
+ }
+
+ try {
+ activatePluginClassLoader();
+
+ yarnAuthorizationProviderImpl.setPermission(target, acls, ugi);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerYarnAuthorizer.setPermission()");
+ }
+ }
+
+ @Override
+ public void setAdmins(AccessControlList acls, UserGroupInformation ugi) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerYarnAuthorizer.setAdmins()");
+ }
+
+ try {
+ activatePluginClassLoader();
+
+ yarnAuthorizationProviderImpl.setAdmins(acls, ugi);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerYarnAuthorizer.setAdmins()");
+ }
+ }
+
+ @Override
+ public boolean isAdmin(UserGroupInformation ugi) {
+
+ boolean ret = false;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerYarnAuthorizer.setAdmins()");
+ }
+
+ try {
+ activatePluginClassLoader();
+
+ ret = yarnAuthorizationProviderImpl.isAdmin(ugi);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerYarnAuthorizer.setAdmins()");
+ }
+
+ return ret;
+ }
+
+ private void activatePluginClassLoader() {
+ if(rangerPluginClassLoader != null) {
+ rangerPluginClassLoader.activate();
+ }
+ }
+
+ private void deactivatePluginClassLoader() {
+ if(rangerPluginClassLoader != null) {
+ rangerPluginClassLoader.deactivate();
+ }
+ }
+
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/src/main/assembly/hbase-agent.xml
----------------------------------------------------------------------
diff --git a/src/main/assembly/hbase-agent.xml b/src/main/assembly/hbase-agent.xml
index 0f22066..0ffc65c 100644
--- a/src/main/assembly/hbase-agent.xml
+++ b/src/main/assembly/hbase-agent.xml
@@ -28,21 +28,34 @@
<binaries>
<includeDependencies>false</includeDependencies>
<unpack>false</unpack>
+ <directoryMode>755</directoryMode>
+ <fileMode>644</fileMode>
+ <outputDirectory>/lib</outputDirectory>
+ </binaries>
+ <includes>
+ <include>security_plugins.ranger-hbase-plugin-shim:ranger-hbase-plugin-shim</include>
+ <include>security_plugins.ranger-plugin-classloader:ranger-plugin-classloader</include>
+ </includes>
+ </moduleSet>
+ <moduleSet>
+ <binaries>
+ <includeDependencies>false</includeDependencies>
+ <unpack>false</unpack>
<directoryMode>755</directoryMode>
<fileMode>644</fileMode>
<dependencySets>
<dependencySet>
- <outputDirectory>/lib</outputDirectory>
+ <outputDirectory>/lib/ranger-hbase-plugin-impl</outputDirectory>
<includes>
<include>com.google.code.gson:gson*</include>
<include>org.eclipse.persistence:eclipselink</include>
- <include>org.apache.httpcomponents:httpmime:jar:${httpcomponent.httpmime.version}</include>
- <include>org.noggit:noggit:jar:${noggit.version}</include>
+ <include>org.apache.httpcomponents:httpmime:jar:${httpcomponent.httpmime.version}</include>
+ <include>org.noggit:noggit:jar:${noggit.version}</include>
</includes>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
- <outputDirectory>/lib</outputDirectory>
+ <outputDirectory>/lib/ranger-hbase-plugin-impl</outputDirectory>
</binaries>
<includes>
<include>org.apache.ranger:ranger_solrj</include>
@@ -55,7 +68,7 @@
</moduleSet>
<moduleSet>
<binaries>
- <includeDependencies>false</includeDependencies>
+ <includeDependencies>true</includeDependencies>
<dependencySets>
<dependencySet>
<outputDirectory>/install/lib</outputDirectory>
@@ -67,7 +80,7 @@
<include>commons-io:commons-io:jar:${commons.io.version}</include>
<include>commons-lang:commons-lang</include>
<include>commons-logging:commons-logging:jar:${commons.logging.version}</include>
- <include>com.google.guava:guava:jar:${guava.version}</include>
+ <include>com.google.guava:guava:jar:${google.guava.version}</include>
<include>org.hamcrest:hamcrest-all</include>
<include>junit:junit</include>
<include>org.slf4j:slf4j-api:jar:${slf4j-api.version}</include>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/src/main/assembly/hdfs-agent.xml
----------------------------------------------------------------------
diff --git a/src/main/assembly/hdfs-agent.xml b/src/main/assembly/hdfs-agent.xml
index 2c18001..deec461 100644
--- a/src/main/assembly/hdfs-agent.xml
+++ b/src/main/assembly/hdfs-agent.xml
@@ -24,39 +24,24 @@
<baseDirectory>${project.name}-${project.version}-hdfs-plugin</baseDirectory>
<includeBaseDirectory>true</includeBaseDirectory>
<moduleSets>
+
<moduleSet>
<binaries>
<includeDependencies>false</includeDependencies>
<unpack>false</unpack>
<directoryMode>755</directoryMode>
<fileMode>644</fileMode>
- <dependencySets>
- <dependencySet>
- <outputDirectory>/lib</outputDirectory>
- <includes>
- <include>com.google.code.gson:gson*</include>
- <include>org.eclipse.persistence:javax.persistence</include>
- <include>org.eclipse.persistence:eclipselink</include>
- <include>org.apache.httpcomponents:httpmime:jar:${httpcomponent.httpmime.version}</include>
- <include>org.noggit:noggit:jar:${noggit.version}</include>
- </includes>
- <unpack>false</unpack>
- </dependencySet>
- </dependencySets>
- <outputDirectory>/lib</outputDirectory>
+ <outputDirectory>/lib</outputDirectory>
</binaries>
<includes>
- <include>org.apache.ranger:ranger_solrj</include>
- <include>security_plugins.ranger-plugins-audit:ranger-plugins-audit</include>
- <include>security_plugins.ranger-plugins-cred:ranger-plugins-cred</include>
- <include>security_plugins.ranger-plugins-impl:ranger-plugins-impl</include>
- <include>security_plugins.ranger-plugins-common:ranger-plugins-common</include>
- <include>security_plugins.ranger-hdfs-plugin:ranger-hdfs-plugin</include>
- </includes>
+ <include>security_plugins.ranger-hdfs-plugin-shim:ranger-hdfs-plugin-shim</include>
+ <include>security_plugins.ranger-plugin-classloader:ranger-plugin-classloader</include>
+ </includes>
</moduleSet>
+
<moduleSet>
<binaries>
- <includeDependencies>false</includeDependencies>
+ <includeDependencies>true</includeDependencies>
<dependencySets>
<dependencySet>
<outputDirectory>/install/lib</outputDirectory>
@@ -68,9 +53,9 @@
<include>commons-io:commons-io:jar:${commons.io.version}</include>
<include>commons-lang:commons-lang</include>
<include>commons-logging:commons-logging:jar:${commons.logging.version}</include>
- <include>com.google.guava:guava:jar:${guava.version}</include>
+ <include>com.google.guava:guava:jar:${google.guava.version}</include>
<include>org.hamcrest:hamcrest-all</include>
- <include>junit:junit</include>
+ <include>junit:junit:${junit.version}</include>
<include>org.slf4j:slf4j-api:jar:${slf4j-api.version}</include>
<include>org.apache.hadoop:hadoop-common:jar:${hadoop-common.version}</include>
<include>org.apache.hadoop:hadoop-auth:jar:${hadoop-common.version}</include>
@@ -85,6 +70,38 @@
<include>org.apache.ranger:credentialbuilder</include>
</includes>
</moduleSet>
+
+ <moduleSet>
+ <binaries>
+ <includeDependencies>true</includeDependencies>
+ <unpack>false</unpack>
+ <directoryMode>755</directoryMode>
+ <fileMode>644</fileMode>
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>/lib/ranger-hdfs-plugin-impl</outputDirectory>
+ <includes>
+ <include>com.google.code.gson:gson*</include>
+ <include>org.eclipse.persistence:javax.persistence</include>
+ <include>org.eclipse.persistence:eclipselink</include>
+ <include>org.apache.httpcomponents:httpmime:jar:${httpcomponent.httpmime.version}</include>
+ <include>org.noggit:noggit:jar:${noggit.version}</include>
+ </includes>
+ <unpack>false</unpack>
+ </dependencySet>
+ </dependencySets>
+ <outputDirectory>/lib/ranger-hdfs-plugin-impl</outputDirectory>
+ </binaries>
+ <includes>
+ <include>org.apache.ranger:ranger_solrj</include>
+ <include>security_plugins.ranger-plugins-audit:ranger-plugins-audit</include>
+ <include>security_plugins.ranger-plugins-cred:ranger-plugins-cred</include>
+ <include>security_plugins.ranger-plugins-impl:ranger-plugins-impl</include>
+ <include>security_plugins.ranger-plugins-common:ranger-plugins-common</include>
+ <include>security_plugins.ranger-hdfs-plugin:ranger-hdfs-plugin</include>
+ </includes>
+ </moduleSet>
+
</moduleSets>
<fileSets>
<!-- conf.templates for enable -->
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/src/main/assembly/hive-agent.xml
----------------------------------------------------------------------
diff --git a/src/main/assembly/hive-agent.xml b/src/main/assembly/hive-agent.xml
index d21c6b8..9122547 100644
--- a/src/main/assembly/hive-agent.xml
+++ b/src/main/assembly/hive-agent.xml
@@ -24,6 +24,19 @@
<baseDirectory>${project.name}-${project.version}-hive-plugin</baseDirectory>
<includeBaseDirectory>true</includeBaseDirectory>
<moduleSets>
+ <moduleSet>
+ <binaries>
+ <includeDependencies>false</includeDependencies>
+ <unpack>false</unpack>
+ <directoryMode>755</directoryMode>
+ <fileMode>644</fileMode>
+ <outputDirectory>/lib</outputDirectory>
+ </binaries>
+ <includes>
+ <include>security_plugins.ranger-hive-plugin-shim:ranger-hive-plugin-shim</include>
+ <include>security_plugins.ranger-plugin-classloader:ranger-plugin-classloader</include>
+ </includes>
+ </moduleSet>
<moduleSet>
<binaries>
<includeDependencies>false</includeDependencies>
@@ -32,18 +45,18 @@
<fileMode>644</fileMode>
<dependencySets>
<dependencySet>
- <outputDirectory>/lib</outputDirectory>
+ <outputDirectory>/lib/ranger-hive-plugin-impl</outputDirectory>
<includes>
<include>com.google.code.gson:gson*</include>
<include>org.eclipse.persistence:eclipselink</include>
<include>org.eclipse.persistence:javax.persistence</include>
- <include>org.apache.httpcomponents:httpmime:jar:${httpcomponent.httpmime.version}</include>
- <include>org.noggit:noggit:jar:${noggit.version}</include>
+ <include>org.apache.httpcomponents:httpmime:jar:${httpcomponent.httpmime.version}</include>
+ <include>org.noggit:noggit:jar:${noggit.version}</include>
</includes>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
- <outputDirectory>/lib</outputDirectory>
+ <outputDirectory>/lib/ranger-hive-plugin-impl</outputDirectory>
</binaries>
<includes>
<include>org.apache.ranger:ranger_solrj</include>
@@ -56,7 +69,7 @@
</moduleSet>
<moduleSet>
<binaries>
- <includeDependencies>false</includeDependencies>
+ <includeDependencies>true</includeDependencies>
<dependencySets>
<dependencySet>
<outputDirectory>/install/lib</outputDirectory>
@@ -68,7 +81,7 @@
<include>commons-io:commons-io:jar:${commons.io.version}</include>
<include>commons-lang:commons-lang</include>
<include>commons-logging:commons-logging:jar:${commons.logging.version}</include>
- <include>com.google.guava:guava:jar:${guava.version}</include>
+ <include>com.google.guava:guava:jar:${google.guava.version}</include>
<include>org.hamcrest:hamcrest-all</include>
<include>junit:junit</include>
<include>org.slf4j:slf4j-api:jar:${slf4j-api.version}</include>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/src/main/assembly/knox-agent.xml
----------------------------------------------------------------------
diff --git a/src/main/assembly/knox-agent.xml b/src/main/assembly/knox-agent.xml
index 4806343..dc73f69 100644
--- a/src/main/assembly/knox-agent.xml
+++ b/src/main/assembly/knox-agent.xml
@@ -24,6 +24,21 @@
<baseDirectory>${project.name}-${project.version}-knox-plugin</baseDirectory>
<includeBaseDirectory>true</includeBaseDirectory>
<moduleSets>
+
+ <moduleSet>
+ <binaries>
+ <includeDependencies>false</includeDependencies>
+ <unpack>false</unpack>
+ <directoryMode>755</directoryMode>
+ <fileMode>644</fileMode>
+ <outputDirectory>/lib</outputDirectory>
+ </binaries>
+ <includes>
+ <include>security_plugins.ranger-knox-plugin-shim:ranger-knox-plugin-shim</include>
+ <include>security_plugins.ranger-plugin-classloader:ranger-plugin-classloader</include>
+ </includes>
+ </moduleSet>
+
<moduleSet>
<binaries>
<includeDependencies>false</includeDependencies>
@@ -32,10 +47,10 @@
<fileMode>644</fileMode>
<dependencySets>
<dependencySet>
- <outputDirectory>/lib</outputDirectory>
+ <outputDirectory>/lib/ranger-knox-plugin-impl</outputDirectory>
<includes>
<include>commons-configuration:commons-configuration</include>
- <include>com.google.code.gson:gson*</include>
+ <include>com.google.code.gson:gson*</include>
<include>org.apache.httpcomponents:httpmime:jar:${httpcomponent.httpmime.version}</include>
<include>org.noggit:noggit:jar:${noggit.version}</include>
<include>com.google.protobuf:protobuf-java:jar:${protobuf-java.version}</include>
@@ -45,7 +60,7 @@
<unpack>false</unpack>
</dependencySet>
</dependencySets>
- <outputDirectory>/lib</outputDirectory>
+ <outputDirectory>/lib/ranger-knox-plugin-impl</outputDirectory>
</binaries>
<includes>
<include>org.apache.ranger:ranger_solrj</include>
@@ -72,7 +87,7 @@
<include>commons-io:commons-io:jar:${commons.io.version}</include>
<include>commons-lang:commons-lang</include>
<include>commons-logging:commons-logging:jar:${commons.logging.version}</include>
- <include>com.google.guava:guava:jar:${guava.version}</include>
+ <include>com.google.guava:guava:jar:${google.guava.version}</include>
<include>org.hamcrest:hamcrest-all</include>
<include>junit:junit</include>
<include>org.slf4j:slf4j-api:jar:${slf4j-api.version}</include>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/src/main/assembly/plugin-kafka.xml
----------------------------------------------------------------------
diff --git a/src/main/assembly/plugin-kafka.xml b/src/main/assembly/plugin-kafka.xml
index 3727bde..31498e5 100644
--- a/src/main/assembly/plugin-kafka.xml
+++ b/src/main/assembly/plugin-kafka.xml
@@ -20,14 +20,28 @@
<includeBaseDirectory>true</includeBaseDirectory>
<moduleSets>
<moduleSet>
+ <binaries>
+ <includeDependencies>false</includeDependencies>
+ <unpack>false</unpack>
+ <directoryMode>755</directoryMode>
+ <fileMode>644</fileMode>
+ <outputDirectory>/lib</outputDirectory>
+ </binaries>
+ <includes>
+ <include>security_plugins.ranger-kafka-plugin-shim:ranger-kafka-plugin-shim</include>
+ <include>security_plugins.ranger-plugin-classloader:ranger-plugin-classloader</include>
+ </includes>
+ </moduleSet>
+
+ <moduleSet>
<binaries>
- <includeDependencies>false</includeDependencies>
+ <includeDependencies>true</includeDependencies>
<unpack>false</unpack>
<directoryMode>755</directoryMode>
<fileMode>644</fileMode>
<dependencySets>
<dependencySet>
- <outputDirectory>/lib</outputDirectory>
+ <outputDirectory>lib/ranger-kafka-plugin-impl</outputDirectory>
<unpack>false</unpack>
<includes>
<include>commons-configuration:commons-configuration:jar:${commons.configuration.version}
@@ -38,6 +52,7 @@
</include>
<include>org.apache.hadoop:hadoop-auth:jar:${hadoop-common.version}
</include>
+ <include>org.apache.hadoop:hadoop-hdfs:jar:${hadoop.version}</include>
<include>com.google.code.gson:gson</include>
<include>org.eclipse.persistence:eclipselink</include>
<include>org.eclipse.persistence:javax.persistence</include>
@@ -47,7 +62,7 @@
</include>
<include>commons-lang:commons-lang</include>
<include>commons-io:commons-io</include>
- <include>com.google.guava:guava:jar:${guava.version}</include>
+ <include>com.google.guava:guava:jar:${google.guava.version}</include>
<include>org.apache.httpcomponents:httpclient:jar:${httpcomponent.httpclient.version}
</include>
<include>org.apache.httpcomponents:httpcore:jar:${httpcomponent.httpcore.version}
@@ -59,7 +74,6 @@
<include>org.codehaus.jackson:jackson-jaxrs</include>
<include>org.codehaus.jackson:jackson-mapper-asl</include>
<include>org.codehaus.jackson:jackson-xc</include>
-
</includes>
</dependencySet>
<dependencySet>
@@ -77,7 +91,7 @@
<include>commons-lang:commons-lang:jar:${commons.lang.version}
</include>
<include>commons-logging:commons-logging</include>
- <include>com.google.guava:guava:jar:${guava.version}</include>
+ <include>com.google.guava:guava:jar:${google.guava.version}</include>
<include>org.hamcrest:hamcrest-all</include>
<include>junit:junit</include>
<include>org.slf4j:slf4j-api:jar:${slf4j-api.version}</include>
@@ -91,20 +105,14 @@
</includes>
</dependencySet>
</dependencySets>
- <outputDirectory>/lib</outputDirectory>
+ <outputDirectory>lib/ranger-kafka-plugin-impl</outputDirectory>
</binaries>
<includes>
+ <include>security_plugins.ranger-kafka-plugin:ranger-kafka-plugin</include>
<include>org.apache.ranger:ranger_solrj</include>
- <include>security_plugins.ranger-plugins-audit:ranger-plugins-audit
- </include>
- <include>security_plugins.ranger-plugins-cred:ranger-plugins-cred
- </include>
- <include>security_plugins.ranger-plugins-impl:ranger-plugins-impl
- </include>
- <include>security_plugins.ranger-plugins-common:ranger-plugins-common
- </include>
- <include>security_plugins.ranger-kafka-plugin:ranger-kafka-plugin
- </include>
+ <include>security_plugins.ranger-plugins-audit:ranger-plugins-audit</include>
+ <include>security_plugins.ranger-plugins-cred:ranger-plugins-cred</include>
+ <include>security_plugins.ranger-plugins-common:ranger-plugins-common</include>
</includes>
</moduleSet>
<moduleSet>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/src/main/assembly/plugin-yarn.xml
----------------------------------------------------------------------
diff --git a/src/main/assembly/plugin-yarn.xml b/src/main/assembly/plugin-yarn.xml
index a791bba..6f8e33b 100644
--- a/src/main/assembly/plugin-yarn.xml
+++ b/src/main/assembly/plugin-yarn.xml
@@ -24,6 +24,20 @@
<baseDirectory>${project.name}-${project.version}-yarn-plugin</baseDirectory>
<includeBaseDirectory>true</includeBaseDirectory>
<moduleSets>
+ <moduleSet>
+ <binaries>
+ <includeDependencies>false</includeDependencies>
+ <unpack>false</unpack>
+ <directoryMode>755</directoryMode>
+ <fileMode>644</fileMode>
+ <outputDirectory>/lib</outputDirectory>
+ </binaries>
+ <includes>
+ <include>security_plugins.ranger-yarn-plugin-shim:ranger-yarn-plugin-shim</include>
+ <include>security_plugins.ranger-plugin-classloader:ranger-plugin-classloader</include>
+ </includes>
+ </moduleSet>
+
<moduleSet>
<binaries>
<includeDependencies>false</includeDependencies>
@@ -32,7 +46,7 @@
<fileMode>644</fileMode>
<dependencySets>
<dependencySet>
- <outputDirectory>/lib</outputDirectory>
+ <outputDirectory>/lib/ranger-yarn-plugin-impl</outputDirectory>
<unpack>false</unpack>
<includes>
<include>org.apache.hadoop:hadoop-common:jar:${hadoop-common.version}</include>
@@ -54,8 +68,8 @@
<include>commons-configuration:commons-configuration:jar:${commons.configuration.version}</include>
<include>commons-io:commons-io:jar:${commons.io.version}</include>
<include>commons-lang:commons-lang:jar:${commons.lang.version}</include>
- <include>commons-logging:commons-logging</include>
- <include>com.google.guava:guava:jar:${guava.version}</include>
+ <include>commons-logging:commons-logging:jar:${commons.logging.version}</include>
+ <include>com.google.guava:guava:jar:${google.guava.version}</include>
<include>org.hamcrest:hamcrest-all</include>
<include>junit:junit</include>
<include>org.slf4j:slf4j-api:jar:${slf4j-api.version}</include>
@@ -66,7 +80,7 @@
</includes>
</dependencySet>
</dependencySets>
- <outputDirectory>/lib</outputDirectory>
+ <outputDirectory>/lib/ranger-yarn-plugin-impl</outputDirectory>
</binaries>
<includes>
<include>org.apache.ranger:ranger_solrj</include>
@@ -79,7 +93,7 @@
</moduleSet>
<moduleSet>
<binaries>
- <includeDependencies>false</includeDependencies>
+ <includeDependencies>true</includeDependencies>
<outputDirectory>/install/lib</outputDirectory>
<unpack>false</unpack>
</binaries>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/src/main/assembly/storm-agent.xml
----------------------------------------------------------------------
diff --git a/src/main/assembly/storm-agent.xml b/src/main/assembly/storm-agent.xml
index 12ec052..a5f4b2c 100644
--- a/src/main/assembly/storm-agent.xml
+++ b/src/main/assembly/storm-agent.xml
@@ -30,9 +30,22 @@
<unpack>false</unpack>
<directoryMode>755</directoryMode>
<fileMode>644</fileMode>
+ <outputDirectory>/lib</outputDirectory>
+ </binaries>
+ <includes>
+ <include>security_plugins.ranger-storm-plugin-shim:ranger-storm-plugin-shim</include>
+ <include>security_plugins.ranger-plugin-classloader:ranger-plugin-classloader</include>
+ </includes>
+ </moduleSet>
+ <moduleSet>
+ <binaries>
+ <includeDependencies>true</includeDependencies>
+ <unpack>false</unpack>
+ <directoryMode>755</directoryMode>
+ <fileMode>644</fileMode>
<dependencySets>
<dependencySet>
- <outputDirectory>/lib</outputDirectory>
+ <outputDirectory>lib/ranger-storm-plugin-impl</outputDirectory>
<unpack>false</unpack>
<includes>
<include>commons-configuration:commons-configuration:jar:${commons.configuration.version}</include>
@@ -44,7 +57,7 @@
<include>commons-collections:commons-collections</include>
<include>com.sun.jersey:jersey-bundle</include>
<include>commons-logging:commons-logging:jar:${commons.logging.version}</include>
- <include>com.google.guava:guava:jar:${guava.version}</include>
+ <include>com.google.guava:guava:jar:${google.guava.version}</include>
<include>org.codehaus.jackson:jackson-jaxrs:jar:${codehaus.jackson.version}</include>
<include>org.codehaus.jackson:jackson-core-asl:jar:${codehaus.jackson.storm.version}</include>
<include>org.codehaus.jackson:jackson-mapper-asl:jar:${codehaus.jackson.storm.version}</include>
@@ -55,7 +68,7 @@
<include>com.google.protobuf:protobuf-java:jar:${protobuf-java.version}</include>
<include>org.apache.hadoop:hadoop-hdfs:jar:${hadoop.version}</include>
<include>org.apache.htrace:htrace-core:jar:${htrace-core.version}</include>
- <include>commons-cli:commons-cli:jar:${commons.cli.version}</include>
+ <include>commons-cli:commons-cli:jar:${commons.cli.version}</include>
<include>commons-lang:commons-lang:jar:${commons.lang.version}</include>
<include>commons-io:commons-io:jar:${commons.io.version}</include>
</includes>
@@ -72,7 +85,7 @@
<include>commons-io:commons-io:jar:${commons.io.version}</include>
<include>commons-lang:commons-lang:jar:${commons.lang.version}</include>
<include>commons-logging:commons-logging</include>
- <include>com.google.guava:guava:jar:${guava.version}</include>
+ <include>com.google.guava:guava:jar:${google.guava.version}</include>
<include>org.hamcrest:hamcrest-all</include>
<include>junit:junit</include>
<include>org.slf4j:slf4j-api:jar:${slf4j-api.version}</include>
@@ -83,7 +96,7 @@
</includes>
</dependencySet>
</dependencySets>
- <outputDirectory>/lib</outputDirectory>
+ <outputDirectory>lib/ranger-storm-plugin-impl</outputDirectory>
</binaries>
<includes>
<include>org.apache.ranger:ranger_solrj</include>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/storm-agent/src/main/java/com/xasecure/authorization/storm/authorizer/XaSecureStormAuthorizer.java
----------------------------------------------------------------------
diff --git a/storm-agent/src/main/java/com/xasecure/authorization/storm/authorizer/XaSecureStormAuthorizer.java b/storm-agent/src/main/java/com/xasecure/authorization/storm/authorizer/XaSecureStormAuthorizer.java
deleted file mode 100644
index 723dd79..0000000
--- a/storm-agent/src/main/java/com/xasecure/authorization/storm/authorizer/XaSecureStormAuthorizer.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package com.xasecure.authorization.storm.authorizer;
-
-import org.apache.ranger.authorization.storm.authorizer.RangerStormAuthorizer;
-
-/**
- * This class exists only to provide for seamless upgrade/downgrade capabilities. Class name is in storm conf which must allow for seamles upgrade and downgrade.
- * Thus when class names were changed XaSecure* -> Ranger* this shell class serves to allow for seamles upgrade as well as downgrade.
- *
- * This class is final because if one needs to customize coprocessor it is expected that RangerStormAuthorizer would be modified/extended as that is
- * the "real" authorizer! This class, hence, should NEVER be more than an EMPTY shell!
- */
-final public class XaSecureStormAuthorizer extends RangerStormAuthorizer {
-}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/storm-agent/src/main/java/org/apache/ranger/authorization/storm/authorizer/RangerStormAuthorizer.java
----------------------------------------------------------------------
diff --git a/storm-agent/src/main/java/org/apache/ranger/authorization/storm/authorizer/RangerStormAuthorizer.java b/storm-agent/src/main/java/org/apache/ranger/authorization/storm/authorizer/RangerStormAuthorizer.java
deleted file mode 100644
index 3687527..0000000
--- a/storm-agent/src/main/java/org/apache/ranger/authorization/storm/authorizer/RangerStormAuthorizer.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
- package org.apache.ranger.authorization.storm.authorizer;
-
-import java.security.Principal;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.hadoop.security.UserGroupInformation;
-import org.apache.ranger.authorization.storm.StormRangerPlugin;
-import org.apache.ranger.authorization.utils.StringUtil;
-import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
-import org.apache.ranger.plugin.policyengine.RangerAccessResult;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Sets;
-
-import backtype.storm.Config;
-import backtype.storm.security.auth.IAuthorizer;
-import backtype.storm.security.auth.ReqContext;
-
-public class RangerStormAuthorizer implements IAuthorizer {
-
- private static final Logger LOG = LoggerFactory.getLogger(RangerStormAuthorizer.class);
-
- static final StormRangerPlugin plugin = new StormRangerPlugin();
-
- static final Set<String> noAuthzOperations = Sets.newHashSet(new String[] { "getNimbusConf", "getClusterInfo" });
-
- /**
- * permit() method is invoked for each incoming Thrift request.
- * @param context request context includes info about
- * @param operation operation name
- * @param topology_storm configuration of targeted topology
- * @return true if the request is authorized, false if reject
- */
-
- @Override
- public boolean permit(ReqContext aRequestContext, String aOperationName, Map aTopologyConfigMap) {
-
- boolean accessAllowed = false ;
- boolean isAuditEnabled = false;
-
- String topologyName = null ;
-
- try {
- topologyName = (aTopologyConfigMap == null ? "" : (String)aTopologyConfigMap.get(Config.TOPOLOGY_NAME)) ;
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("[req "+ aRequestContext.requestID()+ "] Access "
- + " from: [" + aRequestContext.remoteAddress() + "]"
- + " user: [" + aRequestContext.principal() + "],"
- + " op: [" + aOperationName + "],"
- + "topology: [" + topologyName + "]") ;
-
- if (aTopologyConfigMap != null) {
- for(Object keyObj : aTopologyConfigMap.keySet()) {
- Object valObj = aTopologyConfigMap.get(keyObj) ;
- LOG.debug("TOPOLOGY CONFIG MAP [" + keyObj + "] => [" + valObj + "]");
- }
- }
- else {
- LOG.debug("TOPOLOGY CONFIG MAP is passed as null.") ;
- }
- }
-
- if(noAuthzOperations.contains(aOperationName)) {
- accessAllowed = true;
- } else {
- String userName = null ;
- String[] groups = null ;
-
- Principal user = aRequestContext.principal() ;
-
- if (user != null) {
- userName = user.getName() ;
- if (userName != null) {
- UserGroupInformation ugi = UserGroupInformation.createRemoteUser(userName) ;
- userName = ugi.getShortUserName() ;
- groups = ugi.getGroupNames() ;
- if (LOG.isDebugEnabled()) {
- LOG.debug("User found from principal [" + user.getName() + "] => user:[" + userName + "], groups:[" + StringUtil.toString(groups) + "]") ;
- }
- }
- }
-
-
- if (userName != null) {
- String clientIp = (aRequestContext.remoteAddress() == null ? null : aRequestContext.remoteAddress().getHostAddress() ) ;
- RangerAccessRequest accessRequest = plugin.buildAccessRequest(userName, groups, clientIp, topologyName, aOperationName);
- RangerAccessResult result = plugin.isAccessAllowed(accessRequest);
- accessAllowed = result != null && result.getIsAllowed();
- isAuditEnabled = result != null && result.getIsAudited();
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("User found from principal [" + userName + "], groups [" + StringUtil.toString(groups) + "]: verifying using [" + plugin.getClass().getName() + "], allowedFlag => [" + accessAllowed + "], Audit Enabled:" + isAuditEnabled);
- }
- }
- else {
- LOG.info("NULL User found from principal [" + user + "]: Skipping authorization; allowedFlag => [" + accessAllowed + "], Audit Enabled:" + isAuditEnabled);
- }
- }
- }
- catch(Throwable t) {
- LOG.error("RangerStormAuthorizer found this exception", t);
- }
- finally {
- if (LOG.isDebugEnabled()) {
- LOG.debug("[req "+ aRequestContext.requestID()+ "] Access "
- + " from: [" + aRequestContext.remoteAddress() + "]"
- + " user: [" + aRequestContext.principal() + "],"
- + " op: [" + aOperationName + "],"
- + "topology: [" + topologyName + "] => returns [" + accessAllowed + "], Audit Enabled:" + isAuditEnabled) ;
- }
- }
-
- return accessAllowed ;
- }
-
- /**
- * Invoked once immediately after construction
- * @param conf Storm configuration
- */
-
- @Override
- public void prepare(Map aStormConfigMap) {
- plugin.init();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/storm-agent/src/main/java/org/apache/ranger/authorization/storm/authorizer/RangerStormAuthorizerImpl.java
----------------------------------------------------------------------
diff --git a/storm-agent/src/main/java/org/apache/ranger/authorization/storm/authorizer/RangerStormAuthorizerImpl.java b/storm-agent/src/main/java/org/apache/ranger/authorization/storm/authorizer/RangerStormAuthorizerImpl.java
new file mode 100644
index 0000000..2cf4c00
--- /dev/null
+++ b/storm-agent/src/main/java/org/apache/ranger/authorization/storm/authorizer/RangerStormAuthorizerImpl.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+ package org.apache.ranger.authorization.storm.authorizer;
+
+import java.security.Principal;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.ranger.authorization.storm.StormRangerPlugin;
+import org.apache.ranger.authorization.utils.StringUtil;
+import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
+import org.apache.ranger.plugin.policyengine.RangerAccessResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Sets;
+
+import backtype.storm.Config;
+import backtype.storm.security.auth.IAuthorizer;
+import backtype.storm.security.auth.ReqContext;
+
+public class RangerStormAuthorizerImpl implements IAuthorizer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(RangerStormAuthorizerImpl.class);
+
+ static final StormRangerPlugin plugin = new StormRangerPlugin();
+
+ static final Set<String> noAuthzOperations = Sets.newHashSet(new String[] { "getNimbusConf", "getClusterInfo" });
+
+ /**
+ * permit() method is invoked for each incoming Thrift request.
+ * @param context request context includes info about
+ * @param operation operation name
+ * @param topology_storm configuration of targeted topology
+ * @return true if the request is authorized, false if reject
+ */
+
+ @Override
+ public boolean permit(ReqContext aRequestContext, String aOperationName, Map aTopologyConfigMap) {
+
+ boolean accessAllowed = false ;
+ boolean isAuditEnabled = false;
+
+ String topologyName = null ;
+
+ try {
+ topologyName = (aTopologyConfigMap == null ? "" : (String)aTopologyConfigMap.get(Config.TOPOLOGY_NAME)) ;
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("[req "+ aRequestContext.requestID()+ "] Access "
+ + " from: [" + aRequestContext.remoteAddress() + "]"
+ + " user: [" + aRequestContext.principal() + "],"
+ + " op: [" + aOperationName + "],"
+ + "topology: [" + topologyName + "]") ;
+
+ if (aTopologyConfigMap != null) {
+ for(Object keyObj : aTopologyConfigMap.keySet()) {
+ Object valObj = aTopologyConfigMap.get(keyObj) ;
+ LOG.debug("TOPOLOGY CONFIG MAP [" + keyObj + "] => [" + valObj + "]");
+ }
+ }
+ else {
+ LOG.debug("TOPOLOGY CONFIG MAP is passed as null.") ;
+ }
+ }
+
+ if(noAuthzOperations.contains(aOperationName)) {
+ accessAllowed = true;
+ } else {
+ String userName = null ;
+ String[] groups = null ;
+
+ Principal user = aRequestContext.principal() ;
+
+ if (user != null) {
+ userName = user.getName() ;
+ if (userName != null) {
+ UserGroupInformation ugi = UserGroupInformation.createRemoteUser(userName) ;
+ userName = ugi.getShortUserName() ;
+ groups = ugi.getGroupNames() ;
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("User found from principal [" + user.getName() + "] => user:[" + userName + "], groups:[" + StringUtil.toString(groups) + "]") ;
+ }
+ }
+ }
+
+
+ if (userName != null) {
+ String clientIp = (aRequestContext.remoteAddress() == null ? null : aRequestContext.remoteAddress().getHostAddress() ) ;
+ RangerAccessRequest accessRequest = plugin.buildAccessRequest(userName, groups, clientIp, topologyName, aOperationName);
+ RangerAccessResult result = plugin.isAccessAllowed(accessRequest);
+ accessAllowed = result != null && result.getIsAllowed();
+ isAuditEnabled = result != null && result.getIsAudited();
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("User found from principal [" + userName + "], groups [" + StringUtil.toString(groups) + "]: verifying using [" + plugin.getClass().getName() + "], allowedFlag => [" + accessAllowed + "], Audit Enabled:" + isAuditEnabled);
+ }
+ }
+ else {
+ LOG.info("NULL User found from principal [" + user + "]: Skipping authorization; allowedFlag => [" + accessAllowed + "], Audit Enabled:" + isAuditEnabled);
+ }
+ }
+ }
+ catch(Throwable t) {
+ LOG.error("RangerStormAuthorizer found this exception", t);
+ }
+ finally {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("[req "+ aRequestContext.requestID()+ "] Access "
+ + " from: [" + aRequestContext.remoteAddress() + "]"
+ + " user: [" + aRequestContext.principal() + "],"
+ + " op: [" + aOperationName + "],"
+ + "topology: [" + topologyName + "] => returns [" + accessAllowed + "], Audit Enabled:" + isAuditEnabled) ;
+ }
+ }
+
+ return accessAllowed ;
+ }
+
+ /**
+ * Invoked once immediately after construction
+ * @param conf Storm configuration
+ */
+
+ @Override
+ public void prepare(Map aStormConfigMap) {
+ plugin.init();
+ }
+
+}
[5/6] incubator-ranger git commit: RANGER-586: Ranger plugins should
not add dependent libraries to component's CLASSPATH
Posted by rm...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/hbase-agent/src/main/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessorImpl.java
----------------------------------------------------------------------
diff --git a/hbase-agent/src/main/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessorImpl.java b/hbase-agent/src/main/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessorImpl.java
new file mode 100644
index 0000000..66b0dd0
--- /dev/null
+++ b/hbase-agent/src/main/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessorImpl.java
@@ -0,0 +1,1393 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ranger.authorization.hbase;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.NavigableSet;
+import java.util.Set;
+import java.util.TimeZone;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CoprocessorEnvironment;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.NamespaceDescriptor;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Append;
+import org.apache.hadoop.hbase.client.Delete;
+import org.apache.hadoop.hbase.client.Durability;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.Increment;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.coprocessor.CoprocessorException;
+import org.apache.hadoop.hbase.coprocessor.CoprocessorService;
+import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment;
+import org.apache.hadoop.hbase.coprocessor.ObserverContext;
+import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
+import org.apache.hadoop.hbase.coprocessor.RegionServerCoprocessorEnvironment;
+import org.apache.hadoop.hbase.filter.ByteArrayComparable;
+import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
+import org.apache.hadoop.hbase.filter.Filter;
+import org.apache.hadoop.hbase.filter.FilterList;
+import org.apache.hadoop.hbase.ipc.RpcServer;
+import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
+import org.apache.hadoop.hbase.protobuf.ResponseConverter;
+import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos;
+import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.AccessControlService;
+import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription;
+import org.apache.hadoop.hbase.protobuf.generated.QuotaProtos.Quotas;
+import org.apache.hadoop.hbase.protobuf.generated.SecureBulkLoadProtos.CleanupBulkLoadRequest;
+import org.apache.hadoop.hbase.protobuf.generated.SecureBulkLoadProtos.PrepareBulkLoadRequest;
+import org.apache.hadoop.hbase.regionserver.InternalScanner;
+import org.apache.hadoop.hbase.regionserver.Region;
+import org.apache.hadoop.hbase.regionserver.RegionScanner;
+import org.apache.hadoop.hbase.regionserver.ScanType;
+import org.apache.hadoop.hbase.regionserver.Store;
+import org.apache.hadoop.hbase.regionserver.StoreFile;
+import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
+import org.apache.hadoop.hbase.security.AccessDeniedException;
+import org.apache.hadoop.hbase.security.User;
+import org.apache.hadoop.hbase.security.access.Permission;
+import org.apache.hadoop.hbase.security.access.Permission.Action;
+import org.apache.hadoop.hbase.security.access.TablePermission;
+import org.apache.hadoop.hbase.security.access.UserPermission;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Pair;
+import org.apache.hadoop.security.AccessControlException;
+import org.apache.ranger.audit.model.AuthzAuditEvent;
+import org.apache.ranger.authorization.hadoop.config.RangerConfiguration;
+import org.apache.ranger.authorization.hadoop.constants.RangerHadoopConstants;
+import org.apache.ranger.authorization.utils.StringUtil;
+import org.apache.ranger.plugin.audit.RangerDefaultAuditHandler;
+import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
+import org.apache.ranger.plugin.policyengine.RangerAccessResultProcessor;
+import org.apache.ranger.plugin.service.RangerBasePlugin;
+import org.apache.ranger.plugin.util.GrantRevokeRequest;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.Lists;
+import com.google.common.collect.MapMaker;
+import com.google.protobuf.RpcCallback;
+import com.google.protobuf.RpcController;
+import com.google.protobuf.Service;
+
+public class RangerAuthorizationCoprocessorImpl extends RangerAuthorizationCoprocessorBase implements AccessControlService.Interface, CoprocessorService {
+ private static final Log LOG = LogFactory.getLog(RangerAuthorizationCoprocessorImpl.class.getName());
+ private static boolean UpdateRangerPoliciesOnGrantRevoke = RangerHadoopConstants.HBASE_UPDATE_RANGER_POLICIES_ON_GRANT_REVOKE_DEFAULT_VALUE;
+ private static final String GROUP_PREFIX = "@";
+
+ private static final String WILDCARD = "*";
+ private static final String NAMESPACE_SEPARATOR = ":";
+
+ private static final TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT+0");
+
+ private RegionCoprocessorEnvironment regionEnv;
+ private Map<InternalScanner, String> scannerOwners = new MapMaker().weakKeys().makeMap();
+
+ /*
+ * These are package level only for testability and aren't meant to be exposed outside via getters/setters or made available to derived classes.
+ */
+ final HbaseFactory _factory = HbaseFactory.getInstance();
+ final HbaseUserUtils _userUtils = _factory.getUserUtils();
+ final HbaseAuthUtils _authUtils = _factory.getAuthUtils();
+ private static volatile RangerHBasePlugin hbasePlugin = null;
+
+ // Utilities Methods
+ protected byte[] getTableName(RegionCoprocessorEnvironment e) {
+ Region region = e.getRegion();
+ byte[] tableName = null;
+ if (region != null) {
+ HRegionInfo regionInfo = region.getRegionInfo();
+ if (regionInfo != null) {
+ tableName = regionInfo.getTable().getName() ;
+ }
+ }
+ return tableName;
+ }
+ protected void requireSystemOrSuperUser(Configuration conf) throws IOException {
+ User user = User.getCurrent();
+ if (user == null) {
+ throw new IOException("Unable to obtain the current user, authorization checks for internal operations will not work correctly!");
+ }
+ String systemUser = user.getShortName();
+ User activeUser = getActiveUser();
+ if (!Objects.equal(systemUser, activeUser.getShortName()) && !_userUtils.isSuperUser(activeUser)) {
+ throw new AccessDeniedException("User '" + user.getShortName() + "is not system or super user.");
+ }
+ }
+ protected boolean isSpecialTable(HRegionInfo regionInfo) {
+ return isSpecialTable(regionInfo.getTable().getName());
+ }
+ protected boolean isSpecialTable(byte[] tableName) {
+ return isSpecialTable(Bytes.toString(tableName));
+ }
+ protected boolean isSpecialTable(String input) {
+ final String[] specialTables = new String[] { "hbase:meta", "-ROOT-", ".META."};
+ for (String specialTable : specialTables ) {
+ if (specialTable.equals(input)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ protected boolean isAccessForMetaTables(RegionCoprocessorEnvironment env) {
+ HRegionInfo hri = env.getRegion().getRegionInfo();
+
+ if (hri.isMetaTable() || hri.isMetaRegion()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private User getActiveUser() {
+ User user = RpcServer.getRequestUser();
+ if (user == null) {
+ // for non-rpc handling, fallback to system user
+ try {
+ user = User.getCurrent();
+ } catch (IOException e) {
+ LOG.error("Unable to find the current user");
+ user = null;
+ }
+ }
+ return user;
+ }
+
+ private String getRemoteAddress() {
+ InetAddress remoteAddr = RpcServer.getRemoteAddress();
+
+ if(remoteAddr == null) {
+ remoteAddr = RpcServer.getRemoteIp();
+ }
+
+ String strAddr = remoteAddr != null ? remoteAddr.getHostAddress() : null;
+
+ return strAddr;
+ }
+
+ // Methods that are used within the CoProcessor
+ private void requireScannerOwner(InternalScanner s) throws AccessDeniedException {
+ if (!RpcServer.isInRpcCallContext()) {
+ return;
+ }
+
+ String requestUserName = RpcServer.getRequestUserName();
+ String owner = scannerOwners.get(s);
+ if (owner != null && !owner.equals(requestUserName)) {
+ throw new AccessDeniedException("User '"+ requestUserName +"' is not the scanner owner!");
+ }
+ }
+ /**
+ * @param families
+ * @return empty map if families is null, would never have empty or null keys, would never have null values, values could be empty (non-null) set
+ */
+ Map<String, Set<String>> getColumnFamilies(Map<byte[], ? extends Collection<?>> families) {
+ if (families == null) {
+ // null families map passed. Ok, returning empty map.
+ return Collections.<String, Set<String>>emptyMap();
+ }
+ Map<String, Set<String>> result = new HashMap<String, Set<String>>();
+ for (Map.Entry<byte[], ? extends Collection<?>> anEntry : families.entrySet()) {
+ byte[] familyBytes = anEntry.getKey();
+ String family = Bytes.toString(familyBytes);
+ if (family == null || family.isEmpty()) {
+ LOG.error("Unexpected Input: got null or empty column family (key) in families map! Ignoring...");
+ } else {
+ Collection<?> columnCollection = anEntry.getValue();
+ if (CollectionUtils.isEmpty(columnCollection)) {
+ // family points to null map, OK.
+ result.put(family, Collections.<String> emptySet());
+ } else {
+ Iterator<String> columnIterator = new ColumnIterator(columnCollection);
+ Set<String> columns = new HashSet<String>();
+ while (columnIterator.hasNext()) {
+ String column = columnIterator.next();
+ columns.add(column);
+ }
+ result.put(family, columns);
+ }
+ }
+ }
+ return result;
+ }
+
+ static class ColumnFamilyAccessResult {
+ final boolean _everythingIsAccessible;
+ final boolean _somethingIsAccessible;
+ final List<AuthzAuditEvent> _accessAllowedEvents;
+ final List<AuthzAuditEvent> _familyLevelAccessEvents;
+ final AuthzAuditEvent _accessDeniedEvent;
+ final String _denialReason;
+ final RangerAuthorizationFilter _filter;
+
+ ColumnFamilyAccessResult(boolean everythingIsAccessible, boolean somethingIsAccessible,
+ List<AuthzAuditEvent> accessAllowedEvents, List<AuthzAuditEvent> familyLevelAccessEvents, AuthzAuditEvent accessDeniedEvent, String denialReason,
+ RangerAuthorizationFilter filter) {
+ _everythingIsAccessible = everythingIsAccessible;
+ _somethingIsAccessible = somethingIsAccessible;
+ // WARNING: we are just holding on to reference of the collection. Potentially risky optimization
+ _accessAllowedEvents = accessAllowedEvents;
+ _familyLevelAccessEvents = familyLevelAccessEvents;
+ _accessDeniedEvent = accessDeniedEvent;
+ _denialReason = denialReason;
+ // cached values of access results
+ _filter = filter;
+ }
+
+ @Override
+ public String toString() {
+ return Objects.toStringHelper(getClass())
+ .add("everythingIsAccessible", _everythingIsAccessible)
+ .add("somethingIsAccessible", _somethingIsAccessible)
+ .add("accessAllowedEvents", _accessAllowedEvents)
+ .add("familyLevelAccessEvents", _familyLevelAccessEvents)
+ .add("accessDeniedEvent", _accessDeniedEvent)
+ .add("denialReason", _denialReason)
+ .add("filter", _filter)
+ .toString();
+
+ }
+ }
+
+ ColumnFamilyAccessResult evaluateAccess(String operation, Action action, final RegionCoprocessorEnvironment env,
+ final Map<byte[], ? extends Collection<?>> familyMap) throws AccessDeniedException {
+
+ String access = _authUtils.getAccess(action);
+ User user = getActiveUser();
+ String userName = _userUtils.getUserAsString(user);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(String.format("evaluateAccess: entered: user[%s], Operation[%s], access[%s], families[%s]",
+ userName, operation, access, getColumnFamilies(familyMap).toString()));
+ }
+
+ byte[] tableBytes = getTableName(env);
+ if (tableBytes == null || tableBytes.length == 0) {
+ String message = "evaluateAccess: Unexpected: Couldn't get table from RegionCoprocessorEnvironment. Access denied, not audited";
+ LOG.debug(message);
+ throw new AccessDeniedException("Insufficient permissions for operation '" + operation + "',action: " + action);
+ }
+ String table = Bytes.toString(tableBytes);
+
+ final String messageTemplate = "evaluateAccess: exiting: user[%s], Operation[%s], access[%s], families[%s], verdict[%s]";
+ ColumnFamilyAccessResult result;
+ if (canSkipAccessCheck(operation, access, table) || canSkipAccessCheck(operation, access, env)) {
+ LOG.debug("evaluateAccess: exiting: isKnownAccessPattern returned true: access allowed, not audited");
+ result = new ColumnFamilyAccessResult(true, true, null, null, null, null, null);
+ if (LOG.isDebugEnabled()) {
+ Map<String, Set<String>> families = getColumnFamilies(familyMap);
+ String message = String.format(messageTemplate, userName, operation, access, families.toString(), result.toString());
+ LOG.debug(message);
+ }
+ return result;
+ }
+
+ // let's create a session that would be reused. Set things on it that won't change.
+ HbaseAuditHandler auditHandler = _factory.getAuditHandler();
+ AuthorizationSession session = new AuthorizationSession(hbasePlugin)
+ .operation(operation)
+ .remoteAddress(getRemoteAddress())
+ .auditHandler(auditHandler)
+ .user(user)
+ .access(access)
+ .table(table);
+ Map<String, Set<String>> families = getColumnFamilies(familyMap);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("evaluateAccess: families to process: " + families.toString());
+ }
+ if (families == null || families.isEmpty()) {
+ LOG.debug("evaluateAccess: Null or empty families collection, ok. Table level access is desired");
+ session.buildRequest()
+ .authorize();
+ boolean authorized = session.isAuthorized();
+ String reason = "";
+ if (authorized) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("evaluateAccess: table level access granted [" + table + "]");
+ }
+ } else {
+ reason = String.format("Insufficient permissions for user ‘%s',action: %s, tableName:%s, no column families found.", user.getName(), operation, table);
+ }
+ AuthzAuditEvent event = auditHandler.getAndDiscardMostRecentEvent(); // this could be null, of course, depending on audit settings of table.
+
+ // if authorized then pass captured events as access allowed set else as access denied set.
+ result = new ColumnFamilyAccessResult(authorized, authorized,
+ authorized ? Collections.singletonList(event) : null,
+ null, authorized ? null : event, reason, null);
+ if (LOG.isDebugEnabled()) {
+ String message = String.format(messageTemplate, userName, operation, access, families.toString(), result.toString());
+ LOG.debug(message);
+ }
+ return result;
+ } else {
+ LOG.debug("evaluateAccess: Families collection not null. Skipping table-level check, will do finer level check");
+ }
+
+ boolean everythingIsAccessible = true;
+ boolean somethingIsAccessible = false;
+ /*
+ * we would have to accumulate audits of all successful accesses and any one denial (which in our case ends up being the last denial)
+ * We need to keep audit events for family level access check seperate because we don't want them logged in some cases.
+ */
+ List<AuthzAuditEvent> authorizedEvents = new ArrayList<AuthzAuditEvent>();
+ List<AuthzAuditEvent> familyLevelAccessEvents = new ArrayList<AuthzAuditEvent>();
+ AuthzAuditEvent deniedEvent = null;
+ String denialReason = null;
+ // we need to cache the auths results so that we can create a filter, if needed
+ Map<String, Set<String>> columnsAccessAllowed = new HashMap<String, Set<String>>();
+ Set<String> familesAccessAllowed = new HashSet<String>();
+ Set<String> familesAccessDenied = new HashSet<String>();
+ Set<String> familesAccessIndeterminate = new HashSet<String>();
+
+ for (Map.Entry<String, Set<String>> anEntry : families.entrySet()) {
+ String family = anEntry.getKey();
+ session.columnFamily(family);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("evaluateAccess: Processing family: " + family);
+ }
+ Set<String> columns = anEntry.getValue();
+ if (columns == null || columns.isEmpty()) {
+ LOG.debug("evaluateAccess: columns collection null or empty, ok. Family level access is desired.");
+ session.column(null) // zap stale column from prior iteration of this loop, if any
+ .buildRequest()
+ .authorize();
+ AuthzAuditEvent auditEvent = auditHandler.getAndDiscardMostRecentEvent(); // capture it only for success
+ if (session.isAuthorized()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("evaluateAccess: has family level access [" + family + "]");
+ }
+ // we need to do 3 things: housekeeping, decide about audit events, building the results cache for filter
+ somethingIsAccessible = true;
+ familesAccessAllowed.add(family);
+ if (auditEvent != null) {
+ LOG.debug("evaluateAccess: adding to family-level-access-granted-event-set");
+ familyLevelAccessEvents.add(auditEvent);
+ }
+ } else {
+ everythingIsAccessible = false;
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("evaluateAccess: no family level access [" + family + "]. Checking if has partial access (of any type)...");
+ }
+
+ session.resourceMatchingScope(RangerAccessRequest.ResourceMatchingScope.SELF_OR_DESCENDANTS)
+ .buildRequest()
+ .authorize();
+ auditEvent = auditHandler.getAndDiscardMostRecentEvent(); // capture it only for failure
+ if (session.isAuthorized()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("evaluateAccess: has partial access (of some type) in family [" + family + "]");
+ }
+ // we need to do 3 things: housekeeping, decide about audit events, building the results cache for filter
+ somethingIsAccessible = true;
+ familesAccessIndeterminate.add(family);
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("evaluateAccess: has no access of ["+ access + "] type in family [" + family + "]");
+ }
+ familesAccessDenied.add(family);
+ denialReason = String.format("Insufficient permissions for user ‘%s',action: %s, tableName:%s, family:%s.", user.getName(), operation, table, family);
+ if (auditEvent != null && deniedEvent == null) { // we need to capture just one denial event
+ LOG.debug("evaluateAccess: Setting denied access audit event with last auth failure audit event.");
+ deniedEvent = auditEvent;
+ }
+ }
+ // Restore the headMatch setting
+ session.resourceMatchingScope(RangerAccessRequest.ResourceMatchingScope.SELF);
+ }
+ } else {
+ LOG.debug("evaluateAccess: columns collection not empty. Skipping Family level check, will do finer level access check.");
+ Set<String> accessibleColumns = new HashSet<String>(); // will be used in to populate our results cache for the filter
+ for (String column : columns) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("evaluateAccess: Processing column: " + column);
+ }
+ session.column(column)
+ .buildRequest()
+ .authorize();
+ AuthzAuditEvent auditEvent = auditHandler.getAndDiscardMostRecentEvent();
+ if (session.isAuthorized()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("evaluateAccess: has column level access [" + family + ", " + column + "]");
+ }
+ // we need to do 3 things: housekeeping, capturing audit events, building the results cache for filter
+ somethingIsAccessible = true;
+ accessibleColumns.add(column);
+ if (auditEvent != null) {
+ LOG.debug("evaluateAccess: adding to access-granted-audit-event-set");
+ authorizedEvents.add(auditEvent);
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("evaluateAccess: no column level access [" + family + ", " + column + "]");
+ }
+ everythingIsAccessible = false;
+ denialReason = String.format("Insufficient permissions for user ‘%s',action: %s, tableName:%s, family:%s, column: %s", user.getName(), operation, table, family, column);
+ if (auditEvent != null && deniedEvent == null) { // we need to capture just one denial event
+ LOG.debug("evaluateAccess: Setting denied access audit event with last auth failure audit event.");
+ deniedEvent = auditEvent;
+ }
+ }
+ if (!accessibleColumns.isEmpty()) {
+ columnsAccessAllowed.put(family, accessibleColumns);
+ }
+ }
+ }
+ }
+ // Cache of auth results are encapsulated the in the filter. Not every caller of the function uses it - only preGet and preOpt will.
+ RangerAuthorizationFilter filter = new RangerAuthorizationFilter(session, familesAccessAllowed, familesAccessDenied, familesAccessIndeterminate, columnsAccessAllowed);
+ result = new ColumnFamilyAccessResult(everythingIsAccessible, somethingIsAccessible, authorizedEvents, familyLevelAccessEvents, deniedEvent, denialReason, filter);
+ if (LOG.isDebugEnabled()) {
+ String message = String.format(messageTemplate, userName, operation, access, families.toString(), result.toString());
+ LOG.debug(message);
+ }
+ return result;
+ }
+
+ Filter authorizeAccess(String operation, Action action, final RegionCoprocessorEnvironment env, final Map<byte[], NavigableSet<byte[]>> familyMap) throws AccessDeniedException {
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("==> authorizeAccess");
+ }
+ try {
+ ColumnFamilyAccessResult accessResult = evaluateAccess(operation, action, env, familyMap);
+ RangerDefaultAuditHandler auditHandler = new RangerDefaultAuditHandler();
+ if (accessResult._everythingIsAccessible) {
+ auditHandler.logAuthzAudits(accessResult._accessAllowedEvents);
+ auditHandler.logAuthzAudits(accessResult._familyLevelAccessEvents);
+ LOG.debug("authorizeAccess: exiting: No filter returned since all access was allowed");
+ return null; // no filter needed since we are good to go.
+ } else if (accessResult._somethingIsAccessible) {
+ // NOTE: audit logging is split beween logging here (in scope of preOp/preGet) and logging in the filter component for those that couldn't be determined
+ auditHandler.logAuthzAudits(accessResult._accessAllowedEvents);
+ LOG.debug("authorizeAccess: exiting: Filter returned since some access was allowed");
+ return accessResult._filter;
+ } else {
+ // If we are here then it means nothing was accessible! So let's log one denial (in our case, the last denial) and throw an exception
+ auditHandler.logAuthzAudit(accessResult._accessDeniedEvent);
+ LOG.debug("authorizeAccess: exiting: Throwing exception since nothing was accessible");
+ throw new AccessDeniedException(accessResult._denialReason);
+ }
+ } finally {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("<== authorizeAccess");
+ }
+ }
+ }
+
+ Filter combineFilters(Filter filter, Filter existingFilter) {
+ Filter combinedFilter = filter;
+ if (existingFilter != null) {
+ combinedFilter = new FilterList(FilterList.Operator.MUST_PASS_ALL, Lists.newArrayList(filter, existingFilter));
+ }
+ return combinedFilter;
+ }
+
+ void requirePermission(final String operation, final Action action, final RegionCoprocessorEnvironment regionServerEnv, final Map<byte[], ? extends Collection<?>> familyMap)
+ throws AccessDeniedException {
+
+ ColumnFamilyAccessResult accessResult = evaluateAccess(operation, action, regionServerEnv, familyMap);
+ RangerDefaultAuditHandler auditHandler = new RangerDefaultAuditHandler();
+ if (accessResult._everythingIsAccessible) {
+ auditHandler.logAuthzAudits(accessResult._accessAllowedEvents);
+ auditHandler.logAuthzAudits(accessResult._familyLevelAccessEvents);
+ LOG.debug("requirePermission: exiting: all access was allowed");
+ return;
+ } else {
+ auditHandler.logAuthzAudit(accessResult._accessDeniedEvent);
+ LOG.debug("requirePermission: exiting: throwing exception as everything wasn't accessible");
+ throw new AccessDeniedException(accessResult._denialReason);
+ }
+ }
+
+ /**
+ * This could run s
+ * @param operation
+ * @param otherInformation
+ * @param table
+ * @param columnFamily
+ * @param column
+ * @return
+ * @throws AccessDeniedException
+ */
+ void authorizeAccess(String operation, String otherInformation, Action action, String table, String columnFamily, String column) throws AccessDeniedException {
+
+ String access = _authUtils.getAccess(action);
+ if (LOG.isDebugEnabled()) {
+ final String format = "authorizeAccess: %s: Operation[%s], Info[%s], access[%s], table[%s], columnFamily[%s], column[%s]";
+ String message = String.format(format, "Entering", operation, otherInformation, access, table, columnFamily, column);
+ LOG.debug(message);
+ }
+
+ final String format = "authorizeAccess: %s: Operation[%s], Info[%s], access[%s], table[%s], columnFamily[%s], column[%s], allowed[%s], reason[%s]";
+ if (canSkipAccessCheck(operation, access, table)) {
+ if (LOG.isDebugEnabled()) {
+ String message = String.format(format, "Exiting", operation, otherInformation, access, table, columnFamily, column, true, "can skip auth check");
+ LOG.debug(message);
+ }
+ return;
+ }
+ User user = getActiveUser();
+
+ HbaseAuditHandler auditHandler = _factory.getAuditHandler();
+ AuthorizationSession session = new AuthorizationSession(hbasePlugin)
+ .operation(operation)
+ .otherInformation(otherInformation)
+ .remoteAddress(getRemoteAddress())
+ .auditHandler(auditHandler)
+ .user(user)
+ .access(access)
+ .table(table)
+ .columnFamily(columnFamily)
+ .column(column)
+ .buildRequest()
+ .authorize();
+
+ if (LOG.isDebugEnabled()) {
+ boolean allowed = session.isAuthorized();
+ String reason = session.getDenialReason();
+ String message = String.format(format, "Exiting", operation, otherInformation, access, table, columnFamily, column, allowed, reason);
+ LOG.debug(message);
+ }
+
+ session.publishResults();
+ }
+
+ boolean canSkipAccessCheck(final String operation, String access, final String table)
+ throws AccessDeniedException {
+
+ User user = getActiveUser();
+ boolean result = false;
+ if (user == null) {
+ String message = "Unexpeceted: User is null: access denied, not audited!";
+ LOG.warn("canSkipAccessCheck: exiting" + message);
+ throw new AccessDeniedException("No user associated with request (" + operation + ") for action: " + access + "on table:" + table);
+ } else if (isAccessForMetadataRead(access, table)) {
+ LOG.debug("canSkipAccessCheck: true: metadata read access always allowed, not audited");
+ result = true;
+ } else {
+ LOG.debug("Can't skip access checks");
+ }
+
+ return result;
+ }
+
+ boolean canSkipAccessCheck(final String operation, String access, final RegionCoprocessorEnvironment regionServerEnv) throws AccessDeniedException {
+
+ User user = getActiveUser();
+ // read access to metadata tables is always allowed and isn't audited.
+ if (isAccessForMetaTables(regionServerEnv) && _authUtils.isReadAccess(access)) {
+ LOG.debug("isKnownAccessPattern: exiting: Read access for metadata tables allowed, not audited!");
+ return true;
+ }
+ // if write access is desired to metatables then global create access is sufficient
+ if (_authUtils.isWriteAccess(access) && isAccessForMetaTables(regionServerEnv)) {
+ String createAccess = _authUtils.getAccess(Action.CREATE);
+ AuthorizationSession session = new AuthorizationSession(hbasePlugin)
+ .operation(operation)
+ .remoteAddress(getRemoteAddress())
+ .user(user)
+ .access(createAccess)
+ .buildRequest()
+ .authorize();
+ if (session.isAuthorized()) {
+ // NOTE: this access isn't logged
+ LOG.debug("isKnownAccessPattern: exiting: User has global create access, allowed!");
+ return true;
+ }
+ }
+ return false;
+ }
+
+ boolean isAccessForMetadataRead(String access, String table) {
+ if (_authUtils.isReadAccess(access) && isSpecialTable(table)) {
+ LOG.debug("isAccessForMetadataRead: Metadata tables read: access allowed!");
+ return true;
+ }
+ return false;
+ }
+
+ // Check if the user has global permission ...
+ protected void requireGlobalPermission(String request, String objName, Permission.Action action) throws AccessDeniedException {
+ authorizeAccess(request, objName, action, null, null, null);
+ }
+
+ protected void requirePermission(String request, byte[] tableName, Permission.Action action) throws AccessDeniedException {
+ String table = Bytes.toString(tableName);
+
+ authorizeAccess(request, null, action, table, null, null);
+ }
+
+ protected void requirePermission(String request, byte[] aTableName, byte[] aColumnFamily, byte[] aQualifier, Permission.Action action) throws AccessDeniedException {
+
+ String table = Bytes.toString(aTableName);
+ String columnFamily = Bytes.toString(aColumnFamily);
+ String column = Bytes.toString(aQualifier);
+
+ authorizeAccess(request, null, action, table, columnFamily, column);
+ }
+
+ protected void requirePermission(String request, Permission.Action perm, RegionCoprocessorEnvironment env, Collection<byte[]> families) throws IOException {
+ HashMap<byte[], Set<byte[]>> familyMap = new HashMap<byte[], Set<byte[]>>();
+
+ if(families != null) {
+ for (byte[] family : families) {
+ familyMap.put(family, null);
+ }
+ }
+ requirePermission(request, perm, env, familyMap);
+ }
+
+ @Override
+ public void postScannerClose(ObserverContext<RegionCoprocessorEnvironment> c, InternalScanner s) throws IOException {
+ scannerOwners.remove(s);
+ }
+ @Override
+ public RegionScanner postScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c, Scan scan, RegionScanner s) throws IOException {
+ User user = getActiveUser();
+ if (user != null && user.getShortName() != null) {
+ scannerOwners.put(s, user.getShortName());
+ }
+ return s;
+ }
+
+ @Override
+ public void postStartMaster(ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException {
+ //if(UpdateRangerPoliciesOnGrantRevoke) {
+ //AccessControlLists.createACLTable(ctx.getEnvironment().getMasterServices());
+ //RangerAccessControlLists.init(ctx.getEnvironment().getMasterServices());
+ //}
+ }
+
+ @Override
+ public void preAddColumn(ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName, HColumnDescriptor column) throws IOException {
+ requirePermission("addColumn", tableName.getName(), null, null, Action.CREATE);
+ }
+ @Override
+ public Result preAppend(ObserverContext<RegionCoprocessorEnvironment> c, Append append) throws IOException {
+ requirePermission("append", TablePermission.Action.WRITE, c.getEnvironment(), append.getFamilyCellMap());
+ return null;
+ }
+ @Override
+ public void preAssign(ObserverContext<MasterCoprocessorEnvironment> c, HRegionInfo regionInfo) throws IOException {
+ requirePermission("assign", regionInfo.getTable().getName(), null, null, Action.ADMIN);
+ }
+ @Override
+ public void preBalance(ObserverContext<MasterCoprocessorEnvironment> c) throws IOException {
+ requirePermission("balance", null, Permission.Action.ADMIN);
+ }
+ @Override
+ public boolean preBalanceSwitch(ObserverContext<MasterCoprocessorEnvironment> c, boolean newValue) throws IOException {
+ requirePermission("balanceSwitch", null, Permission.Action.ADMIN);
+ return newValue;
+ }
+ @Override
+ public void preBulkLoadHFile(ObserverContext<RegionCoprocessorEnvironment> ctx, List<Pair<byte[], String>> familyPaths) throws IOException {
+ List<byte[]> cfs = new LinkedList<byte[]>();
+ for (Pair<byte[], String> el : familyPaths) {
+ cfs.add(el.getFirst());
+ }
+ requirePermission("bulkLoadHFile", Permission.Action.WRITE, ctx.getEnvironment(), cfs);
+ }
+ @Override
+ public boolean preCheckAndDelete(ObserverContext<RegionCoprocessorEnvironment> c, byte[] row, byte[] family, byte[] qualifier, CompareOp compareOp, ByteArrayComparable comparator, Delete delete, boolean result) throws IOException {
+ Collection<byte[]> familyMap = Arrays.asList(new byte[][] { family });
+ requirePermission("checkAndDelete", TablePermission.Action.READ, c.getEnvironment(), familyMap);
+ requirePermission("checkAndDelete", TablePermission.Action.WRITE, c.getEnvironment(), familyMap);
+ return result;
+ }
+ @Override
+ public boolean preCheckAndPut(ObserverContext<RegionCoprocessorEnvironment> c, byte[] row, byte[] family, byte[] qualifier, CompareOp compareOp, ByteArrayComparable comparator, Put put, boolean result) throws IOException {
+ Collection<byte[]> familyMap = Arrays.asList(new byte[][] { family });
+ requirePermission("checkAndPut", TablePermission.Action.READ, c.getEnvironment(), familyMap);
+ requirePermission("checkAndPut", TablePermission.Action.WRITE, c.getEnvironment(), familyMap);
+ return result;
+ }
+ @Override
+ public void preCloneSnapshot(ObserverContext<MasterCoprocessorEnvironment> ctx, SnapshotDescription snapshot, HTableDescriptor hTableDescriptor) throws IOException {
+ requirePermission("cloneSnapshot", null, Permission.Action.ADMIN);
+ }
+ @Override
+ public void preClose(ObserverContext<RegionCoprocessorEnvironment> e, boolean abortRequested) throws IOException {
+ requirePermission("close", getTableName(e.getEnvironment()), Permission.Action.ADMIN);
+ }
+ @Override
+ public InternalScanner preCompact(ObserverContext<RegionCoprocessorEnvironment> e, Store store, InternalScanner scanner,ScanType scanType) throws IOException {
+ requirePermission("compact", getTableName(e.getEnvironment()), null, null, Action.CREATE);
+ return scanner;
+ }
+ @Override
+ public void preCompactSelection(ObserverContext<RegionCoprocessorEnvironment> e, Store store, List<StoreFile> candidates) throws IOException {
+ requirePermission("compactSelection", getTableName(e.getEnvironment()), null, null, Action.CREATE);
+ }
+
+ @Override
+ public void preCreateTable(ObserverContext<MasterCoprocessorEnvironment> c, HTableDescriptor desc, HRegionInfo[] regions) throws IOException {
+ requirePermission("createTable", desc.getName(), Permission.Action.CREATE);
+ }
+ @Override
+ public void preDelete(ObserverContext<RegionCoprocessorEnvironment> c, Delete delete, WALEdit edit, Durability durability) throws IOException {
+ requirePermission("delete", TablePermission.Action.WRITE, c.getEnvironment(), delete.getFamilyCellMap());
+ }
+ @Override
+ public void preDeleteColumn(ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName, byte[] col) throws IOException {
+ requirePermission("deleteColumn", tableName.getName(), null, null, Action.CREATE);
+ }
+ @Override
+ public void preDeleteSnapshot(ObserverContext<MasterCoprocessorEnvironment> ctx, SnapshotDescription snapshot) throws IOException {
+ requirePermission("deleteSnapshot", null, Permission.Action.ADMIN);
+ }
+ @Override
+ public void preDeleteTable(ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName) throws IOException {
+ requirePermission("deleteTable", tableName.getName(), null, null, Action.CREATE);
+ }
+ @Override
+ public void preDisableTable(ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName) throws IOException {
+ requirePermission("disableTable", tableName.getName(), null, null, Action.CREATE);
+ }
+ @Override
+ public void preEnableTable(ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName) throws IOException {
+ requirePermission("enableTable", tableName.getName(), null, null, Action.CREATE);
+ }
+ @Override
+ public boolean preExists(ObserverContext<RegionCoprocessorEnvironment> c, Get get, boolean exists) throws IOException {
+ requirePermission("exists", TablePermission.Action.READ, c.getEnvironment(), get.familySet());
+ return exists;
+ }
+ @Override
+ public void preFlush(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
+ requirePermission("flush", getTableName(e.getEnvironment()), null, null, Action.CREATE);
+ }
+ @Override
+ public void preGetClosestRowBefore(ObserverContext<RegionCoprocessorEnvironment> c, byte[] row, byte[] family, Result result) throws IOException {
+ requirePermission("getClosestRowBefore", TablePermission.Action.READ, c.getEnvironment(), (family != null ? Lists.newArrayList(family) : null));
+ }
+ @Override
+ public Result preIncrement(ObserverContext<RegionCoprocessorEnvironment> c, Increment increment) throws IOException {
+ requirePermission("increment", TablePermission.Action.WRITE, c.getEnvironment(), increment.getFamilyCellMap().keySet());
+
+ return null;
+ }
+ @Override
+ public long preIncrementColumnValue(ObserverContext<RegionCoprocessorEnvironment> c, byte[] row, byte[] family, byte[] qualifier, long amount, boolean writeToWAL) throws IOException {
+ requirePermission("incrementColumnValue", TablePermission.Action.READ, c.getEnvironment(), Arrays.asList(new byte[][] { family }));
+ requirePermission("incrementColumnValue", TablePermission.Action.WRITE, c.getEnvironment(), Arrays.asList(new byte[][] { family }));
+ return -1;
+ }
+ @Override
+ public void preModifyColumn(ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName, HColumnDescriptor descriptor) throws IOException {
+ requirePermission("modifyColumn", tableName.getName(), null, null, Action.CREATE);
+ }
+ @Override
+ public void preModifyTable(ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName, HTableDescriptor htd) throws IOException {
+ requirePermission("modifyTable", tableName.getName(), null, null, Action.CREATE);
+ }
+ @Override
+ public void preMove(ObserverContext<MasterCoprocessorEnvironment> c, HRegionInfo region, ServerName srcServer, ServerName destServer) throws IOException {
+ requirePermission("move", region.getTable().getName() , null, null, Action.ADMIN);
+ }
+ @Override
+ public void preOpen(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
+ RegionCoprocessorEnvironment env = e.getEnvironment();
+ final Region region = env.getRegion();
+ if (region == null) {
+ LOG.error("NULL region from RegionCoprocessorEnvironment in preOpen()");
+ } else {
+ HRegionInfo regionInfo = region.getRegionInfo();
+ if (isSpecialTable(regionInfo)) {
+ requireSystemOrSuperUser(regionEnv.getConfiguration());
+ } else {
+ requirePermission("open", getTableName(e.getEnvironment()), Action.ADMIN);
+ }
+ }
+ }
+ @Override
+ public void preRestoreSnapshot(ObserverContext<MasterCoprocessorEnvironment> ctx, SnapshotDescription snapshot, HTableDescriptor hTableDescriptor) throws IOException {
+ requirePermission("restoreSnapshot", hTableDescriptor.getName(), Permission.Action.ADMIN);
+ }
+
+ @Override
+ public void preScannerClose(ObserverContext<RegionCoprocessorEnvironment> c, InternalScanner s) throws IOException {
+ requireScannerOwner(s);
+ }
+ @Override
+ public boolean preScannerNext(ObserverContext<RegionCoprocessorEnvironment> c, InternalScanner s, List<Result> result, int limit, boolean hasNext) throws IOException {
+ requireScannerOwner(s);
+ return hasNext;
+ }
+ @Override
+ public RegionScanner preScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c, Scan scan, RegionScanner s) throws IOException {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("==> preScannerOpen");
+ }
+
+ try {
+ RegionCoprocessorEnvironment e = c.getEnvironment();
+
+ Map<byte[], NavigableSet<byte[]>> familyMap = scan.getFamilyMap();
+ String operation = "scannerOpen";
+ Filter filter = authorizeAccess(operation, Action.READ, e, familyMap);
+ if (filter == null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("preScannerOpen: Access allowed for all families/column. No filter added");
+ }
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("preScannerOpen: Access allowed for some of the families/column. New filter added.");
+ }
+ Filter existingFilter = scan.getFilter();
+ Filter combinedFilter = combineFilters(filter, existingFilter);
+ scan.setFilter(combinedFilter);
+ }
+ return s;
+ } finally {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("<== preScannerOpen");
+ }
+ }
+ }
+ @Override
+ public void preShutdown(ObserverContext<MasterCoprocessorEnvironment> c) throws IOException {
+ requirePermission("shutdown", null, Permission.Action.ADMIN);
+ }
+ @Override
+ public void preSnapshot(ObserverContext<MasterCoprocessorEnvironment> ctx, SnapshotDescription snapshot, HTableDescriptor hTableDescriptor) throws IOException {
+ requirePermission("snapshot", hTableDescriptor.getName(), Permission.Action.ADMIN);
+ }
+ @Override
+ public void preSplit(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
+ requirePermission("split", getTableName(e.getEnvironment()), null, null, Action.ADMIN);
+ }
+ @Override
+ public void preStopMaster(ObserverContext<MasterCoprocessorEnvironment> c) throws IOException {
+ requirePermission("stopMaster", null, Permission.Action.ADMIN);
+ }
+ @Override
+ public void preStopRegionServer(ObserverContext<RegionServerCoprocessorEnvironment> env) throws IOException {
+ requirePermission("stop", null, Permission.Action.ADMIN);
+ }
+ @Override
+ public void preUnassign(ObserverContext<MasterCoprocessorEnvironment> c, HRegionInfo regionInfo, boolean force) throws IOException {
+ requirePermission("unassign", regionInfo.getTable().getName(), null, null, Action.ADMIN);
+ }
+
+ @Override
+ public void preSetUserQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
+ final String userName, final Quotas quotas) throws IOException {
+ requireGlobalPermission("setUserQuota", null, Action.ADMIN);
+ }
+
+ @Override
+ public void preSetUserQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
+ final String userName, final TableName tableName, final Quotas quotas) throws IOException {
+ requirePermission("setUserTableQuota", tableName.getName(), null, null, Action.ADMIN);
+ }
+
+ @Override
+ public void preSetUserQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
+ final String userName, final String namespace, final Quotas quotas) throws IOException {
+ requireGlobalPermission("setUserNamespaceQuota", namespace, Action.ADMIN);
+ }
+
+ @Override
+ public void preSetTableQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
+ final TableName tableName, final Quotas quotas) throws IOException {
+ requirePermission("setTableQuota", tableName.getName(), null, null, Action.ADMIN);
+ }
+
+ @Override
+ public void preSetNamespaceQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
+ final String namespace, final Quotas quotas) throws IOException {
+ requireGlobalPermission("setNamespaceQuota", namespace, Action.ADMIN);
+ }
+
+ private String coprocessorType = "unknown";
+ private static final String MASTER_COPROCESSOR_TYPE = "master";
+ private static final String REGIONAL_COPROCESSOR_TYPE = "regional";
+ private static final String REGIONAL_SERVER_COPROCESSOR_TYPE = "regionalServer";
+
+ @Override
+ public void start(CoprocessorEnvironment env) throws IOException {
+ String appType = "unknown";
+
+ if (env instanceof MasterCoprocessorEnvironment) {
+ coprocessorType = MASTER_COPROCESSOR_TYPE;
+ appType = "hbaseMaster";
+ } else if (env instanceof RegionServerCoprocessorEnvironment) {
+ coprocessorType = REGIONAL_SERVER_COPROCESSOR_TYPE;
+ appType = "hbaseRegional";
+ } else if (env instanceof RegionCoprocessorEnvironment) {
+ regionEnv = (RegionCoprocessorEnvironment) env;
+ coprocessorType = REGIONAL_COPROCESSOR_TYPE;
+ appType = "hbaseRegional";
+ }
+
+ Configuration conf = env.getConfiguration();
+ HbaseFactory.initialize(conf);
+
+ // create and initialize the plugin class
+ RangerHBasePlugin plugin = hbasePlugin;
+
+ if(plugin == null) {
+ synchronized(RangerAuthorizationCoprocessorImpl.class) {
+ plugin = hbasePlugin;
+
+ if(plugin == null) {
+ plugin = new RangerHBasePlugin(appType);
+
+ plugin.init();
+
+ UpdateRangerPoliciesOnGrantRevoke = RangerConfiguration.getInstance().getBoolean(RangerHadoopConstants.HBASE_UPDATE_RANGER_POLICIES_ON_GRANT_REVOKE_PROP, RangerHadoopConstants.HBASE_UPDATE_RANGER_POLICIES_ON_GRANT_REVOKE_DEFAULT_VALUE);
+
+ hbasePlugin = plugin;
+ }
+ }
+ }
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Start of Coprocessor: [" + coprocessorType + "]");
+ }
+ }
+ @Override
+ public void prePut(ObserverContext<RegionCoprocessorEnvironment> c, Put put, WALEdit edit, Durability durability) throws IOException {
+ requirePermission("put", TablePermission.Action.WRITE, c.getEnvironment(), put.getFamilyCellMap());
+ }
+
+ @Override
+ public void preGetOp(final ObserverContext<RegionCoprocessorEnvironment> rEnv, final Get get, final List<Cell> result) throws IOException {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("==> preGetOp");
+ }
+ try {
+ RegionCoprocessorEnvironment e = rEnv.getEnvironment();
+ Map<byte[], NavigableSet<byte[]>> familyMap = get.getFamilyMap();
+
+ String operation = "get";
+ Filter filter = authorizeAccess(operation, Action.READ, e, familyMap);
+ if (filter == null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("preGetOp: all access allowed, no filter returned");
+ }
+ } else {
+ Filter existingFilter = get.getFilter();
+ Filter combinedFilter = combineFilters(filter, existingFilter);
+ get.setFilter(combinedFilter);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("preGetOp: partial access, new filter added");
+ }
+ }
+ } finally {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("<== preGetOp");
+ }
+ }
+ }
+ @Override
+ public void preRegionOffline(ObserverContext<MasterCoprocessorEnvironment> c, HRegionInfo regionInfo) throws IOException {
+ requirePermission("regionOffline", regionInfo.getTable().getName(), null, null, Action.ADMIN);
+ }
+ @Override
+ public void preCreateNamespace(ObserverContext<MasterCoprocessorEnvironment> ctx, NamespaceDescriptor ns) throws IOException {
+ requireGlobalPermission("createNamespace", ns.getName(), Action.ADMIN);
+ }
+ @Override
+ public void preDeleteNamespace(ObserverContext<MasterCoprocessorEnvironment> ctx, String namespace) throws IOException {
+ requireGlobalPermission("deleteNamespace", namespace, Action.ADMIN);
+ }
+ @Override
+ public void preModifyNamespace(ObserverContext<MasterCoprocessorEnvironment> ctx, NamespaceDescriptor ns) throws IOException {
+ requireGlobalPermission("modifyNamespace", ns.getName(), Action.ADMIN);
+ }
+
+ @Override
+ public void postGetTableDescriptors(ObserverContext<MasterCoprocessorEnvironment> ctx, List<TableName> tableNamesList, List<HTableDescriptor> descriptors, String regex) throws IOException {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(String.format("==> postGetTableDescriptors(count(tableNamesList)=%s, count(descriptors)=%s, regex=%s)", tableNamesList == null ? 0 : tableNamesList.size(),
+ descriptors == null ? 0 : descriptors.size(), regex));
+ }
+
+ if (CollectionUtils.isNotEmpty(descriptors)) {
+ // Retains only those which passes authorization checks
+ User user = getActiveUser();
+ String access = _authUtils.getAccess(Action.CREATE);
+ HbaseAuditHandler auditHandler = _factory.getAuditHandler(); // this will accumulate audits for all tables that succeed.
+ AuthorizationSession session = new AuthorizationSession(hbasePlugin)
+ .operation("getTableDescriptors")
+ .otherInformation("regex=" + regex)
+ .remoteAddress(getRemoteAddress())
+ .auditHandler(auditHandler)
+ .user(user)
+ .access(access);
+
+ Iterator<HTableDescriptor> itr = descriptors.iterator();
+ while (itr.hasNext()) {
+ HTableDescriptor htd = itr.next();
+ String tableName = htd.getTableName().getNameAsString();
+ session.table(tableName).buildRequest().authorize();
+ if (!session.isAuthorized()) {
+ itr.remove();
+ auditHandler.getAndDiscardMostRecentEvent();
+ }
+ }
+ if (descriptors.size() > 0) {
+ session.logCapturedEvents();
+ }
+ }
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(String.format("<== postGetTableDescriptors(count(tableNamesList)=%s, count(descriptors)=%s, regex=%s)", tableNamesList == null ? 0 : tableNamesList.size(),
+ descriptors == null ? 0 : descriptors.size(), regex));
+ }
+ }
+
+ @Override
+ public void preMerge(ObserverContext<RegionServerCoprocessorEnvironment> ctx, Region regionA, Region regionB) throws IOException {
+ requirePermission("mergeRegions", regionA.getTableDesc().getTableName().getName(), null, null, Action.ADMIN);
+ }
+
+ public void prePrepareBulkLoad(ObserverContext<RegionCoprocessorEnvironment> ctx, PrepareBulkLoadRequest request) throws IOException {
+ List<byte[]> cfs = null;
+
+ requirePermission("prePrepareBulkLoad", Permission.Action.WRITE, ctx.getEnvironment(), cfs);
+ }
+
+ public void preCleanupBulkLoad(ObserverContext<RegionCoprocessorEnvironment> ctx, CleanupBulkLoadRequest request) throws IOException {
+ List<byte[]> cfs = null;
+
+ requirePermission("preCleanupBulkLoad", Permission.Action.WRITE, ctx.getEnvironment(), cfs);
+ }
+
+ public static Date getUTCDate() {
+ Calendar local=Calendar.getInstance();
+ int offset = local.getTimeZone().getOffset(local.getTimeInMillis());
+ GregorianCalendar utc = new GregorianCalendar(gmtTimeZone);
+ utc.setTimeInMillis(local.getTimeInMillis());
+ utc.add(Calendar.MILLISECOND, -offset);
+ return utc.getTime();
+ }
+
+ @Override
+ public void grant(RpcController controller, AccessControlProtos.GrantRequest request, RpcCallback<AccessControlProtos.GrantResponse> done) {
+ boolean isSuccess = false;
+
+ if(UpdateRangerPoliciesOnGrantRevoke) {
+ GrantRevokeRequest grData = null;
+
+ try {
+ grData = createGrantData(request);
+
+ RangerHBasePlugin plugin = hbasePlugin;
+
+ if(plugin != null) {
+ RangerAccessResultProcessor auditHandler = new RangerDefaultAuditHandler();
+
+ plugin.grantAccess(grData, auditHandler);
+
+ isSuccess = true;
+ }
+ } catch(AccessControlException excp) {
+ LOG.warn("grant() failed", excp);
+
+ ResponseConverter.setControllerException(controller, new AccessDeniedException(excp));
+ } catch(IOException excp) {
+ LOG.warn("grant() failed", excp);
+
+ ResponseConverter.setControllerException(controller, excp);
+ } catch (Exception excp) {
+ LOG.warn("grant() failed", excp);
+
+ ResponseConverter.setControllerException(controller, new CoprocessorException(excp.getMessage()));
+ }
+ }
+
+ AccessControlProtos.GrantResponse response = isSuccess ? AccessControlProtos.GrantResponse.getDefaultInstance() : null;
+
+ done.run(response);
+ }
+
+ @Override
+ public void revoke(RpcController controller, AccessControlProtos.RevokeRequest request, RpcCallback<AccessControlProtos.RevokeResponse> done) {
+ boolean isSuccess = false;
+
+ if(UpdateRangerPoliciesOnGrantRevoke) {
+ GrantRevokeRequest grData = null;
+
+ try {
+ grData = createRevokeData(request);
+
+ RangerHBasePlugin plugin = hbasePlugin;
+
+ if(plugin != null) {
+ RangerAccessResultProcessor auditHandler = new RangerDefaultAuditHandler();
+
+ plugin.revokeAccess(grData, auditHandler);
+
+ isSuccess = true;
+ }
+ } catch(AccessControlException excp) {
+ LOG.warn("revoke() failed", excp);
+
+ ResponseConverter.setControllerException(controller, new AccessDeniedException(excp));
+ } catch(IOException excp) {
+ LOG.warn("revoke() failed", excp);
+
+ ResponseConverter.setControllerException(controller, excp);
+ } catch (Exception excp) {
+ LOG.warn("revoke() failed", excp);
+
+ ResponseConverter.setControllerException(controller, new CoprocessorException(excp.getMessage()));
+ }
+ }
+
+ AccessControlProtos.RevokeResponse response = isSuccess ? AccessControlProtos.RevokeResponse.getDefaultInstance() : null;
+
+ done.run(response);
+ }
+
+ @Override
+ public void checkPermissions(RpcController controller, AccessControlProtos.CheckPermissionsRequest request, RpcCallback<AccessControlProtos.CheckPermissionsResponse> done) {
+ LOG.debug("checkPermissions(): ");
+ }
+
+ @Override
+ public void getUserPermissions(RpcController controller, AccessControlProtos.GetUserPermissionsRequest request, RpcCallback<AccessControlProtos.GetUserPermissionsResponse> done) {
+ LOG.debug("getUserPermissions(): ");
+ }
+
+ @Override
+ public Service getService() {
+ return AccessControlProtos.AccessControlService.newReflectiveService(this);
+ }
+
+ private GrantRevokeRequest createGrantData(AccessControlProtos.GrantRequest request) throws Exception {
+ org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.UserPermission up = request.getUserPermission();
+ org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.Permission perm = up == null ? null : up.getPermission();
+
+ UserPermission userPerm = up == null ? null : ProtobufUtil.toUserPermission(up);
+ Permission.Action[] actions = userPerm == null ? null : userPerm.getActions();
+ String userName = userPerm == null ? null : Bytes.toString(userPerm.getUser());
+ String nameSpace = null;
+ String tableName = null;
+ String colFamily = null;
+ String qualifier = null;
+
+ if(perm == null) {
+ throw new Exception("grant(): invalid data - permission is null");
+ }
+
+ if(StringUtil.isEmpty(userName)) {
+ throw new Exception("grant(): invalid data - username empty");
+ }
+
+ if ((actions == null) || (actions.length == 0)) {
+ throw new Exception("grant(): invalid data - no action specified");
+ }
+
+ switch(perm.getType()) {
+ case Global:
+ tableName = colFamily = qualifier = WILDCARD;
+ break;
+
+ case Table:
+ tableName = Bytes.toString(userPerm.getTableName().getName());
+ colFamily = Bytes.toString(userPerm.getFamily());
+ qualifier = Bytes.toString(userPerm.getQualifier());
+ break;
+
+ case Namespace:
+ nameSpace = userPerm.getNamespace();
+ break;
+ }
+
+ if(StringUtil.isEmpty(nameSpace) && StringUtil.isEmpty(tableName) && StringUtil.isEmpty(colFamily) && StringUtil.isEmpty(qualifier)) {
+ throw new Exception("grant(): namespace/table/columnFamily/columnQualifier not specified");
+ }
+
+ tableName = StringUtil.isEmpty(tableName) ? WILDCARD : tableName;
+ colFamily = StringUtil.isEmpty(colFamily) ? WILDCARD : colFamily;
+ qualifier = StringUtil.isEmpty(qualifier) ? WILDCARD : qualifier;
+
+ if(! StringUtil.isEmpty(nameSpace)) {
+ tableName = nameSpace + NAMESPACE_SEPARATOR + tableName;
+ }
+
+ User activeUser = getActiveUser();
+ String grantor = activeUser != null ? activeUser.getShortName() : null;
+
+ Map<String, String> mapResource = new HashMap<String, String>();
+ mapResource.put("table", tableName);
+ mapResource.put("column-family", colFamily);
+ mapResource.put("column", qualifier);
+
+ GrantRevokeRequest ret = new GrantRevokeRequest();
+
+ ret.setGrantor(grantor);
+ ret.setDelegateAdmin(Boolean.FALSE);
+ ret.setEnableAudit(Boolean.TRUE);
+ ret.setReplaceExistingPermissions(Boolean.TRUE);
+ ret.setResource(mapResource);
+ ret.setClientIPAddress(getRemoteAddress());
+
+ if(userName.startsWith(GROUP_PREFIX)) {
+ ret.getGroups().add(userName.substring(GROUP_PREFIX.length()));
+ } else {
+ ret.getUsers().add(userName);
+ }
+
+ for (int i = 0; i < actions.length; i++) {
+ switch(actions[i].code()) {
+ case 'R':
+ ret.getAccessTypes().add(HbaseAuthUtils.ACCESS_TYPE_READ);
+ break;
+
+ case 'W':
+ ret.getAccessTypes().add(HbaseAuthUtils.ACCESS_TYPE_WRITE);
+ break;
+
+ case 'C':
+ ret.getAccessTypes().add(HbaseAuthUtils.ACCESS_TYPE_CREATE);
+ break;
+
+ case 'A':
+ ret.getAccessTypes().add(HbaseAuthUtils.ACCESS_TYPE_ADMIN);
+ ret.setDelegateAdmin(Boolean.TRUE);
+ break;
+
+ default:
+ LOG.warn("grant(): ignoring action '" + actions[i].name() + "' for user '" + userName + "'");
+ }
+ }
+
+ return ret;
+ }
+
+ private GrantRevokeRequest createRevokeData(AccessControlProtos.RevokeRequest request) throws Exception {
+ org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.UserPermission up = request.getUserPermission();
+ org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.Permission perm = up == null ? null : up.getPermission();
+
+ UserPermission userPerm = up == null ? null : ProtobufUtil.toUserPermission(up);
+ String userName = userPerm == null ? null : Bytes.toString(userPerm.getUser());
+ String nameSpace = null;
+ String tableName = null;
+ String colFamily = null;
+ String qualifier = null;
+
+ if(perm == null) {
+ throw new Exception("revoke(): invalid data - permission is null");
+ }
+
+ if(StringUtil.isEmpty(userName)) {
+ throw new Exception("revoke(): invalid data - username empty");
+ }
+
+ switch(perm.getType()) {
+ case Global :
+ tableName = colFamily = qualifier = WILDCARD;
+ break;
+
+ case Table :
+ tableName = Bytes.toString(userPerm.getTableName().getName());
+ colFamily = Bytes.toString(userPerm.getFamily());
+ qualifier = Bytes.toString(userPerm.getQualifier());
+ break;
+
+ case Namespace:
+ nameSpace = userPerm.getNamespace();
+ break;
+ }
+
+ if(StringUtil.isEmpty(nameSpace) && StringUtil.isEmpty(tableName) && StringUtil.isEmpty(colFamily) && StringUtil.isEmpty(qualifier)) {
+ throw new Exception("revoke(): table/columnFamily/columnQualifier not specified");
+ }
+
+ tableName = StringUtil.isEmpty(tableName) ? WILDCARD : tableName;
+ colFamily = StringUtil.isEmpty(colFamily) ? WILDCARD : colFamily;
+ qualifier = StringUtil.isEmpty(qualifier) ? WILDCARD : qualifier;
+
+ if(! StringUtil.isEmpty(nameSpace)) {
+ tableName = nameSpace + NAMESPACE_SEPARATOR + tableName;
+ }
+
+ User activeUser = getActiveUser();
+ String grantor = activeUser != null ? activeUser.getShortName() : null;
+
+ Map<String, String> mapResource = new HashMap<String, String>();
+ mapResource.put("table", tableName);
+ mapResource.put("column-family", colFamily);
+ mapResource.put("column", qualifier);
+
+ GrantRevokeRequest ret = new GrantRevokeRequest();
+
+ ret.setGrantor(grantor);
+ ret.setDelegateAdmin(Boolean.TRUE); // remove delegateAdmin privilege as well
+ ret.setEnableAudit(Boolean.TRUE);
+ ret.setReplaceExistingPermissions(Boolean.TRUE);
+ ret.setResource(mapResource);
+ ret.setClientIPAddress(getRemoteAddress());
+
+ if(userName.startsWith(GROUP_PREFIX)) {
+ ret.getGroups().add(userName.substring(GROUP_PREFIX.length()));
+ } else {
+ ret.getUsers().add(userName);
+ }
+
+ // revoke removes all permissions
+ ret.getAccessTypes().add(HbaseAuthUtils.ACCESS_TYPE_READ);
+ ret.getAccessTypes().add(HbaseAuthUtils.ACCESS_TYPE_WRITE);
+ ret.getAccessTypes().add(HbaseAuthUtils.ACCESS_TYPE_CREATE);
+ ret.getAccessTypes().add(HbaseAuthUtils.ACCESS_TYPE_ADMIN);
+
+ return ret;
+ }
+}
+
+
+class RangerHBasePlugin extends RangerBasePlugin {
+ public RangerHBasePlugin(String appType) {
+ super("hbase", appType);
+ }
+
+ public void init() {
+ super.init();
+ }
+}
+
+
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/hbase-agent/src/test/java/org/apache/hadoop/hbase/security/access/RangerAccessControlListsTest.java
----------------------------------------------------------------------
diff --git a/hbase-agent/src/test/java/org/apache/hadoop/hbase/security/access/RangerAccessControlListsTest.java b/hbase-agent/src/test/java/org/apache/hadoop/hbase/security/access/RangerAccessControlListsTest.java
index aa66d08..033d29e 100644
--- a/hbase-agent/src/test/java/org/apache/hadoop/hbase/security/access/RangerAccessControlListsTest.java
+++ b/hbase-agent/src/test/java/org/apache/hadoop/hbase/security/access/RangerAccessControlListsTest.java
@@ -45,7 +45,7 @@ public class RangerAccessControlListsTest {
@After
public void tearDown() throws Exception {
}
-
+ /*
@Test
public void testInit() {
IOException exceptionFound = null ;
@@ -57,5 +57,5 @@ public class RangerAccessControlListsTest {
}
Assert.assertFalse("Expected to get a NullPointerExecution after init method Execution - Found [" + exceptionFound + "]", (!(exceptionFound != null && exceptionFound.getCause() instanceof NullPointerException))) ;
}
-
+ */
}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessorTest.java
----------------------------------------------------------------------
diff --git a/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessorTest.java b/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessorTest.java
index 72b86d1..434f9f1 100644
--- a/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessorTest.java
+++ b/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessorTest.java
@@ -31,7 +31,7 @@ public class RangerAuthorizationCoprocessorTest {
@Test
public void test_canBeNewed() {
- RangerAuthorizationCoprocessor _coprocessor = new RangerAuthorizationCoprocessor();
+ RangerAuthorizationCoprocessorImpl _coprocessor = new RangerAuthorizationCoprocessorImpl();
assertNotNull(_coprocessor);
}
@@ -43,7 +43,7 @@ public class RangerAuthorizationCoprocessorTest {
@Test
public void test_getColumnFamilies_firewalling() {
// passing null collection should return back an empty map
- RangerAuthorizationCoprocessor _coprocessor = new RangerAuthorizationCoprocessor();
+ RangerAuthorizationCoprocessorImpl _coprocessor = new RangerAuthorizationCoprocessorImpl();
Map<String, Set<String>> result = _coprocessor.getColumnFamilies(null);
assertNotNull(result);
assertTrue(result.isEmpty());
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/hdfs-agent/conf/ranger-hdfs-security.xml
----------------------------------------------------------------------
diff --git a/hdfs-agent/conf/ranger-hdfs-security.xml b/hdfs-agent/conf/ranger-hdfs-security.xml
index 10409d9..9700a69 100644
--- a/hdfs-agent/conf/ranger-hdfs-security.xml
+++ b/hdfs-agent/conf/ranger-hdfs-security.xml
@@ -64,6 +64,22 @@
Directory where Ranger policies are cached after successful retrieval from the source
</description>
</property>
+
+ <property>
+ <name>ranger.policy.rest.client.connection.timeoutMs</name>
+ <value>120000</value>
+ <description>
+ RangerRestClient Connection Timeout in Milli Seconds
+ </description>
+ </property>
+
+ <property>
+ <name>ranger.policy.rest.client.read.timeoutMs</name>
+ <value>30000</value>
+ <description>
+ RangerRestClient read Timeout in Milli Seconds
+ </description>
+ </property>
<property>
<name>ranger.plugin.hdfs.policy.rest.client.connection.timeoutMs</name>
@@ -114,4 +130,7 @@
rwxrwxrwx permission on the resource) if Ranger Authorization fails.
</description>
</property>
+
+
+
</configuration>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/hdfs-agent/src/main/java/org/apache/ranger/authorization/hadoop/RangerHdfsAuthorizer.java
----------------------------------------------------------------------
diff --git a/hdfs-agent/src/main/java/org/apache/ranger/authorization/hadoop/RangerHdfsAuthorizer.java b/hdfs-agent/src/main/java/org/apache/ranger/authorization/hadoop/RangerHdfsAuthorizer.java
deleted file mode 100644
index fa2155c..0000000
--- a/hdfs-agent/src/main/java/org/apache/ranger/authorization/hadoop/RangerHdfsAuthorizer.java
+++ /dev/null
@@ -1,538 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.ranger.authorization.hadoop;
-
-import static org.apache.ranger.authorization.hadoop.constants.RangerHadoopConstants.EXECUTE_ACCCESS_TYPE;
-import static org.apache.ranger.authorization.hadoop.constants.RangerHadoopConstants.READ_ACCCESS_TYPE;
-import static org.apache.ranger.authorization.hadoop.constants.RangerHadoopConstants.WRITE_ACCCESS_TYPE;
-
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.Stack;
-
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.fs.permission.FsAction;
-import org.apache.hadoop.hdfs.server.namenode.INode;
-import org.apache.hadoop.hdfs.server.namenode.INodeAttributeProvider;
-import org.apache.hadoop.hdfs.server.namenode.INodeAttributes;
-import org.apache.hadoop.hdfs.server.namenode.INodeDirectory;
-import org.apache.hadoop.hdfs.util.ReadOnlyList;
-import org.apache.hadoop.ipc.Server;
-import org.apache.hadoop.security.AccessControlException;
-import org.apache.hadoop.security.UserGroupInformation;
-import org.apache.ranger.audit.model.AuthzAuditEvent;
-import org.apache.ranger.authorization.hadoop.config.RangerConfiguration;
-import org.apache.ranger.authorization.hadoop.constants.RangerHadoopConstants;
-import org.apache.ranger.authorization.hadoop.exceptions.RangerAccessControlException;
-import org.apache.ranger.authorization.utils.StringUtil;
-import org.apache.ranger.plugin.audit.RangerDefaultAuditHandler;
-import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
-import org.apache.ranger.plugin.policyengine.RangerAccessRequestImpl;
-import org.apache.ranger.plugin.policyengine.RangerAccessResource;
-import org.apache.ranger.plugin.policyengine.RangerAccessResourceImpl;
-import org.apache.ranger.plugin.policyengine.RangerAccessResult;
-import org.apache.ranger.plugin.service.RangerBasePlugin;
-
-import com.google.common.collect.Sets;
-
-public class RangerHdfsAuthorizer extends INodeAttributeProvider {
- private static final Log LOG = LogFactory.getLog(RangerHdfsAuthorizer.class);
-
- private RangerHdfsPlugin rangerPlugin = null;
- private Map<FsAction, Set<String>> access2ActionListMapper = new HashMap<FsAction, Set<String>>();
-
- public RangerHdfsAuthorizer() {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerHdfsAuthorizer.RangerHdfsAuthorizer()");
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerHdfsAuthorizer.RangerHdfsAuthorizer()");
- }
- }
-
- public void start() {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerHdfsAuthorizer.start()");
- }
-
- RangerHdfsPlugin plugin = new RangerHdfsPlugin();
- plugin.init();
-
- access2ActionListMapper.put(FsAction.NONE, new HashSet<String>());
- access2ActionListMapper.put(FsAction.ALL, Sets.newHashSet(READ_ACCCESS_TYPE, WRITE_ACCCESS_TYPE, EXECUTE_ACCCESS_TYPE));
- access2ActionListMapper.put(FsAction.READ, Sets.newHashSet(READ_ACCCESS_TYPE));
- access2ActionListMapper.put(FsAction.READ_WRITE, Sets.newHashSet(READ_ACCCESS_TYPE, WRITE_ACCCESS_TYPE));
- access2ActionListMapper.put(FsAction.READ_EXECUTE, Sets.newHashSet(READ_ACCCESS_TYPE, EXECUTE_ACCCESS_TYPE));
- access2ActionListMapper.put(FsAction.WRITE, Sets.newHashSet(WRITE_ACCCESS_TYPE));
- access2ActionListMapper.put(FsAction.WRITE_EXECUTE, Sets.newHashSet(WRITE_ACCCESS_TYPE, EXECUTE_ACCCESS_TYPE));
- access2ActionListMapper.put(FsAction.EXECUTE, Sets.newHashSet(EXECUTE_ACCCESS_TYPE));
-
- rangerPlugin = plugin;
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerHdfsAuthorizer.start()");
- }
- }
-
- public void stop() {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerHdfsAuthorizer.stop()");
- }
-
- RangerHdfsPlugin plugin = rangerPlugin;
- rangerPlugin = null;
-
- if(plugin != null) {
- plugin.cleanup();
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerHdfsAuthorizer.stop()");
- }
- }
-
- @Override
- public INodeAttributes getAttributes(String fullPath, INodeAttributes inode) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerHdfsAuthorizer.getAttributes(" + fullPath + ")");
- }
-
- INodeAttributes ret = inode; // return default attributes
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerHdfsAuthorizer.getAttributes(" + fullPath + "): " + ret);
- }
-
- return ret;
- }
-
- @Override
- public INodeAttributes getAttributes(String[] pathElements, INodeAttributes inode) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerHdfsAuthorizer.getAttributes(pathElementsCount=" + (pathElements == null ? 0 : pathElements.length) + ")");
- }
-
- INodeAttributes ret = inode; // return default attributes
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerHdfsAuthorizer.getAttributes(pathElementsCount=" + (pathElements == null ? 0 : pathElements.length) + "): " + ret);
- }
-
- return ret;
- }
-
- @Override
- public AccessControlEnforcer getExternalAccessControlEnforcer(AccessControlEnforcer defaultEnforcer) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerHdfsAuthorizer.getExternalAccessControlEnforcer()");
- }
-
- RangerAccessControlEnforcer rangerAce = new RangerAccessControlEnforcer(defaultEnforcer);
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerHdfsAuthorizer.getExternalAccessControlEnforcer()");
- }
-
- return rangerAce;
- }
-
-
- class RangerAccessControlEnforcer implements AccessControlEnforcer {
- private INodeAttributeProvider.AccessControlEnforcer defaultEnforcer = null;
-
- public RangerAccessControlEnforcer(AccessControlEnforcer defaultEnforcer) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAccessControlEnforcer.RangerAccessControlEnforcer()");
- }
-
- this.defaultEnforcer = defaultEnforcer;
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAccessControlEnforcer.RangerAccessControlEnforcer()");
- }
- }
-
- @Override
- public void checkPermission(String fsOwner, String superGroup, UserGroupInformation ugi,
- INodeAttributes[] inodeAttrs, INode[] inodes, byte[][] pathByNameArr,
- int snapshotId, String path, int ancestorIndex, boolean doCheckOwner,
- FsAction ancestorAccess, FsAction parentAccess, FsAction access,
- FsAction subAccess, boolean ignoreEmptyDir) throws AccessControlException {
- boolean accessGranted = false;
- RangerHdfsPlugin plugin = rangerPlugin;
- RangerHdfsAuditHandler auditHandler = null;
- String user = ugi != null ? ugi.getShortUserName() : null;
- Set<String> groups = ugi != null ? Sets.newHashSet(ugi.getGroupNames()) : null;
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAccessControlEnforcer.checkPermission("
- + "fsOwner=" + fsOwner + "; superGroup=" + superGroup + ", inodesCount=" + (inodes != null ? inodes.length : 0)
- + ", snapshotId=" + snapshotId + ", user=" + user + ", path=" + path + ", ancestorIndex=" + ancestorIndex
- + ", doCheckOwner="+ doCheckOwner + ", ancestorAccess=" + ancestorAccess + ", parentAccess=" + parentAccess
- + ", access=" + access + ", subAccess=" + subAccess + ", ignoreEmptyDir=" + ignoreEmptyDir + ")");
- }
-
- try {
- if(plugin != null && !ArrayUtils.isEmpty(inodes)) {
- auditHandler = new RangerHdfsAuditHandler(path);
-
- if(ancestorIndex >= inodes.length) {
- ancestorIndex = inodes.length - 1;
- }
-
- for(; ancestorIndex >= 0 && inodes[ancestorIndex] == null; ancestorIndex--);
-
- accessGranted = true;
-
- INode ancestor = inodes.length > ancestorIndex && ancestorIndex >= 0 ? inodes[ancestorIndex] : null;
- INode parent = inodes.length > 1 ? inodes[inodes.length - 2] : null;
- INode inode = inodes[inodes.length - 1];
-
- boolean noAccessToCheck = access == null && parentAccess == null && ancestorAccess == null && subAccess == null;
-
- if(noAccessToCheck) { // check for traverse (EXECUTE) access on the path (if path is a directory) or its parent (if path is a file)
- INode node = null;
- INodeAttributes nodeAttribs = null;
-
- if(inode != null && inode.isDirectory()) {
- node = inode;
- nodeAttribs = inodeAttrs.length > 0 ? inodeAttrs[inodeAttrs.length - 1] : null;
- } else if(parent != null) {
- node = parent;
- nodeAttribs = inodeAttrs.length > 1 ? inodeAttrs[inodeAttrs.length - 2] : null;
- }
-
- if(node != null) {
- accessGranted = isAccessAllowed(node, nodeAttribs, FsAction.EXECUTE, user, groups, fsOwner, superGroup, plugin, null);
- }
- }
-
- // checkStickyBit
- if (accessGranted && parentAccess != null && parentAccess.implies(FsAction.WRITE) && parent != null && inode != null) {
- if (parent.getFsPermission() != null && parent.getFsPermission().getStickyBit()) {
- // user should be owner of the parent or the inode
- accessGranted = StringUtils.equals(parent.getUserName(), user) || StringUtils.equals(inode.getUserName(), user);
- }
- }
-
- // checkAncestorAccess
- if(accessGranted && ancestorAccess != null && ancestor != null) {
- INodeAttributes ancestorAttribs = inodeAttrs.length > ancestorIndex ? inodeAttrs[ancestorIndex] : null;
-
- accessGranted = isAccessAllowed(ancestor, ancestorAttribs, ancestorAccess, user, groups, fsOwner, superGroup, plugin, auditHandler);
- }
-
- // checkParentAccess
- if(accessGranted && parentAccess != null && parent != null) {
- INodeAttributes parentAttribs = inodeAttrs.length > 1 ? inodeAttrs[inodeAttrs.length - 2] : null;
-
- accessGranted = isAccessAllowed(parent, parentAttribs, parentAccess, user, groups, fsOwner, superGroup, plugin, auditHandler);
- }
-
- // checkINodeAccess
- if(accessGranted && access != null && inode != null) {
- INodeAttributes inodeAttribs = inodeAttrs.length > 0 ? inodeAttrs[inodeAttrs.length - 1] : null;
-
- accessGranted = isAccessAllowed(inode, inodeAttribs, access, user, groups, fsOwner, superGroup, plugin, auditHandler);
- }
-
- // checkSubAccess
- if(accessGranted && subAccess != null && inode != null && inode.isDirectory()) {
- Stack<INodeDirectory> directories = new Stack<INodeDirectory>();
-
- for(directories.push(inode.asDirectory()); !directories.isEmpty(); ) {
- INodeDirectory dir = directories.pop();
- ReadOnlyList<INode> cList = dir.getChildrenList(snapshotId);
-
- if (!(cList.isEmpty() && ignoreEmptyDir)) {
- INodeAttributes dirAttribs = dir.getSnapshotINode(snapshotId);
-
- accessGranted = isAccessAllowed(dir, dirAttribs, subAccess, user, groups, fsOwner, superGroup, plugin, auditHandler);
-
- if(! accessGranted) {
- break;
- }
- }
-
- for(INode child : cList) {
- if (child.isDirectory()) {
- directories.push(child.asDirectory());
- }
- }
- }
- }
-
- // checkOwnerAccess
- if(accessGranted && doCheckOwner) {
- INodeAttributes inodeAttribs = inodeAttrs.length > 0 ? inodeAttrs[inodeAttrs.length - 1] : null;
- String owner = inodeAttribs != null ? inodeAttribs.getUserName() : null;
-
- accessGranted = StringUtils.equals(user, owner);
- }
- }
-
- if(! accessGranted && RangerHdfsPlugin.isHadoopAuthEnabled() && defaultEnforcer != null) {
- try {
- defaultEnforcer.checkPermission(fsOwner, superGroup, ugi, inodeAttrs, inodes,
- pathByNameArr, snapshotId, path, ancestorIndex, doCheckOwner,
- ancestorAccess, parentAccess, access, subAccess, ignoreEmptyDir);
-
- accessGranted = true;
- } finally {
- if(auditHandler != null) {
- FsAction action = access;
-
- if(action == null) {
- if(parentAccess != null) {
- action = parentAccess;
- } else if(ancestorAccess != null) {
- action = ancestorAccess;
- } else if(subAccess != null) {
- action = subAccess;
- } else {
- action = FsAction.NONE;
- }
- }
-
- auditHandler.logHadoopEvent(path, action, accessGranted);
- }
- }
- }
-
- if(! accessGranted) {
- throw new RangerAccessControlException("Permission denied: principal{user=" + user + ",groups: " + groups + "}, access=" + access + ", " + path) ;
- }
- } finally {
- if(auditHandler != null) {
- auditHandler.flushAudit();
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAccessControlEnforcer.checkPermission(" + path + ", " + access + ", user=" + user + ") : " + accessGranted);
- }
- }
- }
-
- private boolean isAccessAllowed(INode inode, INodeAttributes inodeAttribs, FsAction access, String user, Set<String> groups, String fsOwner, String superGroup, RangerHdfsPlugin plugin, RangerHdfsAuditHandler auditHandler) {
- boolean ret = false;
- String path = inode != null ? inode.getFullPathName() : null;
- String pathOwner = inodeAttribs != null ? inodeAttribs.getUserName() : null;
-
- if(pathOwner == null && inode != null) {
- pathOwner = inode.getUserName();
- }
-
- if (RangerHadoopConstants.HDFS_ROOT_FOLDER_PATH_ALT.equals(path)) {
- path = RangerHadoopConstants.HDFS_ROOT_FOLDER_PATH;
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerAccessControlEnforcer.isAccessAllowed(" + path + ", " + access + ", " + user + ")");
- }
-
- Set<String> accessTypes = access2ActionListMapper.get(access);
-
- if(accessTypes == null) {
- LOG.warn("RangerAccessControlEnforcer.isAccessAllowed(" + path + ", " + access + ", " + user + "): no Ranger accessType found for " + access);
-
- accessTypes = access2ActionListMapper.get(FsAction.NONE);
- }
-
- for(String accessType : accessTypes) {
- RangerHdfsAccessRequest request = new RangerHdfsAccessRequest(path, pathOwner, access, accessType, user, groups);
-
- RangerAccessResult result = plugin.isAccessAllowed(request, auditHandler);
-
- if (result == null) {
- LOG.error("RangerAccessControlEnforcer: Internal error: null RangerAccessResult object received back from isAccessAllowed()!");
- } else {
- ret = result.getIsAllowed();
-
- if (!ret) {
- break;
- }
- }
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerAccessControlEnforcer.isAccessAllowed(" + path + ", " + access + ", " + user + "): " + ret);
- }
-
- return ret;
- }
- }
-}
-
-
-class RangerHdfsPlugin extends RangerBasePlugin {
- private static boolean hadoopAuthEnabled = RangerHadoopConstants.RANGER_ADD_HDFS_PERMISSION_DEFAULT;
-
- public RangerHdfsPlugin() {
- super("hdfs", "hdfs");
- }
-
- public void init() {
- super.init();
-
- RangerHdfsPlugin.hadoopAuthEnabled = RangerConfiguration.getInstance().getBoolean(RangerHadoopConstants.RANGER_ADD_HDFS_PERMISSION_PROP, RangerHadoopConstants.RANGER_ADD_HDFS_PERMISSION_DEFAULT);
- }
-
- public static boolean isHadoopAuthEnabled() {
- return RangerHdfsPlugin.hadoopAuthEnabled;
- }
-}
-
-class RangerHdfsResource extends RangerAccessResourceImpl {
- private static final String KEY_PATH = "path";
-
-
- public RangerHdfsResource(String path, String owner) {
- super.setValue(KEY_PATH, path);
- super.setOwnerUser(owner);
- }
-}
-
-class RangerHdfsAccessRequest extends RangerAccessRequestImpl {
- public RangerHdfsAccessRequest(String path, String pathOwner, FsAction access, String accessType, String user, Set<String> groups) {
- super.setResource(new RangerHdfsResource(path, pathOwner));
- super.setAccessType(accessType);
- super.setUser(user);
- super.setUserGroups(groups);
- super.setAccessTime(StringUtil.getUTCDate());
- super.setClientIPAddress(getRemoteIp());
- super.setAction(access.toString());
- }
-
- private static String getRemoteIp() {
- String ret = null ;
- InetAddress ip = Server.getRemoteIp() ;
- if (ip != null) {
- ret = ip.getHostAddress();
- }
- return ret ;
- }
-}
-
-class RangerHdfsAuditHandler extends RangerDefaultAuditHandler {
- private static final Log LOG = LogFactory.getLog(RangerHdfsAuditHandler.class);
-
- private boolean isAuditEnabled = false;
- private AuthzAuditEvent auditEvent = null;
-
- private static final String RangerModuleName = RangerConfiguration.getInstance().get(RangerHadoopConstants.AUDITLOG_RANGER_MODULE_ACL_NAME_PROP , RangerHadoopConstants.DEFAULT_RANGER_MODULE_ACL_NAME) ;
- private static final String HadoopModuleName = RangerConfiguration.getInstance().get(RangerHadoopConstants.AUDITLOG_HADOOP_MODULE_ACL_NAME_PROP , RangerHadoopConstants.DEFAULT_HADOOP_MODULE_ACL_NAME) ;
- private static final String excludeUserList = RangerConfiguration.getInstance().get(RangerHadoopConstants.AUDITLOG_HDFS_EXCLUDE_LIST_PROP, RangerHadoopConstants.AUDITLOG_EMPTY_STRING) ;
- private static HashSet<String> excludeUsers = null ;
-
- static {
- if (excludeUserList != null && excludeUserList.trim().length() > 0) {
- excludeUsers = new HashSet<String>() ;
- for(String excludeUser : excludeUserList.trim().split(",")) {
- excludeUser = excludeUser.trim() ;
- if (LOG.isDebugEnabled()) {
- LOG.debug("Adding exclude user [" + excludeUser + "]");
- }
- excludeUsers.add(excludeUser) ;
- }
- }
- }
-
- public RangerHdfsAuditHandler(String pathToBeValidated) {
- auditEvent = new AuthzAuditEvent();
- auditEvent.setResourcePath(pathToBeValidated);
- }
-
- @Override
- public void processResult(RangerAccessResult result) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerHdfsAuditHandler.logAudit(" + result + ")");
- }
-
- if(! isAuditEnabled && result.getIsAudited()) {
- isAuditEnabled = true;
- }
-
- RangerAccessRequest request = result.getAccessRequest();
-// RangerServiceDef serviceDef = result.getServiceDef();
- RangerAccessResource resource = request.getResource();
- String resourceType = resource != null ? resource.getLeafName() : null;
- String resourcePath = resource != null ? resource.getAsString() : null;
-
- auditEvent.setUser(request.getUser());
- auditEvent.setResourceType(resourceType) ;
- auditEvent.setAccessType(request.getAction());
- auditEvent.setAccessResult((short)(result.getIsAllowed() ? 1 : 0));
- auditEvent.setClientIP(request.getClientIPAddress());
- auditEvent.setEventTime(request.getAccessTime());
- auditEvent.setAclEnforcer(RangerModuleName);
- auditEvent.setPolicyId(result.getPolicyId());
- auditEvent.setRepositoryType(result.getServiceType());
- auditEvent.setRepositoryName(result.getServiceName());
- auditEvent.setResultReason(resourcePath);
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerHdfsAuditHandler.logAudit(" + result + "): " + auditEvent);
- }
- }
-
- public void logHadoopEvent(String path, FsAction action, boolean accessGranted) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerHdfsAuditHandler.logHadoopEvent(" + path + ", " + action + ", " + accessGranted + ")");
- }
-
- auditEvent.setResultReason(path);
- auditEvent.setAccessResult((short) (accessGranted ? 1 : 0));
- auditEvent.setAccessType(action == null ? null : action.toString());
- auditEvent.setAclEnforcer(HadoopModuleName);
- auditEvent.setPolicyId(-1);
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerHdfsAuditHandler.logHadoopEvent(" + path + ", " + action + ", " + accessGranted + "): " + auditEvent);
- }
- }
-
- public void flushAudit() {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerHdfsAuditHandler.flushAudit(" + isAuditEnabled + ", " + auditEvent + ")");
- }
-
- if(isAuditEnabled && !StringUtils.isEmpty(auditEvent.getAccessType())) {
- String username = auditEvent.getUser();
-
- boolean skipLog = (username != null && excludeUsers != null && excludeUsers.contains(username)) ;
-
- if (! skipLog) {
- super.logAuthzAudit(auditEvent);
- }
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerHdfsAuditHandler.flushAudit(" + isAuditEnabled + ", " + auditEvent + ")");
- }
- }
-}
-
[4/6] incubator-ranger git commit: RANGER-586: Ranger plugins should
not add dependent libraries to component's CLASSPATH
Posted by rm...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/hdfs-agent/src/main/java/org/apache/ranger/authorization/hadoop/RangerHdfsAuthorizerImpl.java
----------------------------------------------------------------------
diff --git a/hdfs-agent/src/main/java/org/apache/ranger/authorization/hadoop/RangerHdfsAuthorizerImpl.java b/hdfs-agent/src/main/java/org/apache/ranger/authorization/hadoop/RangerHdfsAuthorizerImpl.java
new file mode 100644
index 0000000..9389875
--- /dev/null
+++ b/hdfs-agent/src/main/java/org/apache/ranger/authorization/hadoop/RangerHdfsAuthorizerImpl.java
@@ -0,0 +1,538 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.authorization.hadoop;
+
+import static org.apache.ranger.authorization.hadoop.constants.RangerHadoopConstants.EXECUTE_ACCCESS_TYPE;
+import static org.apache.ranger.authorization.hadoop.constants.RangerHadoopConstants.READ_ACCCESS_TYPE;
+import static org.apache.ranger.authorization.hadoop.constants.RangerHadoopConstants.WRITE_ACCCESS_TYPE;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.fs.permission.FsAction;
+import org.apache.hadoop.hdfs.server.namenode.INode;
+import org.apache.hadoop.hdfs.server.namenode.INodeAttributeProvider;
+import org.apache.hadoop.hdfs.server.namenode.INodeAttributes;
+import org.apache.hadoop.hdfs.server.namenode.INodeDirectory;
+import org.apache.hadoop.hdfs.util.ReadOnlyList;
+import org.apache.hadoop.ipc.Server;
+import org.apache.hadoop.security.AccessControlException;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.ranger.audit.model.AuthzAuditEvent;
+import org.apache.ranger.authorization.hadoop.config.RangerConfiguration;
+import org.apache.ranger.authorization.hadoop.constants.RangerHadoopConstants;
+import org.apache.ranger.authorization.hadoop.exceptions.RangerAccessControlException;
+import org.apache.ranger.authorization.utils.StringUtil;
+import org.apache.ranger.plugin.audit.RangerDefaultAuditHandler;
+import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
+import org.apache.ranger.plugin.policyengine.RangerAccessRequestImpl;
+import org.apache.ranger.plugin.policyengine.RangerAccessResource;
+import org.apache.ranger.plugin.policyengine.RangerAccessResourceImpl;
+import org.apache.ranger.plugin.policyengine.RangerAccessResult;
+import org.apache.ranger.plugin.service.RangerBasePlugin;
+
+import com.google.common.collect.Sets;
+
+public class RangerHdfsAuthorizerImpl extends INodeAttributeProvider {
+ private static final Log LOG = LogFactory.getLog(RangerHdfsAuthorizerImpl.class);
+
+ private RangerHdfsPlugin rangerPlugin = null;
+ private Map<FsAction, Set<String>> access2ActionListMapper = new HashMap<FsAction, Set<String>>();
+
+ public RangerHdfsAuthorizerImpl() {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHdfsAuthorizer.RangerHdfsAuthorizer()");
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHdfsAuthorizer.RangerHdfsAuthorizer()");
+ }
+ }
+
+ public void start() {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHdfsAuthorizer.start()");
+ }
+
+ RangerHdfsPlugin plugin = new RangerHdfsPlugin();
+ plugin.init();
+
+ access2ActionListMapper.put(FsAction.NONE, new HashSet<String>());
+ access2ActionListMapper.put(FsAction.ALL, Sets.newHashSet(READ_ACCCESS_TYPE, WRITE_ACCCESS_TYPE, EXECUTE_ACCCESS_TYPE));
+ access2ActionListMapper.put(FsAction.READ, Sets.newHashSet(READ_ACCCESS_TYPE));
+ access2ActionListMapper.put(FsAction.READ_WRITE, Sets.newHashSet(READ_ACCCESS_TYPE, WRITE_ACCCESS_TYPE));
+ access2ActionListMapper.put(FsAction.READ_EXECUTE, Sets.newHashSet(READ_ACCCESS_TYPE, EXECUTE_ACCCESS_TYPE));
+ access2ActionListMapper.put(FsAction.WRITE, Sets.newHashSet(WRITE_ACCCESS_TYPE));
+ access2ActionListMapper.put(FsAction.WRITE_EXECUTE, Sets.newHashSet(WRITE_ACCCESS_TYPE, EXECUTE_ACCCESS_TYPE));
+ access2ActionListMapper.put(FsAction.EXECUTE, Sets.newHashSet(EXECUTE_ACCCESS_TYPE));
+
+ rangerPlugin = plugin;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHdfsAuthorizer.start()");
+ }
+ }
+
+ public void stop() {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHdfsAuthorizer.stop()");
+ }
+
+ RangerHdfsPlugin plugin = rangerPlugin;
+ rangerPlugin = null;
+
+ if(plugin != null) {
+ plugin.cleanup();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHdfsAuthorizer.stop()");
+ }
+ }
+
+ @Override
+ public INodeAttributes getAttributes(String fullPath, INodeAttributes inode) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHdfsAuthorizer.getAttributes(" + fullPath + ")");
+ }
+
+ INodeAttributes ret = inode; // return default attributes
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHdfsAuthorizer.getAttributes(" + fullPath + "): " + ret);
+ }
+
+ return ret;
+ }
+
+ @Override
+ public INodeAttributes getAttributes(String[] pathElements, INodeAttributes inode) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHdfsAuthorizer.getAttributes(pathElementsCount=" + (pathElements == null ? 0 : pathElements.length) + ")");
+ }
+
+ INodeAttributes ret = inode; // return default attributes
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHdfsAuthorizer.getAttributes(pathElementsCount=" + (pathElements == null ? 0 : pathElements.length) + "): " + ret);
+ }
+
+ return ret;
+ }
+
+ @Override
+ public AccessControlEnforcer getExternalAccessControlEnforcer(AccessControlEnforcer defaultEnforcer) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHdfsAuthorizer.getExternalAccessControlEnforcer()");
+ }
+
+ RangerAccessControlEnforcer rangerAce = new RangerAccessControlEnforcer(defaultEnforcer);
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHdfsAuthorizer.getExternalAccessControlEnforcer()");
+ }
+
+ return rangerAce;
+ }
+
+
+ class RangerAccessControlEnforcer implements AccessControlEnforcer {
+ private INodeAttributeProvider.AccessControlEnforcer defaultEnforcer = null;
+
+ public RangerAccessControlEnforcer(AccessControlEnforcer defaultEnforcer) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAccessControlEnforcer.RangerAccessControlEnforcer()");
+ }
+
+ this.defaultEnforcer = defaultEnforcer;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAccessControlEnforcer.RangerAccessControlEnforcer()");
+ }
+ }
+
+ @Override
+ public void checkPermission(String fsOwner, String superGroup, UserGroupInformation ugi,
+ INodeAttributes[] inodeAttrs, INode[] inodes, byte[][] pathByNameArr,
+ int snapshotId, String path, int ancestorIndex, boolean doCheckOwner,
+ FsAction ancestorAccess, FsAction parentAccess, FsAction access,
+ FsAction subAccess, boolean ignoreEmptyDir) throws AccessControlException {
+ boolean accessGranted = false;
+ RangerHdfsPlugin plugin = rangerPlugin;
+ RangerHdfsAuditHandler auditHandler = null;
+ String user = ugi != null ? ugi.getShortUserName() : null;
+ Set<String> groups = ugi != null ? Sets.newHashSet(ugi.getGroupNames()) : null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAccessControlEnforcer.checkPermission("
+ + "fsOwner=" + fsOwner + "; superGroup=" + superGroup + ", inodesCount=" + (inodes != null ? inodes.length : 0)
+ + ", snapshotId=" + snapshotId + ", user=" + user + ", path=" + path + ", ancestorIndex=" + ancestorIndex
+ + ", doCheckOwner="+ doCheckOwner + ", ancestorAccess=" + ancestorAccess + ", parentAccess=" + parentAccess
+ + ", access=" + access + ", subAccess=" + subAccess + ", ignoreEmptyDir=" + ignoreEmptyDir + ")");
+ }
+
+ try {
+ if(plugin != null && !ArrayUtils.isEmpty(inodes)) {
+ auditHandler = new RangerHdfsAuditHandler(path);
+
+ if(ancestorIndex >= inodes.length) {
+ ancestorIndex = inodes.length - 1;
+ }
+
+ for(; ancestorIndex >= 0 && inodes[ancestorIndex] == null; ancestorIndex--);
+
+ accessGranted = true;
+
+ INode ancestor = inodes.length > ancestorIndex && ancestorIndex >= 0 ? inodes[ancestorIndex] : null;
+ INode parent = inodes.length > 1 ? inodes[inodes.length - 2] : null;
+ INode inode = inodes[inodes.length - 1];
+
+ boolean noAccessToCheck = access == null && parentAccess == null && ancestorAccess == null && subAccess == null;
+
+ if(noAccessToCheck) { // check for traverse (EXECUTE) access on the path (if path is a directory) or its parent (if path is a file)
+ INode node = null;
+ INodeAttributes nodeAttribs = null;
+
+ if(inode != null && inode.isDirectory()) {
+ node = inode;
+ nodeAttribs = inodeAttrs.length > 0 ? inodeAttrs[inodeAttrs.length - 1] : null;
+ } else if(parent != null) {
+ node = parent;
+ nodeAttribs = inodeAttrs.length > 1 ? inodeAttrs[inodeAttrs.length - 2] : null;
+ }
+
+ if(node != null) {
+ accessGranted = isAccessAllowed(node, nodeAttribs, FsAction.EXECUTE, user, groups, fsOwner, superGroup, plugin, null);
+ }
+ }
+
+ // checkStickyBit
+ if (accessGranted && parentAccess != null && parentAccess.implies(FsAction.WRITE) && parent != null && inode != null) {
+ if (parent.getFsPermission() != null && parent.getFsPermission().getStickyBit()) {
+ // user should be owner of the parent or the inode
+ accessGranted = StringUtils.equals(parent.getUserName(), user) || StringUtils.equals(inode.getUserName(), user);
+ }
+ }
+
+ // checkAncestorAccess
+ if(accessGranted && ancestorAccess != null && ancestor != null) {
+ INodeAttributes ancestorAttribs = inodeAttrs.length > ancestorIndex ? inodeAttrs[ancestorIndex] : null;
+
+ accessGranted = isAccessAllowed(ancestor, ancestorAttribs, ancestorAccess, user, groups, fsOwner, superGroup, plugin, auditHandler);
+ }
+
+ // checkParentAccess
+ if(accessGranted && parentAccess != null && parent != null) {
+ INodeAttributes parentAttribs = inodeAttrs.length > 1 ? inodeAttrs[inodeAttrs.length - 2] : null;
+
+ accessGranted = isAccessAllowed(parent, parentAttribs, parentAccess, user, groups, fsOwner, superGroup, plugin, auditHandler);
+ }
+
+ // checkINodeAccess
+ if(accessGranted && access != null && inode != null) {
+ INodeAttributes inodeAttribs = inodeAttrs.length > 0 ? inodeAttrs[inodeAttrs.length - 1] : null;
+
+ accessGranted = isAccessAllowed(inode, inodeAttribs, access, user, groups, fsOwner, superGroup, plugin, auditHandler);
+ }
+
+ // checkSubAccess
+ if(accessGranted && subAccess != null && inode != null && inode.isDirectory()) {
+ Stack<INodeDirectory> directories = new Stack<INodeDirectory>();
+
+ for(directories.push(inode.asDirectory()); !directories.isEmpty(); ) {
+ INodeDirectory dir = directories.pop();
+ ReadOnlyList<INode> cList = dir.getChildrenList(snapshotId);
+
+ if (!(cList.isEmpty() && ignoreEmptyDir)) {
+ INodeAttributes dirAttribs = dir.getSnapshotINode(snapshotId);
+
+ accessGranted = isAccessAllowed(dir, dirAttribs, subAccess, user, groups, fsOwner, superGroup, plugin, auditHandler);
+
+ if(! accessGranted) {
+ break;
+ }
+ }
+
+ for(INode child : cList) {
+ if (child.isDirectory()) {
+ directories.push(child.asDirectory());
+ }
+ }
+ }
+ }
+
+ // checkOwnerAccess
+ if(accessGranted && doCheckOwner) {
+ INodeAttributes inodeAttribs = inodeAttrs.length > 0 ? inodeAttrs[inodeAttrs.length - 1] : null;
+ String owner = inodeAttribs != null ? inodeAttribs.getUserName() : null;
+
+ accessGranted = StringUtils.equals(user, owner);
+ }
+ }
+
+ if(! accessGranted && RangerHdfsPlugin.isHadoopAuthEnabled() && defaultEnforcer != null) {
+ try {
+ defaultEnforcer.checkPermission(fsOwner, superGroup, ugi, inodeAttrs, inodes,
+ pathByNameArr, snapshotId, path, ancestorIndex, doCheckOwner,
+ ancestorAccess, parentAccess, access, subAccess, ignoreEmptyDir);
+
+ accessGranted = true;
+ } finally {
+ if(auditHandler != null) {
+ FsAction action = access;
+
+ if(action == null) {
+ if(parentAccess != null) {
+ action = parentAccess;
+ } else if(ancestorAccess != null) {
+ action = ancestorAccess;
+ } else if(subAccess != null) {
+ action = subAccess;
+ } else {
+ action = FsAction.NONE;
+ }
+ }
+
+ auditHandler.logHadoopEvent(path, action, accessGranted);
+ }
+ }
+ }
+
+ if(! accessGranted) {
+ throw new RangerAccessControlException("Permission denied: principal{user=" + user + ",groups: " + groups + "}, access=" + access + ", " + path) ;
+ }
+ } finally {
+ if(auditHandler != null) {
+ auditHandler.flushAudit();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAccessControlEnforcer.checkPermission(" + path + ", " + access + ", user=" + user + ") : " + accessGranted);
+ }
+ }
+ }
+
+ private boolean isAccessAllowed(INode inode, INodeAttributes inodeAttribs, FsAction access, String user, Set<String> groups, String fsOwner, String superGroup, RangerHdfsPlugin plugin, RangerHdfsAuditHandler auditHandler) {
+ boolean ret = false;
+ String path = inode != null ? inode.getFullPathName() : null;
+ String pathOwner = inodeAttribs != null ? inodeAttribs.getUserName() : null;
+
+ if(pathOwner == null && inode != null) {
+ pathOwner = inode.getUserName();
+ }
+
+ if (RangerHadoopConstants.HDFS_ROOT_FOLDER_PATH_ALT.equals(path)) {
+ path = RangerHadoopConstants.HDFS_ROOT_FOLDER_PATH;
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAccessControlEnforcer.isAccessAllowed(" + path + ", " + access + ", " + user + ")");
+ }
+
+ Set<String> accessTypes = access2ActionListMapper.get(access);
+
+ if(accessTypes == null) {
+ LOG.warn("RangerAccessControlEnforcer.isAccessAllowed(" + path + ", " + access + ", " + user + "): no Ranger accessType found for " + access);
+
+ accessTypes = access2ActionListMapper.get(FsAction.NONE);
+ }
+
+ for(String accessType : accessTypes) {
+ RangerHdfsAccessRequest request = new RangerHdfsAccessRequest(path, pathOwner, access, accessType, user, groups);
+
+ RangerAccessResult result = plugin.isAccessAllowed(request, auditHandler);
+
+ if (result == null) {
+ LOG.error("RangerAccessControlEnforcer: Internal error: null RangerAccessResult object received back from isAccessAllowed()!");
+ } else {
+ ret = result.getIsAllowed();
+
+ if (!ret) {
+ break;
+ }
+ }
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAccessControlEnforcer.isAccessAllowed(" + path + ", " + access + ", " + user + "): " + ret);
+ }
+
+ return ret;
+ }
+ }
+}
+
+
+class RangerHdfsPlugin extends RangerBasePlugin {
+ private static boolean hadoopAuthEnabled = RangerHadoopConstants.RANGER_ADD_HDFS_PERMISSION_DEFAULT;
+
+ public RangerHdfsPlugin() {
+ super("hdfs", "hdfs");
+ }
+
+ public void init() {
+ super.init();
+
+ RangerHdfsPlugin.hadoopAuthEnabled = RangerConfiguration.getInstance().getBoolean(RangerHadoopConstants.RANGER_ADD_HDFS_PERMISSION_PROP, RangerHadoopConstants.RANGER_ADD_HDFS_PERMISSION_DEFAULT);
+ }
+
+ public static boolean isHadoopAuthEnabled() {
+ return RangerHdfsPlugin.hadoopAuthEnabled;
+ }
+}
+
+class RangerHdfsResource extends RangerAccessResourceImpl {
+ private static final String KEY_PATH = "path";
+
+
+ public RangerHdfsResource(String path, String owner) {
+ super.setValue(KEY_PATH, path);
+ super.setOwnerUser(owner);
+ }
+}
+
+class RangerHdfsAccessRequest extends RangerAccessRequestImpl {
+ public RangerHdfsAccessRequest(String path, String pathOwner, FsAction access, String accessType, String user, Set<String> groups) {
+ super.setResource(new RangerHdfsResource(path, pathOwner));
+ super.setAccessType(accessType);
+ super.setUser(user);
+ super.setUserGroups(groups);
+ super.setAccessTime(StringUtil.getUTCDate());
+ super.setClientIPAddress(getRemoteIp());
+ super.setAction(access.toString());
+ }
+
+ private static String getRemoteIp() {
+ String ret = null ;
+ InetAddress ip = Server.getRemoteIp() ;
+ if (ip != null) {
+ ret = ip.getHostAddress();
+ }
+ return ret ;
+ }
+}
+
+class RangerHdfsAuditHandler extends RangerDefaultAuditHandler {
+ private static final Log LOG = LogFactory.getLog(RangerHdfsAuditHandler.class);
+
+ private boolean isAuditEnabled = false;
+ private AuthzAuditEvent auditEvent = null;
+
+ private static final String RangerModuleName = RangerConfiguration.getInstance().get(RangerHadoopConstants.AUDITLOG_RANGER_MODULE_ACL_NAME_PROP , RangerHadoopConstants.DEFAULT_RANGER_MODULE_ACL_NAME) ;
+ private static final String HadoopModuleName = RangerConfiguration.getInstance().get(RangerHadoopConstants.AUDITLOG_HADOOP_MODULE_ACL_NAME_PROP , RangerHadoopConstants.DEFAULT_HADOOP_MODULE_ACL_NAME) ;
+ private static final String excludeUserList = RangerConfiguration.getInstance().get(RangerHadoopConstants.AUDITLOG_HDFS_EXCLUDE_LIST_PROP, RangerHadoopConstants.AUDITLOG_EMPTY_STRING) ;
+ private static HashSet<String> excludeUsers = null ;
+
+ static {
+ if (excludeUserList != null && excludeUserList.trim().length() > 0) {
+ excludeUsers = new HashSet<String>() ;
+ for(String excludeUser : excludeUserList.trim().split(",")) {
+ excludeUser = excludeUser.trim() ;
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Adding exclude user [" + excludeUser + "]");
+ }
+ excludeUsers.add(excludeUser) ;
+ }
+ }
+ }
+
+ public RangerHdfsAuditHandler(String pathToBeValidated) {
+ auditEvent = new AuthzAuditEvent();
+ auditEvent.setResourcePath(pathToBeValidated);
+ }
+
+ @Override
+ public void processResult(RangerAccessResult result) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHdfsAuditHandler.logAudit(" + result + ")");
+ }
+
+ if(! isAuditEnabled && result.getIsAudited()) {
+ isAuditEnabled = true;
+ }
+
+ RangerAccessRequest request = result.getAccessRequest();
+// RangerServiceDef serviceDef = result.getServiceDef();
+ RangerAccessResource resource = request.getResource();
+ String resourceType = resource != null ? resource.getLeafName() : null;
+ String resourcePath = resource != null ? resource.getAsString() : null;
+
+ auditEvent.setUser(request.getUser());
+ auditEvent.setResourceType(resourceType) ;
+ auditEvent.setAccessType(request.getAction());
+ auditEvent.setAccessResult((short)(result.getIsAllowed() ? 1 : 0));
+ auditEvent.setClientIP(request.getClientIPAddress());
+ auditEvent.setEventTime(request.getAccessTime());
+ auditEvent.setAclEnforcer(RangerModuleName);
+ auditEvent.setPolicyId(result.getPolicyId());
+ auditEvent.setRepositoryType(result.getServiceType());
+ auditEvent.setRepositoryName(result.getServiceName());
+ auditEvent.setResultReason(resourcePath);
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHdfsAuditHandler.logAudit(" + result + "): " + auditEvent);
+ }
+ }
+
+ public void logHadoopEvent(String path, FsAction action, boolean accessGranted) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHdfsAuditHandler.logHadoopEvent(" + path + ", " + action + ", " + accessGranted + ")");
+ }
+
+ auditEvent.setResultReason(path);
+ auditEvent.setAccessResult((short) (accessGranted ? 1 : 0));
+ auditEvent.setAccessType(action == null ? null : action.toString());
+ auditEvent.setAclEnforcer(HadoopModuleName);
+ auditEvent.setPolicyId(-1);
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHdfsAuditHandler.logHadoopEvent(" + path + ", " + action + ", " + accessGranted + "): " + auditEvent);
+ }
+ }
+
+ public void flushAudit() {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHdfsAuditHandler.flushAudit(" + isAuditEnabled + ", " + auditEvent + ")");
+ }
+
+ if(isAuditEnabled && !StringUtils.isEmpty(auditEvent.getAccessType())) {
+ String username = auditEvent.getUser();
+
+ boolean skipLog = (username != null && excludeUsers != null && excludeUsers.contains(username)) ;
+
+ if (! skipLog) {
+ super.logAuthzAudit(auditEvent);
+ }
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHdfsAuditHandler.flushAudit(" + isAuditEnabled + ", " + auditEvent + ")");
+ }
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/hive-agent/conf/ranger-hive-security.xml
----------------------------------------------------------------------
diff --git a/hive-agent/conf/ranger-hive-security.xml b/hive-agent/conf/ranger-hive-security.xml
index 3a5fc54..515b1fd 100644
--- a/hive-agent/conf/ranger-hive-security.xml
+++ b/hive-agent/conf/ranger-hive-security.xml
@@ -65,6 +65,22 @@
</description>
</property>
+ <property>
+ <name>ranger.policy.rest.client.connection.timeoutMs</name>
+ <value>120000</value>
+ <description>
+ RangerRestClient Connection Timeout in Milli Seconds
+ </description>
+ </property>
+
+ <property>
+ <name>ranger.policy.rest.client.read.timeoutMs</name>
+ <value>30000</value>
+ <description>
+ RangerRestClient read Timeout in Milli Seconds
+ </description>
+ </property>
+
<property>
<name>xasecure.hive.update.xapolicies.on.grant.revoke</name>
<value>true</value>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/hive-agent/src/main/java/com/xasecure/authorization/hive/authorizer/XaSecureHiveAuthorizerFactory.java
----------------------------------------------------------------------
diff --git a/hive-agent/src/main/java/com/xasecure/authorization/hive/authorizer/XaSecureHiveAuthorizerFactory.java b/hive-agent/src/main/java/com/xasecure/authorization/hive/authorizer/XaSecureHiveAuthorizerFactory.java
index e941704..079616c 100644
--- a/hive-agent/src/main/java/com/xasecure/authorization/hive/authorizer/XaSecureHiveAuthorizerFactory.java
+++ b/hive-agent/src/main/java/com/xasecure/authorization/hive/authorizer/XaSecureHiveAuthorizerFactory.java
@@ -18,7 +18,7 @@
*/
package com.xasecure.authorization.hive.authorizer;
-import org.apache.ranger.authorization.hive.authorizer.RangerHiveAuthorizerFactory;
+import org.apache.ranger.authorization.hive.authorizer.RangerHiveAuthorizerFactoryImpl;
/**
* This class exists only to provide for seamless upgrade/downgrade capabilities. Coprocessor name is in hbase config files in /etc/.../conf which
@@ -28,6 +28,6 @@ import org.apache.ranger.authorization.hive.authorizer.RangerHiveAuthorizerFacto
* This class is final because if one needs to customize coprocessor it is expected that RangerAuthorizationCoprocessor would be modified/extended as that is
* the "real" coprocessor! This class, hence, should NEVER be more than an EMPTY shell!
*/
-public final class XaSecureHiveAuthorizerFactory extends RangerHiveAuthorizerFactory {
+public final class XaSecureHiveAuthorizerFactory extends RangerHiveAuthorizerFactoryImpl {
}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/hive-agent/src/main/java/org/apache/ranger/authorization/hive/authorizer/RangerHiveAuthorizerFactory.java
----------------------------------------------------------------------
diff --git a/hive-agent/src/main/java/org/apache/ranger/authorization/hive/authorizer/RangerHiveAuthorizerFactory.java b/hive-agent/src/main/java/org/apache/ranger/authorization/hive/authorizer/RangerHiveAuthorizerFactory.java
deleted file mode 100644
index bd410b7..0000000
--- a/hive-agent/src/main/java/org/apache/ranger/authorization/hive/authorizer/RangerHiveAuthorizerFactory.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
- package org.apache.ranger.authorization.hive.authorizer;
-
-import org.apache.hadoop.hive.conf.HiveConf;
-import org.apache.hadoop.hive.ql.security.HiveAuthenticationProvider;
-import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthorizer;
-import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthorizerFactory;
-import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzPluginException;
-import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveMetastoreClientFactory;
-import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzSessionContext;
-
-public class RangerHiveAuthorizerFactory implements HiveAuthorizerFactory {
- @Override
- public HiveAuthorizer createHiveAuthorizer(HiveMetastoreClientFactory metastoreClientFactory,
- HiveConf conf,
- HiveAuthenticationProvider hiveAuthenticator,
- HiveAuthzSessionContext sessionContext)
- throws HiveAuthzPluginException {
- return new RangerHiveAuthorizer(metastoreClientFactory, conf, hiveAuthenticator, sessionContext);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/hive-agent/src/main/java/org/apache/ranger/authorization/hive/authorizer/RangerHiveAuthorizerFactoryImpl.java
----------------------------------------------------------------------
diff --git a/hive-agent/src/main/java/org/apache/ranger/authorization/hive/authorizer/RangerHiveAuthorizerFactoryImpl.java b/hive-agent/src/main/java/org/apache/ranger/authorization/hive/authorizer/RangerHiveAuthorizerFactoryImpl.java
new file mode 100644
index 0000000..937aaed
--- /dev/null
+++ b/hive-agent/src/main/java/org/apache/ranger/authorization/hive/authorizer/RangerHiveAuthorizerFactoryImpl.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+ package org.apache.ranger.authorization.hive.authorizer;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.ql.security.HiveAuthenticationProvider;
+import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthorizer;
+import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthorizerFactory;
+import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzPluginException;
+import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveMetastoreClientFactory;
+import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzSessionContext;
+
+public class RangerHiveAuthorizerFactoryImpl implements HiveAuthorizerFactory {
+
+ @Override
+ public HiveAuthorizer createHiveAuthorizer(HiveMetastoreClientFactory metastoreClientFactory,
+ HiveConf conf,
+ HiveAuthenticationProvider hiveAuthenticator,
+ HiveAuthzSessionContext sessionContext)
+ throws HiveAuthzPluginException {
+ return new RangerHiveAuthorizer(metastoreClientFactory, conf, hiveAuthenticator, sessionContext);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/knox-agent/src/main/java/com/xasecure/pdp/knox/filter/XASecurePDPKnoxFilter.java
----------------------------------------------------------------------
diff --git a/knox-agent/src/main/java/com/xasecure/pdp/knox/filter/XASecurePDPKnoxFilter.java b/knox-agent/src/main/java/com/xasecure/pdp/knox/filter/XASecurePDPKnoxFilter.java
deleted file mode 100644
index 6b9d6fd..0000000
--- a/knox-agent/src/main/java/com/xasecure/pdp/knox/filter/XASecurePDPKnoxFilter.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package com.xasecure.pdp.knox.filter;
-
-import org.apache.ranger.authorization.knox.RangerPDPKnoxFilter;
-
-public class XASecurePDPKnoxFilter extends RangerPDPKnoxFilter {
-}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/plugin-kafka/conf/ranger-kafka-security.xml
----------------------------------------------------------------------
diff --git a/plugin-kafka/conf/ranger-kafka-security.xml b/plugin-kafka/conf/ranger-kafka-security.xml
index 2c06f5c..f9c8d5f 100644
--- a/plugin-kafka/conf/ranger-kafka-security.xml
+++ b/plugin-kafka/conf/ranger-kafka-security.xml
@@ -80,4 +80,5 @@
RangerRestClient read Timeout in Milli Seconds
</description>
</property>
+
</configuration>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/plugin-kafka/pom.xml
----------------------------------------------------------------------
diff --git a/plugin-kafka/pom.xml b/plugin-kafka/pom.xml
index afee47d..e14e48c 100644
--- a/plugin-kafka/pom.xml
+++ b/plugin-kafka/pom.xml
@@ -47,5 +47,10 @@
<artifactId>kafka_2.10</artifactId>
<version>${kafka.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-hdfs</artifactId>
+ <version>${hadoop.version}</version>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/plugin-kafka/src/main/java/org/apache/ranger/authorization/kafka/authorizer/RangerKafkaAuthorizer.java
----------------------------------------------------------------------
diff --git a/plugin-kafka/src/main/java/org/apache/ranger/authorization/kafka/authorizer/RangerKafkaAuthorizer.java b/plugin-kafka/src/main/java/org/apache/ranger/authorization/kafka/authorizer/RangerKafkaAuthorizer.java
deleted file mode 100644
index dbb2723..0000000
--- a/plugin-kafka/src/main/java/org/apache/ranger/authorization/kafka/authorizer/RangerKafkaAuthorizer.java
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.ranger.authorization.kafka.authorizer;
-
-import java.io.IOException;
-import java.security.Principal;
-import java.util.Date;
-
-import javax.security.auth.Subject;
-
-import kafka.security.auth.Acl;
-import kafka.security.auth.Authorizer;
-import kafka.security.auth.KafkaPrincipal;
-import kafka.security.auth.Operation;
-import kafka.security.auth.Resource;
-import kafka.security.auth.ResourceType;
-import kafka.server.KafkaConfig;
-import kafka.common.security.LoginManager;
-import kafka.network.RequestChannel.Session;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.security.UserGroupInformation;
-import org.apache.ranger.audit.provider.MiscUtil;
-import org.apache.ranger.authorization.utils.StringUtil;
-import org.apache.ranger.plugin.audit.RangerDefaultAuditHandler;
-import org.apache.ranger.plugin.policyengine.RangerAccessRequestImpl;
-import org.apache.ranger.plugin.policyengine.RangerAccessResourceImpl;
-import org.apache.ranger.plugin.policyengine.RangerAccessResult;
-import org.apache.ranger.plugin.service.RangerBasePlugin;
-
-import scala.collection.immutable.HashSet;
-import scala.collection.immutable.Set;
-
-public class RangerKafkaAuthorizer implements Authorizer {
- private static final Log logger = LogFactory
- .getLog(RangerKafkaAuthorizer.class);
-
- public static final String KEY_TOPIC = "topic";
- public static final String KEY_CLUSTER = "cluster";
- public static final String KEY_CONSUMER_GROUP = "consumer_group";
-
- public static final String ACCESS_TYPE_READ = "consume";
- public static final String ACCESS_TYPE_WRITE = "publish";
- public static final String ACCESS_TYPE_CREATE = "create";
- public static final String ACCESS_TYPE_DELETE = "delete";
- public static final String ACCESS_TYPE_CONFIGURE = "configure";
- public static final String ACCESS_TYPE_DESCRIBE = "describe";
- public static final String ACCESS_TYPE_KAFKA_ADMIN = "kafka_admin";
-
- private static volatile RangerBasePlugin rangerPlugin = null;
- long lastLogTime = 0;
- int errorLogFreq = 30000; // Log after every 30 seconds
-
- public RangerKafkaAuthorizer() {
- }
-
- /*
- * (non-Javadoc)
- *
- * @see kafka.security.auth.Authorizer#initialize(kafka.server.KafkaConfig)
- */
- @Override
- public void initialize(KafkaConfig kafkaConfig) {
-
- if (rangerPlugin == null) {
- try {
- Subject subject = LoginManager.subject();
- UserGroupInformation ugi = MiscUtil
- .createUGIFromSubject(subject);
- if (ugi != null) {
- MiscUtil.setUGILoginUser(ugi, subject);
- }
- logger.info("LoginUser=" + MiscUtil.getUGILoginUser());
- } catch (Throwable t) {
- logger.error("Error getting principal.", t);
- }
-
- rangerPlugin = new RangerBasePlugin("kafka", "kafka");
- logger.info("Calling plugin.init()");
- rangerPlugin.init();
-
- RangerDefaultAuditHandler auditHandler = new RangerDefaultAuditHandler();
- rangerPlugin.setResultProcessor(auditHandler);
- }
- }
-
- @Override
- public boolean authorize(Session session, Operation operation,
- Resource resource) {
-
- if (rangerPlugin == null) {
- MiscUtil.logErrorMessageByInterval(logger,
- "Authorizer is still not initialized");
- return false;
- }
-
- // TODO: If resource type if consumer group, then allow it by default
- if (resource.resourceType().equals(ResourceType.CONSUMER_GROUP)) {
- return true;
- }
-
- String userName = null;
- if (session.principal() != null) {
- userName = session.principal().getName();
- userName = StringUtils.substringBefore(userName, "/");
- userName = StringUtils.substringBefore(userName, "@");
- }
- java.util.Set<String> userGroups = MiscUtil
- .getGroupsForRequestUser(userName);
- String ip = session.host();
-
- Date eventTime = StringUtil.getUTCDate();
- String accessType = mapToRangerAccessType(operation);
- boolean validationFailed = false;
- String validationStr = "";
-
- if (accessType == null) {
- if (MiscUtil.logErrorMessageByInterval(logger,
- "Unsupported access type. operation=" + operation)) {
- logger.fatal("Unsupported access type. session=" + session
- + ", operation=" + operation + ", resource=" + resource);
- }
- validationFailed = true;
- validationStr += "Unsupported access type. operation=" + operation;
- }
- String action = accessType;
-
- RangerAccessRequestImpl rangerRequest = new RangerAccessRequestImpl();
- rangerRequest.setUser(userName);
- rangerRequest.setUserGroups(userGroups);
- rangerRequest.setClientIPAddress(ip);
- rangerRequest.setAccessTime(eventTime);
-
- RangerAccessResourceImpl rangerResource = new RangerAccessResourceImpl();
- rangerRequest.setResource(rangerResource);
- rangerRequest.setAccessType(accessType);
- rangerRequest.setAction(action);
- rangerRequest.setRequestData(resource.name());
-
- if (resource.resourceType().equals(ResourceType.TOPIC)) {
- rangerResource.setValue(KEY_TOPIC, resource.name());
- } else if (resource.resourceType().equals(ResourceType.CLUSTER)) {
- // CLUSTER should go as null
- // rangerResource.setValue(KEY_CLUSTER, resource.name());
- } else if (resource.resourceType().equals(ResourceType.CONSUMER_GROUP)) {
- rangerResource.setValue(KEY_CONSUMER_GROUP, resource.name());
- } else {
- logger.fatal("Unsupported resourceType=" + resource.resourceType());
- validationFailed = true;
- }
-
- boolean returnValue = true;
- if (validationFailed) {
- MiscUtil.logErrorMessageByInterval(logger, validationStr
- + ", request=" + rangerRequest);
- returnValue = false;
- } else {
-
- try {
- RangerAccessResult result = rangerPlugin
- .isAccessAllowed(rangerRequest);
- if (result == null) {
- logger.error("Ranger Plugin returned null. Returning false");
- returnValue = false;
- } else {
- returnValue = result.getIsAllowed();
- }
- } catch (Throwable t) {
- logger.error("Error while calling isAccessAllowed(). request="
- + rangerRequest, t);
- }
- }
- if (logger.isDebugEnabled()) {
- logger.debug("rangerRequest=" + rangerRequest + ", return="
- + returnValue);
- }
- return returnValue;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * kafka.security.auth.Authorizer#addAcls(scala.collection.immutable.Set,
- * kafka.security.auth.Resource)
- */
- @Override
- public void addAcls(Set<Acl> acls, Resource resource) {
- logger.error("addAcls() is not supported by Ranger for Kafka");
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * kafka.security.auth.Authorizer#removeAcls(scala.collection.immutable.Set,
- * kafka.security.auth.Resource)
- */
- @Override
- public boolean removeAcls(Set<Acl> acls, Resource resource) {
- logger.error("removeAcls() is not supported by Ranger for Kafka");
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * kafka.security.auth.Authorizer#removeAcls(kafka.security.auth.Resource)
- */
- @Override
- public boolean removeAcls(Resource resource) {
- logger.error("removeAcls() is not supported by Ranger for Kafka");
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see kafka.security.auth.Authorizer#getAcls(kafka.security.auth.Resource)
- */
- @Override
- public Set<Acl> getAcls(Resource resource) {
- Set<Acl> aclList = new HashSet<Acl>();
- logger.error("getAcls() is not supported by Ranger for Kafka");
-
- return aclList;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * kafka.security.auth.Authorizer#getAcls(kafka.security.auth.KafkaPrincipal
- * )
- */
- @Override
- public Set<Acl> getAcls(KafkaPrincipal principal) {
- Set<Acl> aclList = new HashSet<Acl>();
- logger.error("getAcls() is not supported by Ranger for Kafka");
- return aclList;
- }
-
- /**
- * @param operation
- * @return
- */
- private String mapToRangerAccessType(Operation operation) {
- if (operation.equals(Operation.READ)) {
- return ACCESS_TYPE_READ;
- } else if (operation.equals(Operation.WRITE)) {
- return ACCESS_TYPE_WRITE;
- } else if (operation.equals(Operation.ALTER)) {
- return ACCESS_TYPE_CONFIGURE;
- } else if (operation.equals(Operation.DESCRIBE)) {
- return ACCESS_TYPE_DESCRIBE;
- } else if (operation.equals(Operation.CLUSTER_ACTION)) {
- return ACCESS_TYPE_KAFKA_ADMIN;
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/plugin-kafka/src/main/java/org/apache/ranger/authorization/kafka/authorizer/RangerKafkaAuthorizerImpl.java
----------------------------------------------------------------------
diff --git a/plugin-kafka/src/main/java/org/apache/ranger/authorization/kafka/authorizer/RangerKafkaAuthorizerImpl.java b/plugin-kafka/src/main/java/org/apache/ranger/authorization/kafka/authorizer/RangerKafkaAuthorizerImpl.java
new file mode 100644
index 0000000..608371a
--- /dev/null
+++ b/plugin-kafka/src/main/java/org/apache/ranger/authorization/kafka/authorizer/RangerKafkaAuthorizerImpl.java
@@ -0,0 +1,277 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.authorization.kafka.authorizer;
+
+import java.util.Date;
+import javax.security.auth.Subject;
+
+import kafka.security.auth.Acl;
+import kafka.security.auth.Authorizer;
+import kafka.security.auth.KafkaPrincipal;
+import kafka.security.auth.Operation;
+import kafka.security.auth.Resource;
+import kafka.security.auth.ResourceType;
+import kafka.server.KafkaConfig;
+import kafka.common.security.LoginManager;
+import kafka.network.RequestChannel.Session;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.ranger.audit.provider.MiscUtil;
+import org.apache.ranger.authorization.utils.StringUtil;
+import org.apache.ranger.plugin.audit.RangerDefaultAuditHandler;
+import org.apache.ranger.plugin.policyengine.RangerAccessRequestImpl;
+import org.apache.ranger.plugin.policyengine.RangerAccessResourceImpl;
+import org.apache.ranger.plugin.policyengine.RangerAccessResult;
+import org.apache.ranger.plugin.service.RangerBasePlugin;
+
+import scala.collection.immutable.HashSet;
+import scala.collection.immutable.Set;
+
+public class RangerKafkaAuthorizerImpl implements Authorizer {
+ private static final Log logger = LogFactory
+ .getLog(RangerKafkaAuthorizerImpl.class);
+
+ public static final String KEY_TOPIC = "topic";
+ public static final String KEY_CLUSTER = "cluster";
+ public static final String KEY_CONSUMER_GROUP = "consumer_group";
+
+ public static final String ACCESS_TYPE_READ = "consume";
+ public static final String ACCESS_TYPE_WRITE = "publish";
+ public static final String ACCESS_TYPE_CREATE = "create";
+ public static final String ACCESS_TYPE_DELETE = "delete";
+ public static final String ACCESS_TYPE_CONFIGURE = "configure";
+ public static final String ACCESS_TYPE_DESCRIBE = "describe";
+ public static final String ACCESS_TYPE_KAFKA_ADMIN = "kafka_admin";
+
+ private static volatile RangerBasePlugin rangerPlugin = null;
+ long lastLogTime = 0;
+ int errorLogFreq = 30000; // Log after every 30 seconds
+
+ public RangerKafkaAuthorizerImpl() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see kafka.security.auth.Authorizer#initialize(kafka.server.KafkaConfig)
+ */
+ @Override
+ public void initialize(KafkaConfig kafkaConfig) {
+
+ if (rangerPlugin == null) {
+ try {
+ Subject subject = LoginManager.subject();
+ UserGroupInformation ugi = MiscUtil
+ .createUGIFromSubject(subject);
+ if (ugi != null) {
+ MiscUtil.setUGILoginUser(ugi, subject);
+ }
+ logger.info("LoginUser=" + MiscUtil.getUGILoginUser());
+ } catch (Throwable t) {
+ logger.error("Error getting principal.", t);
+ }
+
+ rangerPlugin = new RangerBasePlugin("kafka", "kafka");
+ logger.info("Calling plugin.init()");
+ rangerPlugin.init();
+
+ RangerDefaultAuditHandler auditHandler = new RangerDefaultAuditHandler();
+ rangerPlugin.setResultProcessor(auditHandler);
+ }
+ }
+
+ @Override
+ public boolean authorize(Session session, Operation operation, Resource resource) {
+
+ if (rangerPlugin == null) {
+ MiscUtil.logErrorMessageByInterval(logger,
+ "Authorizer is still not initialized");
+ return false;
+ }
+
+ // TODO: If resource type if consumer group, then allow it by default
+ if (resource.resourceType().equals(ResourceType.CONSUMER_GROUP)) {
+ return true;
+ }
+
+ String userName = null;
+ if (session.principal() != null) {
+ userName = session.principal().getName();
+ userName = StringUtils.substringBefore(userName, "/");
+ userName = StringUtils.substringBefore(userName, "@");
+ }
+ java.util.Set<String> userGroups = MiscUtil
+ .getGroupsForRequestUser(userName);
+ String ip = session.host();
+
+ Date eventTime = StringUtil.getUTCDate();
+ String accessType = mapToRangerAccessType(operation);
+ boolean validationFailed = false;
+ String validationStr = "";
+
+ if (accessType == null) {
+ if (MiscUtil.logErrorMessageByInterval(logger,
+ "Unsupported access type. operation=" + operation)) {
+ logger.fatal("Unsupported access type. session=" + session
+ + ", operation=" + operation + ", resource=" + resource);
+ }
+ validationFailed = true;
+ validationStr += "Unsupported access type. operation=" + operation;
+ }
+ String action = accessType;
+
+ RangerAccessRequestImpl rangerRequest = new RangerAccessRequestImpl();
+ rangerRequest.setUser(userName);
+ rangerRequest.setUserGroups(userGroups);
+ rangerRequest.setClientIPAddress(ip);
+ rangerRequest.setAccessTime(eventTime);
+
+ RangerAccessResourceImpl rangerResource = new RangerAccessResourceImpl();
+ rangerRequest.setResource(rangerResource);
+ rangerRequest.setAccessType(accessType);
+ rangerRequest.setAction(action);
+ rangerRequest.setRequestData(resource.name());
+
+ if (resource.resourceType().equals(ResourceType.TOPIC)) {
+ rangerResource.setValue(KEY_TOPIC, resource.name());
+ } else if (resource.resourceType().equals(ResourceType.CLUSTER)) {
+ // CLUSTER should go as null
+ // rangerResource.setValue(KEY_CLUSTER, resource.name());
+ } else if (resource.resourceType().equals(ResourceType.CONSUMER_GROUP)) {
+ rangerResource.setValue(KEY_CONSUMER_GROUP, resource.name());
+ } else {
+ logger.fatal("Unsupported resourceType=" + resource.resourceType());
+ validationFailed = true;
+ }
+
+ boolean returnValue = true;
+ if (validationFailed) {
+ MiscUtil.logErrorMessageByInterval(logger, validationStr
+ + ", request=" + rangerRequest);
+ returnValue = false;
+ } else {
+
+ try {
+ RangerAccessResult result = rangerPlugin
+ .isAccessAllowed(rangerRequest);
+ if (result == null) {
+ logger.error("Ranger Plugin returned null. Returning false");
+ returnValue = false;
+ } else {
+ returnValue = result.getIsAllowed();
+ }
+ } catch (Throwable t) {
+ logger.error("Error while calling isAccessAllowed(). request="
+ + rangerRequest, t);
+ }
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug("rangerRequest=" + rangerRequest + ", return="
+ + returnValue);
+ }
+ return returnValue;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * kafka.security.auth.Authorizer#addAcls(scala.collection.immutable.Set,
+ * kafka.security.auth.Resource)
+ */
+ @Override
+ public void addAcls(Set<Acl> acls, Resource resource) {
+ logger.error("addAcls() is not supported by Ranger for Kafka");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * kafka.security.auth.Authorizer#removeAcls(scala.collection.immutable.Set,
+ * kafka.security.auth.Resource)
+ */
+ @Override
+ public boolean removeAcls(Set<Acl> acls, Resource resource) {
+ logger.error("removeAcls() is not supported by Ranger for Kafka");
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * kafka.security.auth.Authorizer#removeAcls(kafka.security.auth.Resource)
+ */
+ @Override
+ public boolean removeAcls(Resource resource) {
+ logger.error("removeAcls() is not supported by Ranger for Kafka");
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see kafka.security.auth.Authorizer#getAcls(kafka.security.auth.Resource)
+ */
+ @Override
+ public Set<Acl> getAcls(Resource resource) {
+ Set<Acl> aclList = new HashSet<Acl>();
+ logger.error("getAcls() is not supported by Ranger for Kafka");
+
+ return aclList;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * kafka.security.auth.Authorizer#getAcls(kafka.security.auth.KafkaPrincipal
+ * )
+ */
+ @Override
+ public Set<Acl> getAcls(KafkaPrincipal principal) {
+ Set<Acl> aclList = new HashSet<Acl>();
+ logger.error("getAcls() is not supported by Ranger for Kafka");
+ return aclList;
+ }
+
+ /**
+ * @param operation
+ * @return
+ */
+ private String mapToRangerAccessType(Operation operation) {
+ if (operation.equals(Operation.READ)) {
+ return ACCESS_TYPE_READ;
+ } else if (operation.equals(Operation.WRITE)) {
+ return ACCESS_TYPE_WRITE;
+ } else if (operation.equals(Operation.ALTER)) {
+ return ACCESS_TYPE_CONFIGURE;
+ } else if (operation.equals(Operation.DESCRIBE)) {
+ return ACCESS_TYPE_DESCRIBE;
+ } else if (operation.equals(Operation.CLUSTER_ACTION)) {
+ return ACCESS_TYPE_KAFKA_ADMIN;
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/plugin-kms/conf/ranger-kms-security.xml
----------------------------------------------------------------------
diff --git a/plugin-kms/conf/ranger-kms-security.xml b/plugin-kms/conf/ranger-kms-security.xml
index a22e6cb..58f7076 100755
--- a/plugin-kms/conf/ranger-kms-security.xml
+++ b/plugin-kms/conf/ranger-kms-security.xml
@@ -72,12 +72,13 @@
RangerRestClient Connection Timeout in Milli Seconds
</description>
</property>
-
+
<property>
<name>ranger.plugin.kms.policy.rest.client.read.timeoutMs</name>
<value>30000</value>
<description>
RangerRestClient read Timeout in Milli Seconds
</description>
- </property>
+ </property>
+
</configuration>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/plugin-yarn/src/main/java/org/apache/ranger/authorization/yarn/authorizer/RangerYarnAuthorizer.java
----------------------------------------------------------------------
diff --git a/plugin-yarn/src/main/java/org/apache/ranger/authorization/yarn/authorizer/RangerYarnAuthorizer.java b/plugin-yarn/src/main/java/org/apache/ranger/authorization/yarn/authorizer/RangerYarnAuthorizer.java
deleted file mode 100644
index ab9b7a9..0000000
--- a/plugin-yarn/src/main/java/org/apache/ranger/authorization/yarn/authorizer/RangerYarnAuthorizer.java
+++ /dev/null
@@ -1,354 +0,0 @@
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.ranger.authorization.yarn.authorizer;
-
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.ipc.Server;
-import org.apache.hadoop.security.UserGroupInformation;
-import org.apache.hadoop.security.authorize.AccessControlList;
-import org.apache.hadoop.yarn.security.*;
-import org.apache.hadoop.yarn.security.PrivilegedEntity.EntityType;
-import org.apache.ranger.audit.model.AuthzAuditEvent;
-import org.apache.ranger.authorization.hadoop.config.RangerConfiguration;
-import org.apache.ranger.authorization.hadoop.constants.RangerHadoopConstants;
-import org.apache.ranger.authorization.utils.StringUtil;
-import org.apache.ranger.plugin.audit.RangerDefaultAuditHandler;
-import org.apache.ranger.plugin.policyengine.RangerAccessRequestImpl;
-import org.apache.ranger.plugin.policyengine.RangerAccessResult;
-import org.apache.ranger.plugin.policyengine.RangerAccessResourceImpl;
-import org.apache.ranger.plugin.service.RangerBasePlugin;
-
-import com.google.common.collect.Sets;
-
-public class RangerYarnAuthorizer extends YarnAuthorizationProvider {
- public static final String ACCESS_TYPE_ADMIN_QUEUE = "admin-queue";
- public static final String ACCESS_TYPE_SUBMIT_APP = "submit-app";
- public static final String ACCESS_TYPE_ADMIN = "admin";
-
- private static boolean yarnAuthEnabled = RangerHadoopConstants.RANGER_ADD_YARN_PERMISSION_DEFAULT;
-
- private static final Log LOG = LogFactory.getLog(RangerYarnAuthorizer.class);
-
- private static volatile RangerYarnPlugin yarnPlugin = null;
-
- private AccessControlList admins = null;
- private Map<PrivilegedEntity, Map<AccessType, AccessControlList>> yarnAcl = new HashMap<PrivilegedEntity, Map<AccessType, AccessControlList>>();
-
- @Override
- public void init(Configuration conf) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerYarnAuthorizer.init()");
- }
-
- RangerYarnPlugin plugin = yarnPlugin;
-
- if(plugin == null) {
- synchronized(RangerYarnAuthorizer.class) {
- plugin = yarnPlugin;
-
- if(plugin == null) {
- plugin = new RangerYarnPlugin();
- plugin.init();
-
- yarnPlugin = plugin;
- }
- }
- }
-
- RangerYarnAuthorizer.yarnAuthEnabled = RangerConfiguration.getInstance().getBoolean(RangerHadoopConstants.RANGER_ADD_YARN_PERMISSION_PROP, RangerHadoopConstants.RANGER_ADD_YARN_PERMISSION_DEFAULT);
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerYarnAuthorizer.init()");
- }
- }
-
- @Override
- public boolean checkPermission(AccessType accessType, PrivilegedEntity entity, UserGroupInformation ugi) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerYarnAuthorizer.checkPermission(" + accessType + ", " + toString(entity) + ", " + ugi + ")");
- }
-
- boolean ret = false;
- RangerYarnPlugin plugin = yarnPlugin;
- RangerYarnAuditHandler auditHandler = null;
- RangerAccessResult result = null;
-
- if(plugin != null) {
- RangerYarnAccessRequest request = new RangerYarnAccessRequest(entity, getRangerAccessType(accessType), accessType.name(), ugi);
-
- auditHandler = new RangerYarnAuditHandler();
-
- result = plugin.isAccessAllowed(request, auditHandler);
- }
-
- if(RangerYarnAuthorizer.yarnAuthEnabled && (result == null || !result.getIsAccessDetermined())) {
- ret = isAllowedByYarnAcl(accessType, entity, ugi, auditHandler);
- } else {
- ret = result == null ? false : result.getIsAllowed();
- }
-
- if(auditHandler != null) {
- auditHandler.flushAudit();
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerYarnAuthorizer.checkPermission(" + accessType + ", " + toString(entity) + ", " + ugi + "): " + ret);
- }
-
- return ret;
- }
-
- @Override
- public boolean isAdmin(UserGroupInformation ugi) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerYarnAuthorizer.isAdmin(" + ugi + ")");
- }
-
- boolean ret = false;
-
- AccessControlList admins = this.admins;
-
- if(admins != null) {
- ret = admins.isUserAllowed(ugi);
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerYarnAuthorizer.isAdmin(" + ugi + "): " + ret);
- }
-
- return ret;
- }
-
- @Override
- public void setAdmins(AccessControlList acl, UserGroupInformation ugi) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerYarnAuthorizer.setAdmins(" + acl + ", " + ugi + ")");
- }
-
- admins = acl;
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerYarnAuthorizer.setAdmins(" + acl + ", " + ugi + ")");
- }
- }
-
- @Override
- public void setPermission(PrivilegedEntity entity, Map<AccessType, AccessControlList> permission, UserGroupInformation ugi) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerYarnAuthorizer.setPermission(" + toString(entity) + ", " + permission + ", " + ugi + ")");
- }
-
- yarnAcl.put(entity, permission);
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerYarnAuthorizer.setPermission(" + toString(entity) + ", " + permission + ", " + ugi + ")");
- }
- }
-
- public boolean isAllowedByYarnAcl(AccessType accessType, PrivilegedEntity entity, UserGroupInformation ugi, RangerYarnAuditHandler auditHandler) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerYarnAuthorizer.isAllowedByYarnAcl(" + accessType + ", " + toString(entity) + ", " + ugi + ")");
- }
-
- boolean ret = false;
-
- for(Map.Entry<PrivilegedEntity, Map<AccessType, AccessControlList>> e : yarnAcl.entrySet()) {
- PrivilegedEntity aclEntity = e.getKey();
- Map<AccessType, AccessControlList> entityPermissions = e.getValue();
-
- AccessControlList acl = entityPermissions == null ? null : entityPermissions.get(accessType);
-
- if(acl == null || !acl.isUserAllowed(ugi)) {
- continue;
- }
-
- if(! isSelfOrChildOf(entity, aclEntity)) {
- continue;
- }
-
- ret = true;
-
- break;
- }
-
- if(auditHandler != null) {
- auditHandler.logYarnAclEvent(ret);
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerYarnAuthorizer.isAllowedByYarnAcl(" + accessType + ", " + toString(entity) + ", " + ugi + "): " + ret);
- }
-
- return ret;
- }
-
- private static String getRangerAccessType(AccessType accessType) {
- String ret = null;
-
- switch(accessType) {
- case ADMINISTER_QUEUE:
- ret = RangerYarnAuthorizer.ACCESS_TYPE_ADMIN_QUEUE;
- break;
-
- case SUBMIT_APP:
- ret = RangerYarnAuthorizer.ACCESS_TYPE_SUBMIT_APP;
- break;
- }
-
- return ret;
- }
-
- private boolean isSelfOrChildOf(PrivilegedEntity queue, PrivilegedEntity parentQueue) {
- boolean ret = queue.equals(parentQueue);
-
- if(!ret && queue.getType() == EntityType.QUEUE) {
- String queueName = queue.getName();
- String parentQueueName = parentQueue.getName();
-
- if(queueName.contains(".") && !StringUtil.isEmpty(parentQueueName)) {
- if(parentQueueName.charAt(parentQueueName.length() - 1) != '.') {
- parentQueueName += ".";
- }
-
- ret = queueName.startsWith(parentQueueName);
- }
- }
-
- return ret;
- }
-
- private String toString(PrivilegedEntity entity) {
- if(entity != null) {
- return "{name=" + entity.getName() + "; type=" + entity.getType() + "}";
- }
-
- return "null";
- }
-}
-
-class RangerYarnPlugin extends RangerBasePlugin {
- public RangerYarnPlugin() {
- super("yarn", "yarn");
- }
-
- @Override
- public void init() {
- super.init();
-
- RangerDefaultAuditHandler auditHandler = new RangerDefaultAuditHandler();
-
- super.setResultProcessor(auditHandler);
- }
-}
-
-class RangerYarnResource extends RangerAccessResourceImpl {
- private static final String KEY_QUEUE = "queue";
-
- public RangerYarnResource(PrivilegedEntity entity) {
- setValue(KEY_QUEUE, entity != null ? entity.getName() : null);
- }
-}
-
-class RangerYarnAccessRequest extends RangerAccessRequestImpl {
- public RangerYarnAccessRequest(PrivilegedEntity entity, String accessType, String action, UserGroupInformation ugi) {
- super.setResource(new RangerYarnResource(entity));
- super.setAccessType(accessType);
- super.setUser(ugi.getShortUserName());
- super.setUserGroups(Sets.newHashSet(ugi.getGroupNames()));
- super.setAccessTime(StringUtil.getUTCDate());
- super.setClientIPAddress(getRemoteIp());
- super.setAction(accessType);
- }
-
- private static String getRemoteIp() {
- String ret = null ;
- InetAddress ip = Server.getRemoteIp() ;
- if (ip != null) {
- ret = ip.getHostAddress();
- }
- return ret ;
- }
-}
-
-class RangerYarnAuditHandler extends RangerDefaultAuditHandler {
- private static final Log LOG = LogFactory.getLog(RangerYarnAuditHandler.class);
-
- private static final String YarnModuleName = RangerConfiguration.getInstance().get(RangerHadoopConstants.AUDITLOG_YARN_MODULE_ACL_NAME_PROP , RangerHadoopConstants.DEFAULT_YARN_MODULE_ACL_NAME) ;
-
- private boolean isAuditEnabled = false;
- private AuthzAuditEvent auditEvent = null;
-
- public RangerYarnAuditHandler() {
- }
-
- @Override
- public void processResult(RangerAccessResult result) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerYarnAuditHandler.logAudit(" + result + ")");
- }
-
- if(! isAuditEnabled && result.getIsAudited()) {
- isAuditEnabled = true;
- }
-
- auditEvent = super.getAuthzEvents(result);
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerYarnAuditHandler.logAudit(" + result + "): " + auditEvent);
- }
- }
-
- public void logYarnAclEvent(boolean accessGranted) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerYarnAuditHandler.logYarnAclEvent(" + accessGranted + ")");
- }
-
- if(auditEvent != null) {
- auditEvent.setAccessResult((short) (accessGranted ? 1 : 0));
- auditEvent.setAclEnforcer(YarnModuleName);
- auditEvent.setPolicyId(-1);
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerYarnAuditHandler.logYarnAclEvent(" + accessGranted + "): " + auditEvent);
- }
- }
-
- public void flushAudit() {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerYarnAuditHandler.flushAudit(" + isAuditEnabled + ", " + auditEvent + ")");
- }
-
- if(isAuditEnabled) {
- super.logAuthzAudit(auditEvent);
- }
-
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerYarnAuditHandler.flushAudit(" + isAuditEnabled + ", " + auditEvent + ")");
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/plugin-yarn/src/main/java/org/apache/ranger/authorization/yarn/authorizer/RangerYarnAuthorizerImpl.java
----------------------------------------------------------------------
diff --git a/plugin-yarn/src/main/java/org/apache/ranger/authorization/yarn/authorizer/RangerYarnAuthorizerImpl.java b/plugin-yarn/src/main/java/org/apache/ranger/authorization/yarn/authorizer/RangerYarnAuthorizerImpl.java
new file mode 100644
index 0000000..d154539
--- /dev/null
+++ b/plugin-yarn/src/main/java/org/apache/ranger/authorization/yarn/authorizer/RangerYarnAuthorizerImpl.java
@@ -0,0 +1,354 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.authorization.yarn.authorizer;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.ipc.Server;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.security.authorize.AccessControlList;
+import org.apache.hadoop.yarn.security.*;
+import org.apache.hadoop.yarn.security.PrivilegedEntity.EntityType;
+import org.apache.ranger.audit.model.AuthzAuditEvent;
+import org.apache.ranger.authorization.hadoop.config.RangerConfiguration;
+import org.apache.ranger.authorization.hadoop.constants.RangerHadoopConstants;
+import org.apache.ranger.authorization.utils.StringUtil;
+import org.apache.ranger.plugin.audit.RangerDefaultAuditHandler;
+import org.apache.ranger.plugin.policyengine.RangerAccessRequestImpl;
+import org.apache.ranger.plugin.policyengine.RangerAccessResult;
+import org.apache.ranger.plugin.policyengine.RangerAccessResourceImpl;
+import org.apache.ranger.plugin.service.RangerBasePlugin;
+
+import com.google.common.collect.Sets;
+
+public class RangerYarnAuthorizerImpl extends YarnAuthorizationProvider {
+ public static final String ACCESS_TYPE_ADMIN_QUEUE = "admin-queue";
+ public static final String ACCESS_TYPE_SUBMIT_APP = "submit-app";
+ public static final String ACCESS_TYPE_ADMIN = "admin";
+
+ private static boolean yarnAuthEnabled = RangerHadoopConstants.RANGER_ADD_YARN_PERMISSION_DEFAULT;
+
+ private static final Log LOG = LogFactory.getLog(RangerYarnAuthorizerImpl.class);
+
+ private static volatile RangerYarnPlugin yarnPlugin = null;
+
+ private AccessControlList admins = null;
+ private Map<PrivilegedEntity, Map<AccessType, AccessControlList>> yarnAcl = new HashMap<PrivilegedEntity, Map<AccessType, AccessControlList>>();
+
+ @Override
+ public void init(Configuration conf) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerYarnAuthorizer.init()");
+ }
+
+ RangerYarnPlugin plugin = yarnPlugin;
+
+ if(plugin == null) {
+ synchronized(RangerYarnAuthorizerImpl.class) {
+ plugin = yarnPlugin;
+
+ if(plugin == null) {
+ plugin = new RangerYarnPlugin();
+ plugin.init();
+
+ yarnPlugin = plugin;
+ }
+ }
+ }
+
+ RangerYarnAuthorizerImpl.yarnAuthEnabled = RangerConfiguration.getInstance().getBoolean(RangerHadoopConstants.RANGER_ADD_YARN_PERMISSION_PROP, RangerHadoopConstants.RANGER_ADD_YARN_PERMISSION_DEFAULT);
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerYarnAuthorizer.init()");
+ }
+ }
+
+ @Override
+ public boolean checkPermission(AccessType accessType, PrivilegedEntity entity, UserGroupInformation ugi) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerYarnAuthorizer.checkPermission(" + accessType + ", " + toString(entity) + ", " + ugi + ")");
+ }
+
+ boolean ret = false;
+ RangerYarnPlugin plugin = yarnPlugin;
+ RangerYarnAuditHandler auditHandler = null;
+ RangerAccessResult result = null;
+
+ if(plugin != null) {
+ RangerYarnAccessRequest request = new RangerYarnAccessRequest(entity, getRangerAccessType(accessType), accessType.name(), ugi);
+
+ auditHandler = new RangerYarnAuditHandler();
+
+ result = plugin.isAccessAllowed(request, auditHandler);
+ }
+
+ if(RangerYarnAuthorizerImpl.yarnAuthEnabled && (result == null || !result.getIsAccessDetermined())) {
+ ret = isAllowedByYarnAcl(accessType, entity, ugi, auditHandler);
+ } else {
+ ret = result == null ? false : result.getIsAllowed();
+ }
+
+ if(auditHandler != null) {
+ auditHandler.flushAudit();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerYarnAuthorizer.checkPermission(" + accessType + ", " + toString(entity) + ", " + ugi + "): " + ret);
+ }
+
+ return ret;
+ }
+
+ @Override
+ public boolean isAdmin(UserGroupInformation ugi) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerYarnAuthorizer.isAdmin(" + ugi + ")");
+ }
+
+ boolean ret = false;
+
+ AccessControlList admins = this.admins;
+
+ if(admins != null) {
+ ret = admins.isUserAllowed(ugi);
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerYarnAuthorizer.isAdmin(" + ugi + "): " + ret);
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void setAdmins(AccessControlList acl, UserGroupInformation ugi) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerYarnAuthorizer.setAdmins(" + acl + ", " + ugi + ")");
+ }
+
+ admins = acl;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerYarnAuthorizer.setAdmins(" + acl + ", " + ugi + ")");
+ }
+ }
+
+ @Override
+ public void setPermission(PrivilegedEntity entity, Map<AccessType, AccessControlList> permission, UserGroupInformation ugi) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerYarnAuthorizer.setPermission(" + toString(entity) + ", " + permission + ", " + ugi + ")");
+ }
+
+ yarnAcl.put(entity, permission);
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerYarnAuthorizer.setPermission(" + toString(entity) + ", " + permission + ", " + ugi + ")");
+ }
+ }
+
+ public boolean isAllowedByYarnAcl(AccessType accessType, PrivilegedEntity entity, UserGroupInformation ugi, RangerYarnAuditHandler auditHandler) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerYarnAuthorizer.isAllowedByYarnAcl(" + accessType + ", " + toString(entity) + ", " + ugi + ")");
+ }
+
+ boolean ret = false;
+
+ for(Map.Entry<PrivilegedEntity, Map<AccessType, AccessControlList>> e : yarnAcl.entrySet()) {
+ PrivilegedEntity aclEntity = e.getKey();
+ Map<AccessType, AccessControlList> entityPermissions = e.getValue();
+
+ AccessControlList acl = entityPermissions == null ? null : entityPermissions.get(accessType);
+
+ if(acl == null || !acl.isUserAllowed(ugi)) {
+ continue;
+ }
+
+ if(! isSelfOrChildOf(entity, aclEntity)) {
+ continue;
+ }
+
+ ret = true;
+
+ break;
+ }
+
+ if(auditHandler != null) {
+ auditHandler.logYarnAclEvent(ret);
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerYarnAuthorizer.isAllowedByYarnAcl(" + accessType + ", " + toString(entity) + ", " + ugi + "): " + ret);
+ }
+
+ return ret;
+ }
+
+ private static String getRangerAccessType(AccessType accessType) {
+ String ret = null;
+
+ switch(accessType) {
+ case ADMINISTER_QUEUE:
+ ret = RangerYarnAuthorizerImpl.ACCESS_TYPE_ADMIN_QUEUE;
+ break;
+
+ case SUBMIT_APP:
+ ret = RangerYarnAuthorizerImpl.ACCESS_TYPE_SUBMIT_APP;
+ break;
+ }
+
+ return ret;
+ }
+
+ private boolean isSelfOrChildOf(PrivilegedEntity queue, PrivilegedEntity parentQueue) {
+ boolean ret = queue.equals(parentQueue);
+
+ if(!ret && queue.getType() == EntityType.QUEUE) {
+ String queueName = queue.getName();
+ String parentQueueName = parentQueue.getName();
+
+ if(queueName.contains(".") && !StringUtil.isEmpty(parentQueueName)) {
+ if(parentQueueName.charAt(parentQueueName.length() - 1) != '.') {
+ parentQueueName += ".";
+ }
+
+ ret = queueName.startsWith(parentQueueName);
+ }
+ }
+
+ return ret;
+ }
+
+ private String toString(PrivilegedEntity entity) {
+ if(entity != null) {
+ return "{name=" + entity.getName() + "; type=" + entity.getType() + "}";
+ }
+
+ return "null";
+ }
+}
+
+class RangerYarnPlugin extends RangerBasePlugin {
+ public RangerYarnPlugin() {
+ super("yarn", "yarn");
+ }
+
+ @Override
+ public void init() {
+ super.init();
+
+ RangerDefaultAuditHandler auditHandler = new RangerDefaultAuditHandler();
+
+ super.setResultProcessor(auditHandler);
+ }
+}
+
+class RangerYarnResource extends RangerAccessResourceImpl {
+ private static final String KEY_QUEUE = "queue";
+
+ public RangerYarnResource(PrivilegedEntity entity) {
+ setValue(KEY_QUEUE, entity != null ? entity.getName() : null);
+ }
+}
+
+class RangerYarnAccessRequest extends RangerAccessRequestImpl {
+ public RangerYarnAccessRequest(PrivilegedEntity entity, String accessType, String action, UserGroupInformation ugi) {
+ super.setResource(new RangerYarnResource(entity));
+ super.setAccessType(accessType);
+ super.setUser(ugi.getShortUserName());
+ super.setUserGroups(Sets.newHashSet(ugi.getGroupNames()));
+ super.setAccessTime(StringUtil.getUTCDate());
+ super.setClientIPAddress(getRemoteIp());
+ super.setAction(accessType);
+ }
+
+ private static String getRemoteIp() {
+ String ret = null ;
+ InetAddress ip = Server.getRemoteIp() ;
+ if (ip != null) {
+ ret = ip.getHostAddress();
+ }
+ return ret ;
+ }
+}
+
+class RangerYarnAuditHandler extends RangerDefaultAuditHandler {
+ private static final Log LOG = LogFactory.getLog(RangerYarnAuditHandler.class);
+
+ private static final String YarnModuleName = RangerConfiguration.getInstance().get(RangerHadoopConstants.AUDITLOG_YARN_MODULE_ACL_NAME_PROP , RangerHadoopConstants.DEFAULT_YARN_MODULE_ACL_NAME) ;
+
+ private boolean isAuditEnabled = false;
+ private AuthzAuditEvent auditEvent = null;
+
+ public RangerYarnAuditHandler() {
+ }
+
+ @Override
+ public void processResult(RangerAccessResult result) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerYarnAuditHandler.logAudit(" + result + ")");
+ }
+
+ if(! isAuditEnabled && result.getIsAudited()) {
+ isAuditEnabled = true;
+ }
+
+ auditEvent = super.getAuthzEvents(result);
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerYarnAuditHandler.logAudit(" + result + "): " + auditEvent);
+ }
+ }
+
+ public void logYarnAclEvent(boolean accessGranted) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerYarnAuditHandler.logYarnAclEvent(" + accessGranted + ")");
+ }
+
+ if(auditEvent != null) {
+ auditEvent.setAccessResult((short) (accessGranted ? 1 : 0));
+ auditEvent.setAclEnforcer(YarnModuleName);
+ auditEvent.setPolicyId(-1);
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerYarnAuditHandler.logYarnAclEvent(" + accessGranted + "): " + auditEvent);
+ }
+ }
+
+ public void flushAudit() {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerYarnAuditHandler.flushAudit(" + isAuditEnabled + ", " + auditEvent + ")");
+ }
+
+ if(isAuditEnabled) {
+ super.logAuthzAudit(auditEvent);
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerYarnAuditHandler.flushAudit(" + isAuditEnabled + ", " + auditEvent + ")");
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 0ccf12e..2452785 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,8 +14,7 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache</groupId>
@@ -97,6 +96,15 @@
<module>unixauthservice</module>
<module>ranger-util</module>
<module>plugin-kms</module>
+ <module>plugin-kafka</module>
+ <module>ranger-hdfs-plugin-shim</module>
+ <module>ranger-plugin-classloader</module>
+ <module>ranger-hive-plugin-shim</module>
+ <module>ranger-hbase-plugin-shim</module>
+ <module>ranger-knox-plugin-shim</module>
+ <module>ranger-yarn-plugin-shim</module>
+ <module>ranger-storm-plugin-shim</module>
+ <module>ranger-kafka-plugin-shim</module>
</modules>
<properties>
<javac.source.version>1.7</javac.source.version>
@@ -150,8 +158,9 @@
<jersey-bundle.version>1.17.1</jersey-bundle.version>
<jersey-client.version>2.6</jersey-client.version>
<junit.version>4.11</junit.version>
- <kafka.version>0.8.2.0</kafka.version>
- <!-- <kafka.version>0.8.2.2.3.0.0-2208</kafka.version> -->
+ <!-- <kafka.version>0.8.2.0</kafka.version> -->
+ <!-- <kafka.version>0.8.2.2.3.0.0-2320</kafka.version> -->
+ <kafka.version>0.8.2.2.3.2.0-2950</kafka.version>
<mockito.version>1.8.4</mockito.version>
<hamcrest-version>1.3</hamcrest-version>
<knox.gateway.version>0.6.0</knox.gateway.version>
@@ -505,7 +514,7 @@
<phase>process-resources</phase>
<configuration>
<target>
- <echo message="${project.version}" file="${project.build.directory}/version" />
+ <echo message="${project.version}" file="${project.build.directory}/version"/>
</target>
</configuration>
<goals>
@@ -524,4 +533,4 @@
</plugin>
</plugins>
</build>
-</project>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-hbase-plugin-shim/pom.xml
----------------------------------------------------------------------
diff --git a/ranger-hbase-plugin-shim/pom.xml b/ranger-hbase-plugin-shim/pom.xml
new file mode 100644
index 0000000..c95075b
--- /dev/null
+++ b/ranger-hbase-plugin-shim/pom.xml
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>security_plugins.ranger-hbase-plugin-shim</groupId>
+ <artifactId>ranger-hbase-plugin-shim</artifactId>
+ <name>HBase Security Plugin Shim</name>
+ <description>HBase Security Plugins Shim</description>
+ <packaging>jar</packaging>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <parent>
+ <groupId>org.apache.ranger</groupId>
+ <artifactId>ranger</artifactId>
+ <version>0.5.0</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.hbase</groupId>
+ <artifactId>hbase-server</artifactId>
+ <version>${hbase.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-hdfs</artifactId>
+ <version>${hadoop.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugins-common</groupId>
+ <artifactId>ranger-plugins-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugins-audit</groupId>
+ <artifactId>ranger-plugins-audit</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugin-classloader</groupId>
+ <artifactId>ranger-plugin-classloader</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-hbase-plugin</groupId>
+ <artifactId>ranger-hbase-plugin</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-integration</artifactId>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-hbase-plugin-shim/src/main/java/com/xasecure/authorization/hbase/XaSecureAuthorizationCoprocessor.java
----------------------------------------------------------------------
diff --git a/ranger-hbase-plugin-shim/src/main/java/com/xasecure/authorization/hbase/XaSecureAuthorizationCoprocessor.java b/ranger-hbase-plugin-shim/src/main/java/com/xasecure/authorization/hbase/XaSecureAuthorizationCoprocessor.java
new file mode 100644
index 0000000..bc01e51
--- /dev/null
+++ b/ranger-hbase-plugin-shim/src/main/java/com/xasecure/authorization/hbase/XaSecureAuthorizationCoprocessor.java
@@ -0,0 +1,33 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.xasecure.authorization.hbase;
+
+import org.apache.hadoop.hbase.coprocessor.CoprocessorService;
+import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.AccessControlService;
+import org.apache.ranger.authorization.hbase.RangerAuthorizationCoprocessor;
+/**
+ * This class exists only to provide for seamless upgrade/downgrade capabilities. Coprocessor name is in hbase config files in /etc/.../conf which
+ * is not only out of bounds for any upgrade script but also must be of a form to allow for downgrad! Thus when class names were changed XaSecure* -> Ranger*
+ * this shell class serves to allow for seamles upgrade as well as downgrade.
+ *
+ * This class is final because if one needs to customize coprocessor it is expected that RangerAuthorizationCoprocessor would be modified/extended as that is
+ * the "real" coprocessor! This class, hence, should NEVER be more than an EMPTY shell!
+ */
+public final class XaSecureAuthorizationCoprocessor extends RangerAuthorizationCoprocessor implements AccessControlService.Interface, CoprocessorService {
+}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-hbase-plugin-shim/src/main/java/org/apache/hadoop/hbase/security/access/RangerAccessControlLists.java
----------------------------------------------------------------------
diff --git a/ranger-hbase-plugin-shim/src/main/java/org/apache/hadoop/hbase/security/access/RangerAccessControlLists.java b/ranger-hbase-plugin-shim/src/main/java/org/apache/hadoop/hbase/security/access/RangerAccessControlLists.java
new file mode 100644
index 0000000..7f33b15
--- /dev/null
+++ b/ranger-hbase-plugin-shim/src/main/java/org/apache/hadoop/hbase/security/access/RangerAccessControlLists.java
@@ -0,0 +1,104 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.security.access;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.hadoop.hbase.TableExistsException;
+import org.apache.hadoop.hbase.master.MasterServices;
+import org.apache.log4j.Logger;
+
+
+public class RangerAccessControlLists {
+
+ private static final Logger LOG = Logger.getLogger(RangerAccessControlLists.class) ;
+
+ public static void init(MasterServices master) throws IOException {
+
+ Class<AccessControlLists> accessControlListsClass = AccessControlLists.class ;
+ String cName = accessControlListsClass.getName() ;
+
+ Class<?>[] params = new Class[1] ;
+ params[0] = MasterServices.class ;
+
+ for (String mname : new String[] { "init", "createACLTable" } ) {
+ try {
+ try {
+ Method m = accessControlListsClass.getDeclaredMethod(mname, params) ;
+ if (m != null) {
+ try {
+
+ try {
+ m.invoke(null, master) ;
+ logInfo("Execute method name [" + mname + "] in Class [" + cName + "] is successful.");
+ } catch (InvocationTargetException e) {
+ Throwable cause = e ;
+ boolean tableExistsExceptionFound = false ;
+ if (e != null) {
+ Throwable ecause = e.getTargetException() ;
+ if (ecause != null) {
+ cause = ecause ;
+ if (ecause instanceof TableExistsException) {
+ tableExistsExceptionFound = true ;
+ }
+ }
+ }
+ if (! tableExistsExceptionFound) {
+ logError("Unable to execute the method [" + mname + "] on [" + cName + "] due to exception", cause) ;
+ throw new IOException(cause) ;
+ }
+ }
+ return ;
+ } catch (IllegalArgumentException e) {
+ logError("Unable to execute method name [" + mname + "] in Class [" + cName + "].", e);
+ throw new IOException(e) ;
+ } catch (IllegalAccessException e) {
+ logError("Unable to execute method name [" + mname + "] in Class [" + cName + "].", e);
+ throw new IOException(e) ;
+ }
+ }
+ }
+ catch(NoSuchMethodException nsme) {
+ logInfo("Unable to get method name [" + mname + "] in Class [" + cName + "]. Ignoring the exception");
+ }
+ } catch (SecurityException e) {
+ logError("Unable to get method name [" + mname + "] in Class [" + cName + "].", e);
+ throw new IOException(e) ;
+ }
+ }
+ throw new IOException("Unable to initialize() [" + cName + "]") ;
+ }
+
+
+ private static void logInfo(String msg) {
+ // System.out.println(msg) ;
+ LOG.info(msg) ;
+ }
+
+ private static void logError(String msg, Throwable t) {
+// System.err.println(msg) ;
+// if (t != null) {
+// t.printStackTrace(System.err);
+// }
+ LOG.error(msg, t);
+ }
+
+}
[6/6] incubator-ranger git commit: RANGER-586: Ranger plugins should
not add dependent libraries to component's CLASSPATH
Posted by rm...@apache.org.
RANGER-586: Ranger plugins should not add dependent libraries to component's CLASSPATH
Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/ebe83454
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/ebe83454
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/ebe83454
Branch: refs/heads/ranger-rmani
Commit: ebe83454b9b62d6d17ed0d097bb5b6a98ce5301a
Parents: 6f75871
Author: rmani <rm...@hortonworks.com>
Authored: Wed Oct 21 17:02:02 2015 -0700
Committer: rmani <rm...@hortonworks.com>
Committed: Wed Oct 21 17:02:02 2015 -0700
----------------------------------------------------------------------
agents-common/scripts/enable-agent.sh | 25 +-
hbase-agent/conf/ranger-hbase-security.xml | 16 +
.../hbase/XaSecureAuthorizationCoprocessor.java | 35 -
.../access/RangerAccessControlLists.java | 104 -
.../hbase/RangerAuthorizationCoprocessor.java | 1391 -------
.../RangerAuthorizationCoprocessorImpl.java | 1393 +++++++
.../access/RangerAccessControlListsTest.java | 4 +-
.../RangerAuthorizationCoprocessorTest.java | 4 +-
hdfs-agent/conf/ranger-hdfs-security.xml | 19 +
.../hadoop/RangerHdfsAuthorizer.java | 538 ---
.../hadoop/RangerHdfsAuthorizerImpl.java | 538 +++
hive-agent/conf/ranger-hive-security.xml | 16 +
.../XaSecureHiveAuthorizerFactory.java | 4 +-
.../authorizer/RangerHiveAuthorizerFactory.java | 39 -
.../RangerHiveAuthorizerFactoryImpl.java | 40 +
.../pdp/knox/filter/XASecurePDPKnoxFilter.java | 25 -
plugin-kafka/conf/ranger-kafka-security.xml | 1 +
plugin-kafka/pom.xml | 5 +
.../kafka/authorizer/RangerKafkaAuthorizer.java | 281 --
.../authorizer/RangerKafkaAuthorizerImpl.java | 277 ++
plugin-kms/conf/ranger-kms-security.xml | 5 +-
.../yarn/authorizer/RangerYarnAuthorizer.java | 354 --
.../authorizer/RangerYarnAuthorizerImpl.java | 354 ++
pom.xml | 21 +-
ranger-hbase-plugin-shim/pom.xml | 78 +
.../hbase/XaSecureAuthorizationCoprocessor.java | 33 +
.../access/RangerAccessControlLists.java | 104 +
.../hbase/RangerAuthorizationCoprocessor.java | 3702 ++++++++++++++++++
.../dependency-reduced-pom.xml | 188 +
ranger-hdfs-plugin-shim/pom.xml | 74 +
.../hadoop/RangerHdfsAuthorizer.java | 197 +
ranger-hive-plugin-shim/pom.xml | 105 +
.../XaSecureHiveAuthorizerFactory.java | 32 +
.../authorizer/RangerHiveAuthorizerFactory.java | 126 +
ranger-kafka-plugin-shim/pom.xml | 56 +
.../kafka/authorizer/RangerKafkaAuthorizer.java | 248 ++
ranger-knox-plugin-shim/pom.xml | 91 +
.../pdp/knox/filter/XASecurePDPKnoxFilter.java | 25 +
.../authorization/knox/RangerPDPKnoxFilter.java | 153 +
ranger-plugin-classloader/pom.xml | 39 +
.../classloader/RangerPluginClassLoader.java | 290 ++
.../RangerPluginClassLoaderUtil.java | 165 +
.../classloader/RangerPluginProxyGenerator.java | 91 +
.../test/Impl/TestChildFistClassLoader.java | 56 +
.../classloader/test/Impl/TestPluginImpl.java | 32 +
.../plugin/classloader/test/Impl/TestPrint.java | 28 +
.../plugin/classloader/test/TestPlugin.java | 24 +
.../classloader/test/TestPrintParent.java | 29 +
ranger-storm-plugin-shim/pom.xml | 81 +
.../authorizer/XaSecureStormAuthorizer.java | 32 +
.../storm/authorizer/RangerStormAuthorizer.java | 138 +
ranger-yarn-plugin-shim/pom.xml | 66 +
.../yarn/authorizer/RangerYarnAuthorizer.java | 205 +
src/main/assembly/hbase-agent.xml | 25 +-
src/main/assembly/hdfs-agent.xml | 65 +-
src/main/assembly/hive-agent.xml | 25 +-
src/main/assembly/knox-agent.xml | 23 +-
src/main/assembly/plugin-kafka.xml | 40 +-
src/main/assembly/plugin-yarn.xml | 24 +-
src/main/assembly/storm-agent.xml | 23 +-
.../authorizer/XaSecureStormAuthorizer.java | 32 -
.../storm/authorizer/RangerStormAuthorizer.java | 148 -
.../authorizer/RangerStormAuthorizerImpl.java | 148 +
63 files changed, 9501 insertions(+), 3029 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/agents-common/scripts/enable-agent.sh
----------------------------------------------------------------------
diff --git a/agents-common/scripts/enable-agent.sh b/agents-common/scripts/enable-agent.sh
index f3db125..ac0d26d 100755
--- a/agents-common/scripts/enable-agent.sh
+++ b/agents-common/scripts/enable-agent.sh
@@ -121,6 +121,9 @@ INSTALL_ARGS="${PROJ_INSTALL_DIR}/install.properties"
COMPONENT_INSTALL_ARGS="${PROJ_INSTALL_DIR}/${COMPONENT_NAME}-install.properties"
JAVA=$JAVA_HOME/bin/java
+PLUGIN_DEPENDENT_LIB_DIR=lib/"${PROJ_NAME}-${COMPONENT_NAME}-impl"
+PROJ_LIB_PLUGIN_DIR=${PROJ_INSTALL_DIR}/${PLUGIN_DEPENDENT_LIB_DIR}
+
HCOMPONENT_INSTALL_DIR_NAME=$(getInstallProperty 'COMPONENT_INSTALL_DIR_NAME')
@@ -173,12 +176,15 @@ fi
#
HCOMPONENT_INSTALL_DIR=`(cd ${hdir} ; pwd)`
HCOMPONENT_LIB_DIR=${HCOMPONENT_INSTALL_DIR}/lib
+HCOMPONENT_PLUGIN_DEPENDENT_LIB_DIR=${HCOMPONENT_LIB_DIR}/"${PROJ_NAME}-${COMPONENT_NAME}-impl"
if [ "${HCOMPONENT_NAME}" = "knox" ]; then
HCOMPONENT_LIB_DIR=${HCOMPONENT_INSTALL_DIR}/ext
elif [ "${HCOMPONENT_NAME}" = "solr" ]; then
HCOMPONENT_LIB_DIR=${HCOMPONENT_INSTALL_DIR}/solr-webapp/webapp/WEB-INF/lib
elif [ "${HCOMPONENT_NAME}" = "kafka" ]; then
HCOMPONENT_LIB_DIR=${HCOMPONENT_INSTALL_DIR}/libs
+elif [ "${HCOMPONENT_NAME}" = "storm" ]; then
+ HCOMPONENT_LIB_DIR=${HCOMPONENT_INSTALL_DIR}/extlib-daemon
fi
HCOMPONENT_CONF_DIR=${HCOMPONENT_INSTALL_DIR}/conf
@@ -496,8 +502,7 @@ then
#if [ -d "${PROJ_LIB_DIR}" ]
#then
dt=`date '+%Y%m%d%H%M%S'`
- dbJar=$(getInstallProperty 'SQL_CONNECTOR_JAR')
- for f in ${PROJ_LIB_DIR}/*.jar ${dbJar}
+ for f in ${PROJ_LIB_DIR}/*.jar
do
if [ -f "${f}" ]
then
@@ -513,6 +518,22 @@ then
fi
fi
done
+
+ # ADD SQL CONNECTOR JAR TO PLUGIN DEPENDENCY JAR FOLDER
+ dbJar=$(getInstallProperty 'SQL_CONNECTOR_JAR')
+ if [ -f "${dbJar}" ]
+ then
+ bn=`basename ${dbJar}`
+ if [ -f ${PROJ_LIB_PLUGIN_DIR}/${bn} ]
+ then
+ rm ${PROJ_LIB_PLUGIN_DIR}/${bn}
+ fi
+ if [ ! -f ${PROJ_LIB_PLUGIN_DIR}/${bn} ]
+ then
+ ln -s ${dbJar} ${PROJ_LIB_PLUGIN_DIR}/${bn}
+ fi
+ fi
+
#fi
#
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/hbase-agent/conf/ranger-hbase-security.xml
----------------------------------------------------------------------
diff --git a/hbase-agent/conf/ranger-hbase-security.xml b/hbase-agent/conf/ranger-hbase-security.xml
index 08716ea..3c66b97 100644
--- a/hbase-agent/conf/ranger-hbase-security.xml
+++ b/hbase-agent/conf/ranger-hbase-security.xml
@@ -64,6 +64,22 @@
Directory where Ranger policies are cached after successful retrieval from the source
</description>
</property>
+
+ <property>
+ <name>ranger.policy.rest.client.connection.timeoutMs</name>
+ <value>120000</value>
+ <description>
+ RangerRestClient Connection Timeout in Milli Seconds
+ </description>
+ </property>
+
+ <property>
+ <name>ranger.policy.rest.client.read.timeoutMs</name>
+ <value>30000</value>
+ <description>
+ RangerRestClient read Timeout in Milli Seconds
+ </description>
+ </property>
<property>
<name>xasecure.hbase.update.xapolicies.on.grant.revoke</name>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/hbase-agent/src/main/java/com/xasecure/authorization/hbase/XaSecureAuthorizationCoprocessor.java
----------------------------------------------------------------------
diff --git a/hbase-agent/src/main/java/com/xasecure/authorization/hbase/XaSecureAuthorizationCoprocessor.java b/hbase-agent/src/main/java/com/xasecure/authorization/hbase/XaSecureAuthorizationCoprocessor.java
deleted file mode 100644
index 574a07c..0000000
--- a/hbase-agent/src/main/java/com/xasecure/authorization/hbase/XaSecureAuthorizationCoprocessor.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.xasecure.authorization.hbase;
-
-import org.apache.hadoop.hbase.coprocessor.CoprocessorService;
-import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos;
-import org.apache.ranger.authorization.hbase.RangerAuthorizationCoprocessor;
-
-/**
- * This class exists only to provide for seamless upgrade/downgrade capabilities. Coprocessor name is in hbase config files in /etc/.../conf which
- * is not only out of bounds for any upgrade script but also must be of a form to allow for downgrad! Thus when class names were changed XaSecure* -> Ranger*
- * this shell class serves to allow for seamles upgrade as well as downgrade.
- *
- * This class is final because if one needs to customize coprocessor it is expected that RangerAuthorizationCoprocessor would be modified/extended as that is
- * the "real" coprocessor! This class, hence, should NEVER be more than an EMPTY shell!
- */
-public final class XaSecureAuthorizationCoprocessor extends RangerAuthorizationCoprocessor implements AccessControlProtos.AccessControlService.Interface, CoprocessorService {
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/hbase-agent/src/main/java/org/apache/hadoop/hbase/security/access/RangerAccessControlLists.java
----------------------------------------------------------------------
diff --git a/hbase-agent/src/main/java/org/apache/hadoop/hbase/security/access/RangerAccessControlLists.java b/hbase-agent/src/main/java/org/apache/hadoop/hbase/security/access/RangerAccessControlLists.java
deleted file mode 100644
index 7f33b15..0000000
--- a/hbase-agent/src/main/java/org/apache/hadoop/hbase/security/access/RangerAccessControlLists.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.hbase.security.access;
-
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import org.apache.hadoop.hbase.TableExistsException;
-import org.apache.hadoop.hbase.master.MasterServices;
-import org.apache.log4j.Logger;
-
-
-public class RangerAccessControlLists {
-
- private static final Logger LOG = Logger.getLogger(RangerAccessControlLists.class) ;
-
- public static void init(MasterServices master) throws IOException {
-
- Class<AccessControlLists> accessControlListsClass = AccessControlLists.class ;
- String cName = accessControlListsClass.getName() ;
-
- Class<?>[] params = new Class[1] ;
- params[0] = MasterServices.class ;
-
- for (String mname : new String[] { "init", "createACLTable" } ) {
- try {
- try {
- Method m = accessControlListsClass.getDeclaredMethod(mname, params) ;
- if (m != null) {
- try {
-
- try {
- m.invoke(null, master) ;
- logInfo("Execute method name [" + mname + "] in Class [" + cName + "] is successful.");
- } catch (InvocationTargetException e) {
- Throwable cause = e ;
- boolean tableExistsExceptionFound = false ;
- if (e != null) {
- Throwable ecause = e.getTargetException() ;
- if (ecause != null) {
- cause = ecause ;
- if (ecause instanceof TableExistsException) {
- tableExistsExceptionFound = true ;
- }
- }
- }
- if (! tableExistsExceptionFound) {
- logError("Unable to execute the method [" + mname + "] on [" + cName + "] due to exception", cause) ;
- throw new IOException(cause) ;
- }
- }
- return ;
- } catch (IllegalArgumentException e) {
- logError("Unable to execute method name [" + mname + "] in Class [" + cName + "].", e);
- throw new IOException(e) ;
- } catch (IllegalAccessException e) {
- logError("Unable to execute method name [" + mname + "] in Class [" + cName + "].", e);
- throw new IOException(e) ;
- }
- }
- }
- catch(NoSuchMethodException nsme) {
- logInfo("Unable to get method name [" + mname + "] in Class [" + cName + "]. Ignoring the exception");
- }
- } catch (SecurityException e) {
- logError("Unable to get method name [" + mname + "] in Class [" + cName + "].", e);
- throw new IOException(e) ;
- }
- }
- throw new IOException("Unable to initialize() [" + cName + "]") ;
- }
-
-
- private static void logInfo(String msg) {
- // System.out.println(msg) ;
- LOG.info(msg) ;
- }
-
- private static void logError(String msg, Throwable t) {
-// System.err.println(msg) ;
-// if (t != null) {
-// t.printStackTrace(System.err);
-// }
- LOG.error(msg, t);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/hbase-agent/src/main/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessor.java
----------------------------------------------------------------------
diff --git a/hbase-agent/src/main/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessor.java b/hbase-agent/src/main/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessor.java
deleted file mode 100644
index 8762bf5..0000000
--- a/hbase-agent/src/main/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessor.java
+++ /dev/null
@@ -1,1391 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.ranger.authorization.hbase;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.NavigableSet;
-import java.util.Set;
-import java.util.TimeZone;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.Cell;
-import org.apache.hadoop.hbase.CoprocessorEnvironment;
-import org.apache.hadoop.hbase.HColumnDescriptor;
-import org.apache.hadoop.hbase.HRegionInfo;
-import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.NamespaceDescriptor;
-import org.apache.hadoop.hbase.ServerName;
-import org.apache.hadoop.hbase.TableName;
-import org.apache.hadoop.hbase.client.Append;
-import org.apache.hadoop.hbase.client.Delete;
-import org.apache.hadoop.hbase.client.Durability;
-import org.apache.hadoop.hbase.client.Get;
-import org.apache.hadoop.hbase.client.Increment;
-import org.apache.hadoop.hbase.client.Put;
-import org.apache.hadoop.hbase.client.Result;
-import org.apache.hadoop.hbase.client.Scan;
-import org.apache.hadoop.hbase.coprocessor.CoprocessorException;
-import org.apache.hadoop.hbase.coprocessor.CoprocessorService;
-import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment;
-import org.apache.hadoop.hbase.coprocessor.ObserverContext;
-import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
-import org.apache.hadoop.hbase.coprocessor.RegionServerCoprocessorEnvironment;
-import org.apache.hadoop.hbase.filter.ByteArrayComparable;
-import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
-import org.apache.hadoop.hbase.filter.Filter;
-import org.apache.hadoop.hbase.filter.FilterList;
-import org.apache.hadoop.hbase.ipc.RpcServer;
-import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
-import org.apache.hadoop.hbase.protobuf.ResponseConverter;
-import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos;
-import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.AccessControlService;
-import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription;
-import org.apache.hadoop.hbase.protobuf.generated.QuotaProtos.Quotas;
-import org.apache.hadoop.hbase.protobuf.generated.SecureBulkLoadProtos.CleanupBulkLoadRequest;
-import org.apache.hadoop.hbase.protobuf.generated.SecureBulkLoadProtos.PrepareBulkLoadRequest;
-import org.apache.hadoop.hbase.regionserver.InternalScanner;
-import org.apache.hadoop.hbase.regionserver.Region;
-import org.apache.hadoop.hbase.regionserver.RegionScanner;
-import org.apache.hadoop.hbase.regionserver.ScanType;
-import org.apache.hadoop.hbase.regionserver.Store;
-import org.apache.hadoop.hbase.regionserver.StoreFile;
-import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
-import org.apache.hadoop.hbase.security.AccessDeniedException;
-import org.apache.hadoop.hbase.security.User;
-import org.apache.hadoop.hbase.security.access.Permission;
-import org.apache.hadoop.hbase.security.access.Permission.Action;
-import org.apache.hadoop.hbase.security.access.RangerAccessControlLists;
-import org.apache.hadoop.hbase.security.access.TablePermission;
-import org.apache.hadoop.hbase.security.access.UserPermission;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.Pair;
-import org.apache.hadoop.security.AccessControlException;
-import org.apache.ranger.audit.model.AuthzAuditEvent;
-import org.apache.ranger.authorization.hadoop.config.RangerConfiguration;
-import org.apache.ranger.authorization.hadoop.constants.RangerHadoopConstants;
-import org.apache.ranger.authorization.utils.StringUtil;
-import org.apache.ranger.plugin.audit.RangerDefaultAuditHandler;
-import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
-import org.apache.ranger.plugin.policyengine.RangerAccessResultProcessor;
-import org.apache.ranger.plugin.service.RangerBasePlugin;
-import org.apache.ranger.plugin.util.GrantRevokeRequest;
-
-import com.google.common.base.Objects;
-import com.google.common.collect.Lists;
-import com.google.common.collect.MapMaker;
-import com.google.protobuf.RpcCallback;
-import com.google.protobuf.RpcController;
-import com.google.protobuf.Service;
-
-public class RangerAuthorizationCoprocessor extends RangerAuthorizationCoprocessorBase implements AccessControlService.Interface, CoprocessorService {
- private static final Log LOG = LogFactory.getLog(RangerAuthorizationCoprocessor.class.getName());
- private static boolean UpdateRangerPoliciesOnGrantRevoke = RangerHadoopConstants.HBASE_UPDATE_RANGER_POLICIES_ON_GRANT_REVOKE_DEFAULT_VALUE;
- private static final String GROUP_PREFIX = "@";
-
- private static final String WILDCARD = "*";
- private static final String NAMESPACE_SEPARATOR = ":";
-
- private static final TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT+0");
-
- private RegionCoprocessorEnvironment regionEnv;
- private Map<InternalScanner, String> scannerOwners = new MapMaker().weakKeys().makeMap();
-
- /*
- * These are package level only for testability and aren't meant to be exposed outside via getters/setters or made available to derived classes.
- */
- final HbaseFactory _factory = HbaseFactory.getInstance();
- final HbaseUserUtils _userUtils = _factory.getUserUtils();
- final HbaseAuthUtils _authUtils = _factory.getAuthUtils();
- private static volatile RangerHBasePlugin hbasePlugin = null;
-
- // Utilities Methods
- protected byte[] getTableName(RegionCoprocessorEnvironment e) {
- Region region = e.getRegion();
- byte[] tableName = null;
- if (region != null) {
- HRegionInfo regionInfo = region.getRegionInfo();
- if (regionInfo != null) {
- tableName = regionInfo.getTable().getName() ;
- }
- }
- return tableName;
- }
- protected void requireSystemOrSuperUser(Configuration conf) throws IOException {
- User user = User.getCurrent();
- if (user == null) {
- throw new IOException("Unable to obtain the current user, authorization checks for internal operations will not work correctly!");
- }
- String systemUser = user.getShortName();
- User activeUser = getActiveUser();
- if (!Objects.equal(systemUser, activeUser.getShortName()) && !_userUtils.isSuperUser(activeUser)) {
- throw new AccessDeniedException("User '" + user.getShortName() + "is not system or super user.");
- }
- }
- protected boolean isSpecialTable(HRegionInfo regionInfo) {
- return isSpecialTable(regionInfo.getTable().getName());
- }
- protected boolean isSpecialTable(byte[] tableName) {
- return isSpecialTable(Bytes.toString(tableName));
- }
- protected boolean isSpecialTable(String input) {
- final String[] specialTables = new String[] { "hbase:meta", "-ROOT-", ".META."};
- for (String specialTable : specialTables ) {
- if (specialTable.equals(input)) {
- return true;
- }
- }
-
- return false;
- }
- protected boolean isAccessForMetaTables(RegionCoprocessorEnvironment env) {
- HRegionInfo hri = env.getRegion().getRegionInfo();
-
- if (hri.isMetaTable() || hri.isMetaRegion()) {
- return true;
- } else {
- return false;
- }
- }
-
- private User getActiveUser() {
- User user = RpcServer.getRequestUser();
- if (user == null) {
- // for non-rpc handling, fallback to system user
- try {
- user = User.getCurrent();
- } catch (IOException e) {
- LOG.error("Unable to find the current user");
- user = null;
- }
- }
- return user;
- }
-
- private String getRemoteAddress() {
- InetAddress remoteAddr = RpcServer.getRemoteAddress();
-
- if(remoteAddr == null) {
- remoteAddr = RpcServer.getRemoteIp();
- }
-
- String strAddr = remoteAddr != null ? remoteAddr.getHostAddress() : null;
-
- return strAddr;
- }
-
- // Methods that are used within the CoProcessor
- private void requireScannerOwner(InternalScanner s) throws AccessDeniedException {
- if (!RpcServer.isInRpcCallContext()) {
- return;
- }
-
- String requestUserName = RpcServer.getRequestUserName();
- String owner = scannerOwners.get(s);
- if (owner != null && !owner.equals(requestUserName)) {
- throw new AccessDeniedException("User '"+ requestUserName +"' is not the scanner owner!");
- }
- }
- /**
- * @param families
- * @return empty map if families is null, would never have empty or null keys, would never have null values, values could be empty (non-null) set
- */
- Map<String, Set<String>> getColumnFamilies(Map<byte[], ? extends Collection<?>> families) {
- if (families == null) {
- // null families map passed. Ok, returning empty map.
- return Collections.<String, Set<String>>emptyMap();
- }
- Map<String, Set<String>> result = new HashMap<String, Set<String>>();
- for (Map.Entry<byte[], ? extends Collection<?>> anEntry : families.entrySet()) {
- byte[] familyBytes = anEntry.getKey();
- String family = Bytes.toString(familyBytes);
- if (family == null || family.isEmpty()) {
- LOG.error("Unexpected Input: got null or empty column family (key) in families map! Ignoring...");
- } else {
- Collection<?> columnCollection = anEntry.getValue();
- if (CollectionUtils.isEmpty(columnCollection)) {
- // family points to null map, OK.
- result.put(family, Collections.<String> emptySet());
- } else {
- Iterator<String> columnIterator = new ColumnIterator(columnCollection);
- Set<String> columns = new HashSet<String>();
- while (columnIterator.hasNext()) {
- String column = columnIterator.next();
- columns.add(column);
- }
- result.put(family, columns);
- }
- }
- }
- return result;
- }
-
- static class ColumnFamilyAccessResult {
- final boolean _everythingIsAccessible;
- final boolean _somethingIsAccessible;
- final List<AuthzAuditEvent> _accessAllowedEvents;
- final List<AuthzAuditEvent> _familyLevelAccessEvents;
- final AuthzAuditEvent _accessDeniedEvent;
- final String _denialReason;
- final RangerAuthorizationFilter _filter;
-
- ColumnFamilyAccessResult(boolean everythingIsAccessible, boolean somethingIsAccessible,
- List<AuthzAuditEvent> accessAllowedEvents, List<AuthzAuditEvent> familyLevelAccessEvents, AuthzAuditEvent accessDeniedEvent, String denialReason,
- RangerAuthorizationFilter filter) {
- _everythingIsAccessible = everythingIsAccessible;
- _somethingIsAccessible = somethingIsAccessible;
- // WARNING: we are just holding on to reference of the collection. Potentially risky optimization
- _accessAllowedEvents = accessAllowedEvents;
- _familyLevelAccessEvents = familyLevelAccessEvents;
- _accessDeniedEvent = accessDeniedEvent;
- _denialReason = denialReason;
- // cached values of access results
- _filter = filter;
- }
-
- @Override
- public String toString() {
- return Objects.toStringHelper(getClass())
- .add("everythingIsAccessible", _everythingIsAccessible)
- .add("somethingIsAccessible", _somethingIsAccessible)
- .add("accessAllowedEvents", _accessAllowedEvents)
- .add("familyLevelAccessEvents", _familyLevelAccessEvents)
- .add("accessDeniedEvent", _accessDeniedEvent)
- .add("denialReason", _denialReason)
- .add("filter", _filter)
- .toString();
-
- }
- }
-
- ColumnFamilyAccessResult evaluateAccess(String operation, Action action, final RegionCoprocessorEnvironment env,
- final Map<byte[], ? extends Collection<?>> familyMap) throws AccessDeniedException {
-
- String access = _authUtils.getAccess(action);
- User user = getActiveUser();
- String userName = _userUtils.getUserAsString(user);
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(String.format("evaluateAccess: entered: user[%s], Operation[%s], access[%s], families[%s]",
- userName, operation, access, getColumnFamilies(familyMap).toString()));
- }
-
- byte[] tableBytes = getTableName(env);
- if (tableBytes == null || tableBytes.length == 0) {
- String message = "evaluateAccess: Unexpected: Couldn't get table from RegionCoprocessorEnvironment. Access denied, not audited";
- LOG.debug(message);
- throw new AccessDeniedException("Insufficient permissions for operation '" + operation + "',action: " + action);
- }
- String table = Bytes.toString(tableBytes);
-
- final String messageTemplate = "evaluateAccess: exiting: user[%s], Operation[%s], access[%s], families[%s], verdict[%s]";
- ColumnFamilyAccessResult result;
- if (canSkipAccessCheck(operation, access, table) || canSkipAccessCheck(operation, access, env)) {
- LOG.debug("evaluateAccess: exiting: isKnownAccessPattern returned true: access allowed, not audited");
- result = new ColumnFamilyAccessResult(true, true, null, null, null, null, null);
- if (LOG.isDebugEnabled()) {
- Map<String, Set<String>> families = getColumnFamilies(familyMap);
- String message = String.format(messageTemplate, userName, operation, access, families.toString(), result.toString());
- LOG.debug(message);
- }
- return result;
- }
-
- // let's create a session that would be reused. Set things on it that won't change.
- HbaseAuditHandler auditHandler = _factory.getAuditHandler();
- AuthorizationSession session = new AuthorizationSession(hbasePlugin)
- .operation(operation)
- .remoteAddress(getRemoteAddress())
- .auditHandler(auditHandler)
- .user(user)
- .access(access)
- .table(table);
- Map<String, Set<String>> families = getColumnFamilies(familyMap);
- if (LOG.isDebugEnabled()) {
- LOG.debug("evaluateAccess: families to process: " + families.toString());
- }
- if (families == null || families.isEmpty()) {
- LOG.debug("evaluateAccess: Null or empty families collection, ok. Table level access is desired");
- session.buildRequest()
- .authorize();
- boolean authorized = session.isAuthorized();
- String reason = "";
- if (authorized) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("evaluateAccess: table level access granted [" + table + "]");
- }
- } else {
- reason = String.format("Insufficient permissions for user ‘%s',action: %s, tableName:%s, no column families found.", user.getName(), operation, table);
- }
- AuthzAuditEvent event = auditHandler.getAndDiscardMostRecentEvent(); // this could be null, of course, depending on audit settings of table.
-
- // if authorized then pass captured events as access allowed set else as access denied set.
- result = new ColumnFamilyAccessResult(authorized, authorized,
- authorized ? Collections.singletonList(event) : null,
- null, authorized ? null : event, reason, null);
- if (LOG.isDebugEnabled()) {
- String message = String.format(messageTemplate, userName, operation, access, families.toString(), result.toString());
- LOG.debug(message);
- }
- return result;
- } else {
- LOG.debug("evaluateAccess: Families collection not null. Skipping table-level check, will do finer level check");
- }
-
- boolean everythingIsAccessible = true;
- boolean somethingIsAccessible = false;
- /*
- * we would have to accumulate audits of all successful accesses and any one denial (which in our case ends up being the last denial)
- * We need to keep audit events for family level access check seperate because we don't want them logged in some cases.
- */
- List<AuthzAuditEvent> authorizedEvents = new ArrayList<AuthzAuditEvent>();
- List<AuthzAuditEvent> familyLevelAccessEvents = new ArrayList<AuthzAuditEvent>();
- AuthzAuditEvent deniedEvent = null;
- String denialReason = null;
- // we need to cache the auths results so that we can create a filter, if needed
- Map<String, Set<String>> columnsAccessAllowed = new HashMap<String, Set<String>>();
- Set<String> familesAccessAllowed = new HashSet<String>();
- Set<String> familesAccessDenied = new HashSet<String>();
- Set<String> familesAccessIndeterminate = new HashSet<String>();
-
- for (Map.Entry<String, Set<String>> anEntry : families.entrySet()) {
- String family = anEntry.getKey();
- session.columnFamily(family);
- if (LOG.isDebugEnabled()) {
- LOG.debug("evaluateAccess: Processing family: " + family);
- }
- Set<String> columns = anEntry.getValue();
- if (columns == null || columns.isEmpty()) {
- LOG.debug("evaluateAccess: columns collection null or empty, ok. Family level access is desired.");
- session.column(null) // zap stale column from prior iteration of this loop, if any
- .buildRequest()
- .authorize();
- AuthzAuditEvent auditEvent = auditHandler.getAndDiscardMostRecentEvent(); // capture it only for success
- if (session.isAuthorized()) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("evaluateAccess: has family level access [" + family + "]");
- }
- // we need to do 3 things: housekeeping, decide about audit events, building the results cache for filter
- somethingIsAccessible = true;
- familesAccessAllowed.add(family);
- if (auditEvent != null) {
- LOG.debug("evaluateAccess: adding to family-level-access-granted-event-set");
- familyLevelAccessEvents.add(auditEvent);
- }
- } else {
- everythingIsAccessible = false;
- if (LOG.isDebugEnabled()) {
- LOG.debug("evaluateAccess: no family level access [" + family + "]. Checking if has partial access (of any type)...");
- }
-
- session.resourceMatchingScope(RangerAccessRequest.ResourceMatchingScope.SELF_OR_DESCENDANTS)
- .buildRequest()
- .authorize();
- auditEvent = auditHandler.getAndDiscardMostRecentEvent(); // capture it only for failure
- if (session.isAuthorized()) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("evaluateAccess: has partial access (of some type) in family [" + family + "]");
- }
- // we need to do 3 things: housekeeping, decide about audit events, building the results cache for filter
- somethingIsAccessible = true;
- familesAccessIndeterminate.add(family);
- } else {
- if (LOG.isDebugEnabled()) {
- LOG.debug("evaluateAccess: has no access of ["+ access + "] type in family [" + family + "]");
- }
- familesAccessDenied.add(family);
- denialReason = String.format("Insufficient permissions for user ‘%s',action: %s, tableName:%s, family:%s.", user.getName(), operation, table, family);
- if (auditEvent != null && deniedEvent == null) { // we need to capture just one denial event
- LOG.debug("evaluateAccess: Setting denied access audit event with last auth failure audit event.");
- deniedEvent = auditEvent;
- }
- }
- // Restore the headMatch setting
- session.resourceMatchingScope(RangerAccessRequest.ResourceMatchingScope.SELF);
- }
- } else {
- LOG.debug("evaluateAccess: columns collection not empty. Skipping Family level check, will do finer level access check.");
- Set<String> accessibleColumns = new HashSet<String>(); // will be used in to populate our results cache for the filter
- for (String column : columns) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("evaluateAccess: Processing column: " + column);
- }
- session.column(column)
- .buildRequest()
- .authorize();
- AuthzAuditEvent auditEvent = auditHandler.getAndDiscardMostRecentEvent();
- if (session.isAuthorized()) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("evaluateAccess: has column level access [" + family + ", " + column + "]");
- }
- // we need to do 3 things: housekeeping, capturing audit events, building the results cache for filter
- somethingIsAccessible = true;
- accessibleColumns.add(column);
- if (auditEvent != null) {
- LOG.debug("evaluateAccess: adding to access-granted-audit-event-set");
- authorizedEvents.add(auditEvent);
- }
- } else {
- if (LOG.isDebugEnabled()) {
- LOG.debug("evaluateAccess: no column level access [" + family + ", " + column + "]");
- }
- everythingIsAccessible = false;
- denialReason = String.format("Insufficient permissions for user ‘%s',action: %s, tableName:%s, family:%s, column: %s", user.getName(), operation, table, family, column);
- if (auditEvent != null && deniedEvent == null) { // we need to capture just one denial event
- LOG.debug("evaluateAccess: Setting denied access audit event with last auth failure audit event.");
- deniedEvent = auditEvent;
- }
- }
- if (!accessibleColumns.isEmpty()) {
- columnsAccessAllowed.put(family, accessibleColumns);
- }
- }
- }
- }
- // Cache of auth results are encapsulated the in the filter. Not every caller of the function uses it - only preGet and preOpt will.
- RangerAuthorizationFilter filter = new RangerAuthorizationFilter(session, familesAccessAllowed, familesAccessDenied, familesAccessIndeterminate, columnsAccessAllowed);
- result = new ColumnFamilyAccessResult(everythingIsAccessible, somethingIsAccessible, authorizedEvents, familyLevelAccessEvents, deniedEvent, denialReason, filter);
- if (LOG.isDebugEnabled()) {
- String message = String.format(messageTemplate, userName, operation, access, families.toString(), result.toString());
- LOG.debug(message);
- }
- return result;
- }
-
- Filter authorizeAccess(String operation, Action action, final RegionCoprocessorEnvironment env, final Map<byte[], NavigableSet<byte[]>> familyMap) throws AccessDeniedException {
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> authorizeAccess");
- }
- try {
- ColumnFamilyAccessResult accessResult = evaluateAccess(operation, action, env, familyMap);
- RangerDefaultAuditHandler auditHandler = new RangerDefaultAuditHandler();
- if (accessResult._everythingIsAccessible) {
- auditHandler.logAuthzAudits(accessResult._accessAllowedEvents);
- auditHandler.logAuthzAudits(accessResult._familyLevelAccessEvents);
- LOG.debug("authorizeAccess: exiting: No filter returned since all access was allowed");
- return null; // no filter needed since we are good to go.
- } else if (accessResult._somethingIsAccessible) {
- // NOTE: audit logging is split beween logging here (in scope of preOp/preGet) and logging in the filter component for those that couldn't be determined
- auditHandler.logAuthzAudits(accessResult._accessAllowedEvents);
- LOG.debug("authorizeAccess: exiting: Filter returned since some access was allowed");
- return accessResult._filter;
- } else {
- // If we are here then it means nothing was accessible! So let's log one denial (in our case, the last denial) and throw an exception
- auditHandler.logAuthzAudit(accessResult._accessDeniedEvent);
- LOG.debug("authorizeAccess: exiting: Throwing exception since nothing was accessible");
- throw new AccessDeniedException(accessResult._denialReason);
- }
- } finally {
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== authorizeAccess");
- }
- }
- }
-
- Filter combineFilters(Filter filter, Filter existingFilter) {
- Filter combinedFilter = filter;
- if (existingFilter != null) {
- combinedFilter = new FilterList(FilterList.Operator.MUST_PASS_ALL, Lists.newArrayList(filter, existingFilter));
- }
- return combinedFilter;
- }
-
- void requirePermission(final String operation, final Action action, final RegionCoprocessorEnvironment regionServerEnv, final Map<byte[], ? extends Collection<?>> familyMap)
- throws AccessDeniedException {
-
- ColumnFamilyAccessResult accessResult = evaluateAccess(operation, action, regionServerEnv, familyMap);
- RangerDefaultAuditHandler auditHandler = new RangerDefaultAuditHandler();
- if (accessResult._everythingIsAccessible) {
- auditHandler.logAuthzAudits(accessResult._accessAllowedEvents);
- auditHandler.logAuthzAudits(accessResult._familyLevelAccessEvents);
- LOG.debug("requirePermission: exiting: all access was allowed");
- return;
- } else {
- auditHandler.logAuthzAudit(accessResult._accessDeniedEvent);
- LOG.debug("requirePermission: exiting: throwing exception as everything wasn't accessible");
- throw new AccessDeniedException(accessResult._denialReason);
- }
- }
-
- /**
- * This could run s
- * @param operation
- * @param otherInformation
- * @param table
- * @param columnFamily
- * @param column
- * @return
- * @throws AccessDeniedException
- */
- void authorizeAccess(String operation, String otherInformation, Action action, String table, String columnFamily, String column) throws AccessDeniedException {
-
- String access = _authUtils.getAccess(action);
- if (LOG.isDebugEnabled()) {
- final String format = "authorizeAccess: %s: Operation[%s], Info[%s], access[%s], table[%s], columnFamily[%s], column[%s]";
- String message = String.format(format, "Entering", operation, otherInformation, access, table, columnFamily, column);
- LOG.debug(message);
- }
-
- final String format = "authorizeAccess: %s: Operation[%s], Info[%s], access[%s], table[%s], columnFamily[%s], column[%s], allowed[%s], reason[%s]";
- if (canSkipAccessCheck(operation, access, table)) {
- if (LOG.isDebugEnabled()) {
- String message = String.format(format, "Exiting", operation, otherInformation, access, table, columnFamily, column, true, "can skip auth check");
- LOG.debug(message);
- }
- return;
- }
- User user = getActiveUser();
-
- HbaseAuditHandler auditHandler = _factory.getAuditHandler();
- AuthorizationSession session = new AuthorizationSession(hbasePlugin)
- .operation(operation)
- .otherInformation(otherInformation)
- .remoteAddress(getRemoteAddress())
- .auditHandler(auditHandler)
- .user(user)
- .access(access)
- .table(table)
- .columnFamily(columnFamily)
- .column(column)
- .buildRequest()
- .authorize();
-
- if (LOG.isDebugEnabled()) {
- boolean allowed = session.isAuthorized();
- String reason = session.getDenialReason();
- String message = String.format(format, "Exiting", operation, otherInformation, access, table, columnFamily, column, allowed, reason);
- LOG.debug(message);
- }
-
- session.publishResults();
- }
-
- boolean canSkipAccessCheck(final String operation, String access, final String table)
- throws AccessDeniedException {
-
- User user = getActiveUser();
- boolean result = false;
- if (user == null) {
- String message = "Unexpeceted: User is null: access denied, not audited!";
- LOG.warn("canSkipAccessCheck: exiting" + message);
- throw new AccessDeniedException("No user associated with request (" + operation + ") for action: " + access + "on table:" + table);
- } else if (isAccessForMetadataRead(access, table)) {
- LOG.debug("canSkipAccessCheck: true: metadata read access always allowed, not audited");
- result = true;
- } else {
- LOG.debug("Can't skip access checks");
- }
-
- return result;
- }
-
- boolean canSkipAccessCheck(final String operation, String access, final RegionCoprocessorEnvironment regionServerEnv) throws AccessDeniedException {
-
- User user = getActiveUser();
- // read access to metadata tables is always allowed and isn't audited.
- if (isAccessForMetaTables(regionServerEnv) && _authUtils.isReadAccess(access)) {
- LOG.debug("isKnownAccessPattern: exiting: Read access for metadata tables allowed, not audited!");
- return true;
- }
- // if write access is desired to metatables then global create access is sufficient
- if (_authUtils.isWriteAccess(access) && isAccessForMetaTables(regionServerEnv)) {
- String createAccess = _authUtils.getAccess(Action.CREATE);
- AuthorizationSession session = new AuthorizationSession(hbasePlugin)
- .operation(operation)
- .remoteAddress(getRemoteAddress())
- .user(user)
- .access(createAccess)
- .buildRequest()
- .authorize();
- if (session.isAuthorized()) {
- // NOTE: this access isn't logged
- LOG.debug("isKnownAccessPattern: exiting: User has global create access, allowed!");
- return true;
- }
- }
- return false;
- }
-
- boolean isAccessForMetadataRead(String access, String table) {
- if (_authUtils.isReadAccess(access) && isSpecialTable(table)) {
- LOG.debug("isAccessForMetadataRead: Metadata tables read: access allowed!");
- return true;
- }
- return false;
- }
-
- // Check if the user has global permission ...
- protected void requireGlobalPermission(String request, String objName, Permission.Action action) throws AccessDeniedException {
- authorizeAccess(request, objName, action, null, null, null);
- }
-
- protected void requirePermission(String request, byte[] tableName, Permission.Action action) throws AccessDeniedException {
- String table = Bytes.toString(tableName);
-
- authorizeAccess(request, null, action, table, null, null);
- }
-
- protected void requirePermission(String request, byte[] aTableName, byte[] aColumnFamily, byte[] aQualifier, Permission.Action action) throws AccessDeniedException {
-
- String table = Bytes.toString(aTableName);
- String columnFamily = Bytes.toString(aColumnFamily);
- String column = Bytes.toString(aQualifier);
-
- authorizeAccess(request, null, action, table, columnFamily, column);
- }
-
- protected void requirePermission(String request, Permission.Action perm, RegionCoprocessorEnvironment env, Collection<byte[]> families) throws IOException {
- HashMap<byte[], Set<byte[]>> familyMap = new HashMap<byte[], Set<byte[]>>();
-
- if(families != null) {
- for (byte[] family : families) {
- familyMap.put(family, null);
- }
- }
- requirePermission(request, perm, env, familyMap);
- }
-
- @Override
- public void postScannerClose(ObserverContext<RegionCoprocessorEnvironment> c, InternalScanner s) throws IOException {
- scannerOwners.remove(s);
- }
- @Override
- public RegionScanner postScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c, Scan scan, RegionScanner s) throws IOException {
- User user = getActiveUser();
- if (user != null && user.getShortName() != null) {
- scannerOwners.put(s, user.getShortName());
- }
- return s;
- }
- @Override
- public void postStartMaster(ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException {
- if(UpdateRangerPoliciesOnGrantRevoke) {
- RangerAccessControlLists.init(ctx.getEnvironment().getMasterServices());
- }
- }
- @Override
- public void preAddColumn(ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName, HColumnDescriptor column) throws IOException {
- requirePermission("addColumn", tableName.getName(), null, null, Action.CREATE);
- }
- @Override
- public Result preAppend(ObserverContext<RegionCoprocessorEnvironment> c, Append append) throws IOException {
- requirePermission("append", TablePermission.Action.WRITE, c.getEnvironment(), append.getFamilyCellMap());
- return null;
- }
- @Override
- public void preAssign(ObserverContext<MasterCoprocessorEnvironment> c, HRegionInfo regionInfo) throws IOException {
- requirePermission("assign", regionInfo.getTable().getName(), null, null, Action.ADMIN);
- }
- @Override
- public void preBalance(ObserverContext<MasterCoprocessorEnvironment> c) throws IOException {
- requirePermission("balance", null, Permission.Action.ADMIN);
- }
- @Override
- public boolean preBalanceSwitch(ObserverContext<MasterCoprocessorEnvironment> c, boolean newValue) throws IOException {
- requirePermission("balanceSwitch", null, Permission.Action.ADMIN);
- return newValue;
- }
- @Override
- public void preBulkLoadHFile(ObserverContext<RegionCoprocessorEnvironment> ctx, List<Pair<byte[], String>> familyPaths) throws IOException {
- List<byte[]> cfs = new LinkedList<byte[]>();
- for (Pair<byte[], String> el : familyPaths) {
- cfs.add(el.getFirst());
- }
- requirePermission("bulkLoadHFile", Permission.Action.WRITE, ctx.getEnvironment(), cfs);
- }
- @Override
- public boolean preCheckAndDelete(ObserverContext<RegionCoprocessorEnvironment> c, byte[] row, byte[] family, byte[] qualifier, CompareOp compareOp, ByteArrayComparable comparator, Delete delete, boolean result) throws IOException {
- Collection<byte[]> familyMap = Arrays.asList(new byte[][] { family });
- requirePermission("checkAndDelete", TablePermission.Action.READ, c.getEnvironment(), familyMap);
- requirePermission("checkAndDelete", TablePermission.Action.WRITE, c.getEnvironment(), familyMap);
- return result;
- }
- @Override
- public boolean preCheckAndPut(ObserverContext<RegionCoprocessorEnvironment> c, byte[] row, byte[] family, byte[] qualifier, CompareOp compareOp, ByteArrayComparable comparator, Put put, boolean result) throws IOException {
- Collection<byte[]> familyMap = Arrays.asList(new byte[][] { family });
- requirePermission("checkAndPut", TablePermission.Action.READ, c.getEnvironment(), familyMap);
- requirePermission("checkAndPut", TablePermission.Action.WRITE, c.getEnvironment(), familyMap);
- return result;
- }
- @Override
- public void preCloneSnapshot(ObserverContext<MasterCoprocessorEnvironment> ctx, SnapshotDescription snapshot, HTableDescriptor hTableDescriptor) throws IOException {
- requirePermission("cloneSnapshot", null, Permission.Action.ADMIN);
- }
- @Override
- public void preClose(ObserverContext<RegionCoprocessorEnvironment> e, boolean abortRequested) throws IOException {
- requirePermission("close", getTableName(e.getEnvironment()), Permission.Action.ADMIN);
- }
- @Override
- public InternalScanner preCompact(ObserverContext<RegionCoprocessorEnvironment> e, Store store, InternalScanner scanner,ScanType scanType) throws IOException {
- requirePermission("compact", getTableName(e.getEnvironment()), null, null, Action.CREATE);
- return scanner;
- }
- @Override
- public void preCompactSelection(ObserverContext<RegionCoprocessorEnvironment> e, Store store, List<StoreFile> candidates) throws IOException {
- requirePermission("compactSelection", getTableName(e.getEnvironment()), null, null, Action.CREATE);
- }
-
- @Override
- public void preCreateTable(ObserverContext<MasterCoprocessorEnvironment> c, HTableDescriptor desc, HRegionInfo[] regions) throws IOException {
- requirePermission("createTable", desc.getName(), Permission.Action.CREATE);
- }
- @Override
- public void preDelete(ObserverContext<RegionCoprocessorEnvironment> c, Delete delete, WALEdit edit, Durability durability) throws IOException {
- requirePermission("delete", TablePermission.Action.WRITE, c.getEnvironment(), delete.getFamilyCellMap());
- }
- @Override
- public void preDeleteColumn(ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName, byte[] col) throws IOException {
- requirePermission("deleteColumn", tableName.getName(), null, null, Action.CREATE);
- }
- @Override
- public void preDeleteSnapshot(ObserverContext<MasterCoprocessorEnvironment> ctx, SnapshotDescription snapshot) throws IOException {
- requirePermission("deleteSnapshot", null, Permission.Action.ADMIN);
- }
- @Override
- public void preDeleteTable(ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName) throws IOException {
- requirePermission("deleteTable", tableName.getName(), null, null, Action.CREATE);
- }
- @Override
- public void preDisableTable(ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName) throws IOException {
- requirePermission("disableTable", tableName.getName(), null, null, Action.CREATE);
- }
- @Override
- public void preEnableTable(ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName) throws IOException {
- requirePermission("enableTable", tableName.getName(), null, null, Action.CREATE);
- }
- @Override
- public boolean preExists(ObserverContext<RegionCoprocessorEnvironment> c, Get get, boolean exists) throws IOException {
- requirePermission("exists", TablePermission.Action.READ, c.getEnvironment(), get.familySet());
- return exists;
- }
- @Override
- public void preFlush(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
- requirePermission("flush", getTableName(e.getEnvironment()), null, null, Action.CREATE);
- }
- @Override
- public void preGetClosestRowBefore(ObserverContext<RegionCoprocessorEnvironment> c, byte[] row, byte[] family, Result result) throws IOException {
- requirePermission("getClosestRowBefore", TablePermission.Action.READ, c.getEnvironment(), (family != null ? Lists.newArrayList(family) : null));
- }
- @Override
- public Result preIncrement(ObserverContext<RegionCoprocessorEnvironment> c, Increment increment) throws IOException {
- requirePermission("increment", TablePermission.Action.WRITE, c.getEnvironment(), increment.getFamilyCellMap().keySet());
-
- return null;
- }
- @Override
- public long preIncrementColumnValue(ObserverContext<RegionCoprocessorEnvironment> c, byte[] row, byte[] family, byte[] qualifier, long amount, boolean writeToWAL) throws IOException {
- requirePermission("incrementColumnValue", TablePermission.Action.READ, c.getEnvironment(), Arrays.asList(new byte[][] { family }));
- requirePermission("incrementColumnValue", TablePermission.Action.WRITE, c.getEnvironment(), Arrays.asList(new byte[][] { family }));
- return -1;
- }
- @Override
- public void preModifyColumn(ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName, HColumnDescriptor descriptor) throws IOException {
- requirePermission("modifyColumn", tableName.getName(), null, null, Action.CREATE);
- }
- @Override
- public void preModifyTable(ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName, HTableDescriptor htd) throws IOException {
- requirePermission("modifyTable", tableName.getName(), null, null, Action.CREATE);
- }
- @Override
- public void preMove(ObserverContext<MasterCoprocessorEnvironment> c, HRegionInfo region, ServerName srcServer, ServerName destServer) throws IOException {
- requirePermission("move", region.getTable().getName() , null, null, Action.ADMIN);
- }
- @Override
- public void preOpen(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
- RegionCoprocessorEnvironment env = e.getEnvironment();
- final Region region = env.getRegion();
- if (region == null) {
- LOG.error("NULL region from RegionCoprocessorEnvironment in preOpen()");
- } else {
- HRegionInfo regionInfo = region.getRegionInfo();
- if (isSpecialTable(regionInfo)) {
- requireSystemOrSuperUser(regionEnv.getConfiguration());
- } else {
- requirePermission("open", getTableName(e.getEnvironment()), Action.ADMIN);
- }
- }
- }
- @Override
- public void preRestoreSnapshot(ObserverContext<MasterCoprocessorEnvironment> ctx, SnapshotDescription snapshot, HTableDescriptor hTableDescriptor) throws IOException {
- requirePermission("restoreSnapshot", hTableDescriptor.getName(), Permission.Action.ADMIN);
- }
-
- @Override
- public void preScannerClose(ObserverContext<RegionCoprocessorEnvironment> c, InternalScanner s) throws IOException {
- requireScannerOwner(s);
- }
- @Override
- public boolean preScannerNext(ObserverContext<RegionCoprocessorEnvironment> c, InternalScanner s, List<Result> result, int limit, boolean hasNext) throws IOException {
- requireScannerOwner(s);
- return hasNext;
- }
- @Override
- public RegionScanner preScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c, Scan scan, RegionScanner s) throws IOException {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> preScannerOpen");
- }
-
- try {
- RegionCoprocessorEnvironment e = c.getEnvironment();
-
- Map<byte[], NavigableSet<byte[]>> familyMap = scan.getFamilyMap();
- String operation = "scannerOpen";
- Filter filter = authorizeAccess(operation, Action.READ, e, familyMap);
- if (filter == null) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("preScannerOpen: Access allowed for all families/column. No filter added");
- }
- } else {
- if (LOG.isDebugEnabled()) {
- LOG.debug("preScannerOpen: Access allowed for some of the families/column. New filter added.");
- }
- Filter existingFilter = scan.getFilter();
- Filter combinedFilter = combineFilters(filter, existingFilter);
- scan.setFilter(combinedFilter);
- }
- return s;
- } finally {
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== preScannerOpen");
- }
- }
- }
- @Override
- public void preShutdown(ObserverContext<MasterCoprocessorEnvironment> c) throws IOException {
- requirePermission("shutdown", null, Permission.Action.ADMIN);
- }
- @Override
- public void preSnapshot(ObserverContext<MasterCoprocessorEnvironment> ctx, SnapshotDescription snapshot, HTableDescriptor hTableDescriptor) throws IOException {
- requirePermission("snapshot", hTableDescriptor.getName(), Permission.Action.ADMIN);
- }
- @Override
- public void preSplit(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
- requirePermission("split", getTableName(e.getEnvironment()), null, null, Action.ADMIN);
- }
- @Override
- public void preStopMaster(ObserverContext<MasterCoprocessorEnvironment> c) throws IOException {
- requirePermission("stopMaster", null, Permission.Action.ADMIN);
- }
- @Override
- public void preStopRegionServer(ObserverContext<RegionServerCoprocessorEnvironment> env) throws IOException {
- requirePermission("stop", null, Permission.Action.ADMIN);
- }
- @Override
- public void preUnassign(ObserverContext<MasterCoprocessorEnvironment> c, HRegionInfo regionInfo, boolean force) throws IOException {
- requirePermission("unassign", regionInfo.getTable().getName(), null, null, Action.ADMIN);
- }
-
- @Override
- public void preSetUserQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
- final String userName, final Quotas quotas) throws IOException {
- requireGlobalPermission("setUserQuota", null, Action.ADMIN);
- }
-
- @Override
- public void preSetUserQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
- final String userName, final TableName tableName, final Quotas quotas) throws IOException {
- requirePermission("setUserTableQuota", tableName.getName(), null, null, Action.ADMIN);
- }
-
- @Override
- public void preSetUserQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
- final String userName, final String namespace, final Quotas quotas) throws IOException {
- requireGlobalPermission("setUserNamespaceQuota", namespace, Action.ADMIN);
- }
-
- @Override
- public void preSetTableQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
- final TableName tableName, final Quotas quotas) throws IOException {
- requirePermission("setTableQuota", tableName.getName(), null, null, Action.ADMIN);
- }
-
- @Override
- public void preSetNamespaceQuota(final ObserverContext<MasterCoprocessorEnvironment> ctx,
- final String namespace, final Quotas quotas) throws IOException {
- requireGlobalPermission("setNamespaceQuota", namespace, Action.ADMIN);
- }
-
- private String coprocessorType = "unknown";
- private static final String MASTER_COPROCESSOR_TYPE = "master";
- private static final String REGIONAL_COPROCESSOR_TYPE = "regional";
- private static final String REGIONAL_SERVER_COPROCESSOR_TYPE = "regionalServer";
-
- @Override
- public void start(CoprocessorEnvironment env) throws IOException {
- String appType = "unknown";
-
- if (env instanceof MasterCoprocessorEnvironment) {
- coprocessorType = MASTER_COPROCESSOR_TYPE;
- appType = "hbaseMaster";
- } else if (env instanceof RegionServerCoprocessorEnvironment) {
- coprocessorType = REGIONAL_SERVER_COPROCESSOR_TYPE;
- appType = "hbaseRegional";
- } else if (env instanceof RegionCoprocessorEnvironment) {
- regionEnv = (RegionCoprocessorEnvironment) env;
- coprocessorType = REGIONAL_COPROCESSOR_TYPE;
- appType = "hbaseRegional";
- }
-
- Configuration conf = env.getConfiguration();
- HbaseFactory.initialize(conf);
-
- // create and initialize the plugin class
- RangerHBasePlugin plugin = hbasePlugin;
-
- if(plugin == null) {
- synchronized(RangerAuthorizationCoprocessor.class) {
- plugin = hbasePlugin;
-
- if(plugin == null) {
- plugin = new RangerHBasePlugin(appType);
-
- plugin.init();
-
- UpdateRangerPoliciesOnGrantRevoke = RangerConfiguration.getInstance().getBoolean(RangerHadoopConstants.HBASE_UPDATE_RANGER_POLICIES_ON_GRANT_REVOKE_PROP, RangerHadoopConstants.HBASE_UPDATE_RANGER_POLICIES_ON_GRANT_REVOKE_DEFAULT_VALUE);
-
- hbasePlugin = plugin;
- }
- }
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("Start of Coprocessor: [" + coprocessorType + "]");
- }
- }
- @Override
- public void prePut(ObserverContext<RegionCoprocessorEnvironment> c, Put put, WALEdit edit, Durability durability) throws IOException {
- requirePermission("put", TablePermission.Action.WRITE, c.getEnvironment(), put.getFamilyCellMap());
- }
-
- @Override
- public void preGetOp(final ObserverContext<RegionCoprocessorEnvironment> rEnv, final Get get, final List<Cell> result) throws IOException {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> preGetOp");
- }
- try {
- RegionCoprocessorEnvironment e = rEnv.getEnvironment();
- Map<byte[], NavigableSet<byte[]>> familyMap = get.getFamilyMap();
-
- String operation = "get";
- Filter filter = authorizeAccess(operation, Action.READ, e, familyMap);
- if (filter == null) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("preGetOp: all access allowed, no filter returned");
- }
- } else {
- Filter existingFilter = get.getFilter();
- Filter combinedFilter = combineFilters(filter, existingFilter);
- get.setFilter(combinedFilter);
- if (LOG.isDebugEnabled()) {
- LOG.debug("preGetOp: partial access, new filter added");
- }
- }
- } finally {
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== preGetOp");
- }
- }
- }
- @Override
- public void preRegionOffline(ObserverContext<MasterCoprocessorEnvironment> c, HRegionInfo regionInfo) throws IOException {
- requirePermission("regionOffline", regionInfo.getTable().getName(), null, null, Action.ADMIN);
- }
- @Override
- public void preCreateNamespace(ObserverContext<MasterCoprocessorEnvironment> ctx, NamespaceDescriptor ns) throws IOException {
- requireGlobalPermission("createNamespace", ns.getName(), Action.ADMIN);
- }
- @Override
- public void preDeleteNamespace(ObserverContext<MasterCoprocessorEnvironment> ctx, String namespace) throws IOException {
- requireGlobalPermission("deleteNamespace", namespace, Action.ADMIN);
- }
- @Override
- public void preModifyNamespace(ObserverContext<MasterCoprocessorEnvironment> ctx, NamespaceDescriptor ns) throws IOException {
- requireGlobalPermission("modifyNamespace", ns.getName(), Action.ADMIN);
- }
-
- @Override
- public void postGetTableDescriptors(ObserverContext<MasterCoprocessorEnvironment> ctx, List<TableName> tableNamesList, List<HTableDescriptor> descriptors, String regex) throws IOException {
- if (LOG.isDebugEnabled()) {
- LOG.debug(String.format("==> postGetTableDescriptors(count(tableNamesList)=%s, count(descriptors)=%s, regex=%s)", tableNamesList == null ? 0 : tableNamesList.size(),
- descriptors == null ? 0 : descriptors.size(), regex));
- }
-
- if (CollectionUtils.isNotEmpty(descriptors)) {
- // Retains only those which passes authorization checks
- User user = getActiveUser();
- String access = _authUtils.getAccess(Action.CREATE);
- HbaseAuditHandler auditHandler = _factory.getAuditHandler(); // this will accumulate audits for all tables that succeed.
- AuthorizationSession session = new AuthorizationSession(hbasePlugin)
- .operation("getTableDescriptors")
- .otherInformation("regex=" + regex)
- .remoteAddress(getRemoteAddress())
- .auditHandler(auditHandler)
- .user(user)
- .access(access);
-
- Iterator<HTableDescriptor> itr = descriptors.iterator();
- while (itr.hasNext()) {
- HTableDescriptor htd = itr.next();
- String tableName = htd.getTableName().getNameAsString();
- session.table(tableName).buildRequest().authorize();
- if (!session.isAuthorized()) {
- itr.remove();
- auditHandler.getAndDiscardMostRecentEvent();
- }
- }
- if (descriptors.size() > 0) {
- session.logCapturedEvents();
- }
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(String.format("<== postGetTableDescriptors(count(tableNamesList)=%s, count(descriptors)=%s, regex=%s)", tableNamesList == null ? 0 : tableNamesList.size(),
- descriptors == null ? 0 : descriptors.size(), regex));
- }
- }
-
- @Override
- public void preMerge(ObserverContext<RegionServerCoprocessorEnvironment> ctx, Region regionA, Region regionB) throws IOException {
- requirePermission("mergeRegions", regionA.getTableDesc().getTableName().getName(), null, null, Action.ADMIN);
- }
-
- public void prePrepareBulkLoad(ObserverContext<RegionCoprocessorEnvironment> ctx, PrepareBulkLoadRequest request) throws IOException {
- List<byte[]> cfs = null;
-
- requirePermission("prePrepareBulkLoad", Permission.Action.WRITE, ctx.getEnvironment(), cfs);
- }
-
- public void preCleanupBulkLoad(ObserverContext<RegionCoprocessorEnvironment> ctx, CleanupBulkLoadRequest request) throws IOException {
- List<byte[]> cfs = null;
-
- requirePermission("preCleanupBulkLoad", Permission.Action.WRITE, ctx.getEnvironment(), cfs);
- }
-
- public static Date getUTCDate() {
- Calendar local=Calendar.getInstance();
- int offset = local.getTimeZone().getOffset(local.getTimeInMillis());
- GregorianCalendar utc = new GregorianCalendar(gmtTimeZone);
- utc.setTimeInMillis(local.getTimeInMillis());
- utc.add(Calendar.MILLISECOND, -offset);
- return utc.getTime();
- }
-
- @Override
- public void grant(RpcController controller, AccessControlProtos.GrantRequest request, RpcCallback<AccessControlProtos.GrantResponse> done) {
- boolean isSuccess = false;
-
- if(UpdateRangerPoliciesOnGrantRevoke) {
- GrantRevokeRequest grData = null;
-
- try {
- grData = createGrantData(request);
-
- RangerHBasePlugin plugin = hbasePlugin;
-
- if(plugin != null) {
- RangerAccessResultProcessor auditHandler = new RangerDefaultAuditHandler();
-
- plugin.grantAccess(grData, auditHandler);
-
- isSuccess = true;
- }
- } catch(AccessControlException excp) {
- LOG.warn("grant() failed", excp);
-
- ResponseConverter.setControllerException(controller, new AccessDeniedException(excp));
- } catch(IOException excp) {
- LOG.warn("grant() failed", excp);
-
- ResponseConverter.setControllerException(controller, excp);
- } catch (Exception excp) {
- LOG.warn("grant() failed", excp);
-
- ResponseConverter.setControllerException(controller, new CoprocessorException(excp.getMessage()));
- }
- }
-
- AccessControlProtos.GrantResponse response = isSuccess ? AccessControlProtos.GrantResponse.getDefaultInstance() : null;
-
- done.run(response);
- }
-
- @Override
- public void revoke(RpcController controller, AccessControlProtos.RevokeRequest request, RpcCallback<AccessControlProtos.RevokeResponse> done) {
- boolean isSuccess = false;
-
- if(UpdateRangerPoliciesOnGrantRevoke) {
- GrantRevokeRequest grData = null;
-
- try {
- grData = createRevokeData(request);
-
- RangerHBasePlugin plugin = hbasePlugin;
-
- if(plugin != null) {
- RangerAccessResultProcessor auditHandler = new RangerDefaultAuditHandler();
-
- plugin.revokeAccess(grData, auditHandler);
-
- isSuccess = true;
- }
- } catch(AccessControlException excp) {
- LOG.warn("revoke() failed", excp);
-
- ResponseConverter.setControllerException(controller, new AccessDeniedException(excp));
- } catch(IOException excp) {
- LOG.warn("revoke() failed", excp);
-
- ResponseConverter.setControllerException(controller, excp);
- } catch (Exception excp) {
- LOG.warn("revoke() failed", excp);
-
- ResponseConverter.setControllerException(controller, new CoprocessorException(excp.getMessage()));
- }
- }
-
- AccessControlProtos.RevokeResponse response = isSuccess ? AccessControlProtos.RevokeResponse.getDefaultInstance() : null;
-
- done.run(response);
- }
-
- @Override
- public void checkPermissions(RpcController controller, AccessControlProtos.CheckPermissionsRequest request, RpcCallback<AccessControlProtos.CheckPermissionsResponse> done) {
- LOG.debug("checkPermissions(): ");
- }
-
- @Override
- public void getUserPermissions(RpcController controller, AccessControlProtos.GetUserPermissionsRequest request, RpcCallback<AccessControlProtos.GetUserPermissionsResponse> done) {
- LOG.debug("getUserPermissions(): ");
- }
-
- @Override
- public Service getService() {
- return AccessControlProtos.AccessControlService.newReflectiveService(this);
- }
-
- private GrantRevokeRequest createGrantData(AccessControlProtos.GrantRequest request) throws Exception {
- org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.UserPermission up = request.getUserPermission();
- org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.Permission perm = up == null ? null : up.getPermission();
-
- UserPermission userPerm = up == null ? null : ProtobufUtil.toUserPermission(up);
- Permission.Action[] actions = userPerm == null ? null : userPerm.getActions();
- String userName = userPerm == null ? null : Bytes.toString(userPerm.getUser());
- String nameSpace = null;
- String tableName = null;
- String colFamily = null;
- String qualifier = null;
-
- if(perm == null) {
- throw new Exception("grant(): invalid data - permission is null");
- }
-
- if(StringUtil.isEmpty(userName)) {
- throw new Exception("grant(): invalid data - username empty");
- }
-
- if ((actions == null) || (actions.length == 0)) {
- throw new Exception("grant(): invalid data - no action specified");
- }
-
- switch(perm.getType()) {
- case Global:
- tableName = colFamily = qualifier = WILDCARD;
- break;
-
- case Table:
- tableName = Bytes.toString(userPerm.getTableName().getName());
- colFamily = Bytes.toString(userPerm.getFamily());
- qualifier = Bytes.toString(userPerm.getQualifier());
- break;
-
- case Namespace:
- nameSpace = userPerm.getNamespace();
- break;
- }
-
- if(StringUtil.isEmpty(nameSpace) && StringUtil.isEmpty(tableName) && StringUtil.isEmpty(colFamily) && StringUtil.isEmpty(qualifier)) {
- throw new Exception("grant(): namespace/table/columnFamily/columnQualifier not specified");
- }
-
- tableName = StringUtil.isEmpty(tableName) ? WILDCARD : tableName;
- colFamily = StringUtil.isEmpty(colFamily) ? WILDCARD : colFamily;
- qualifier = StringUtil.isEmpty(qualifier) ? WILDCARD : qualifier;
-
- if(! StringUtil.isEmpty(nameSpace)) {
- tableName = nameSpace + NAMESPACE_SEPARATOR + tableName;
- }
-
- User activeUser = getActiveUser();
- String grantor = activeUser != null ? activeUser.getShortName() : null;
-
- Map<String, String> mapResource = new HashMap<String, String>();
- mapResource.put("table", tableName);
- mapResource.put("column-family", colFamily);
- mapResource.put("column", qualifier);
-
- GrantRevokeRequest ret = new GrantRevokeRequest();
-
- ret.setGrantor(grantor);
- ret.setDelegateAdmin(Boolean.FALSE);
- ret.setEnableAudit(Boolean.TRUE);
- ret.setReplaceExistingPermissions(Boolean.TRUE);
- ret.setResource(mapResource);
- ret.setClientIPAddress(getRemoteAddress());
-
- if(userName.startsWith(GROUP_PREFIX)) {
- ret.getGroups().add(userName.substring(GROUP_PREFIX.length()));
- } else {
- ret.getUsers().add(userName);
- }
-
- for (int i = 0; i < actions.length; i++) {
- switch(actions[i].code()) {
- case 'R':
- ret.getAccessTypes().add(HbaseAuthUtils.ACCESS_TYPE_READ);
- break;
-
- case 'W':
- ret.getAccessTypes().add(HbaseAuthUtils.ACCESS_TYPE_WRITE);
- break;
-
- case 'C':
- ret.getAccessTypes().add(HbaseAuthUtils.ACCESS_TYPE_CREATE);
- break;
-
- case 'A':
- ret.getAccessTypes().add(HbaseAuthUtils.ACCESS_TYPE_ADMIN);
- ret.setDelegateAdmin(Boolean.TRUE);
- break;
-
- default:
- LOG.warn("grant(): ignoring action '" + actions[i].name() + "' for user '" + userName + "'");
- }
- }
-
- return ret;
- }
-
- private GrantRevokeRequest createRevokeData(AccessControlProtos.RevokeRequest request) throws Exception {
- org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.UserPermission up = request.getUserPermission();
- org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.Permission perm = up == null ? null : up.getPermission();
-
- UserPermission userPerm = up == null ? null : ProtobufUtil.toUserPermission(up);
- String userName = userPerm == null ? null : Bytes.toString(userPerm.getUser());
- String nameSpace = null;
- String tableName = null;
- String colFamily = null;
- String qualifier = null;
-
- if(perm == null) {
- throw new Exception("revoke(): invalid data - permission is null");
- }
-
- if(StringUtil.isEmpty(userName)) {
- throw new Exception("revoke(): invalid data - username empty");
- }
-
- switch(perm.getType()) {
- case Global :
- tableName = colFamily = qualifier = WILDCARD;
- break;
-
- case Table :
- tableName = Bytes.toString(userPerm.getTableName().getName());
- colFamily = Bytes.toString(userPerm.getFamily());
- qualifier = Bytes.toString(userPerm.getQualifier());
- break;
-
- case Namespace:
- nameSpace = userPerm.getNamespace();
- break;
- }
-
- if(StringUtil.isEmpty(nameSpace) && StringUtil.isEmpty(tableName) && StringUtil.isEmpty(colFamily) && StringUtil.isEmpty(qualifier)) {
- throw new Exception("revoke(): table/columnFamily/columnQualifier not specified");
- }
-
- tableName = StringUtil.isEmpty(tableName) ? WILDCARD : tableName;
- colFamily = StringUtil.isEmpty(colFamily) ? WILDCARD : colFamily;
- qualifier = StringUtil.isEmpty(qualifier) ? WILDCARD : qualifier;
-
- if(! StringUtil.isEmpty(nameSpace)) {
- tableName = nameSpace + NAMESPACE_SEPARATOR + tableName;
- }
-
- User activeUser = getActiveUser();
- String grantor = activeUser != null ? activeUser.getShortName() : null;
-
- Map<String, String> mapResource = new HashMap<String, String>();
- mapResource.put("table", tableName);
- mapResource.put("column-family", colFamily);
- mapResource.put("column", qualifier);
-
- GrantRevokeRequest ret = new GrantRevokeRequest();
-
- ret.setGrantor(grantor);
- ret.setDelegateAdmin(Boolean.TRUE); // remove delegateAdmin privilege as well
- ret.setEnableAudit(Boolean.TRUE);
- ret.setReplaceExistingPermissions(Boolean.TRUE);
- ret.setResource(mapResource);
- ret.setClientIPAddress(getRemoteAddress());
-
- if(userName.startsWith(GROUP_PREFIX)) {
- ret.getGroups().add(userName.substring(GROUP_PREFIX.length()));
- } else {
- ret.getUsers().add(userName);
- }
-
- // revoke removes all permissions
- ret.getAccessTypes().add(HbaseAuthUtils.ACCESS_TYPE_READ);
- ret.getAccessTypes().add(HbaseAuthUtils.ACCESS_TYPE_WRITE);
- ret.getAccessTypes().add(HbaseAuthUtils.ACCESS_TYPE_CREATE);
- ret.getAccessTypes().add(HbaseAuthUtils.ACCESS_TYPE_ADMIN);
-
- return ret;
- }
-}
-
-
-class RangerHBasePlugin extends RangerBasePlugin {
- public RangerHBasePlugin(String appType) {
- super("hbase", appType);
- }
-
- public void init() {
- super.init();
- }
-}
-
-
[3/6] incubator-ranger git commit: RANGER-586: Ranger plugins should
not add dependent libraries to component's CLASSPATH
Posted by rm...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-hbase-plugin-shim/src/main/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessor.java
----------------------------------------------------------------------
diff --git a/ranger-hbase-plugin-shim/src/main/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessor.java b/ranger-hbase-plugin-shim/src/main/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessor.java
new file mode 100644
index 0000000..d6fd056
--- /dev/null
+++ b/ranger-hbase-plugin-shim/src/main/java/org/apache/ranger/authorization/hbase/RangerAuthorizationCoprocessor.java
@@ -0,0 +1,3702 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ranger.authorization.hbase;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.NavigableSet;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellScanner;
+import org.apache.hadoop.hbase.Coprocessor;
+import org.apache.hadoop.hbase.CoprocessorEnvironment;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.NamespaceDescriptor;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Append;
+import org.apache.hadoop.hbase.client.Delete;
+import org.apache.hadoop.hbase.client.Durability;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.Increment;
+import org.apache.hadoop.hbase.client.Mutation;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.coprocessor.BulkLoadObserver;
+import org.apache.hadoop.hbase.coprocessor.CoprocessorService;
+import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment;
+import org.apache.hadoop.hbase.coprocessor.MasterObserver;
+import org.apache.hadoop.hbase.coprocessor.ObserverContext;
+import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
+import org.apache.hadoop.hbase.coprocessor.RegionObserver;
+import org.apache.hadoop.hbase.coprocessor.RegionServerCoprocessorEnvironment;
+import org.apache.hadoop.hbase.coprocessor.RegionServerObserver;
+import org.apache.hadoop.hbase.filter.ByteArrayComparable;
+import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
+import org.apache.hadoop.hbase.io.FSDataInputStreamWrapper;
+import org.apache.hadoop.hbase.io.Reference;
+import org.apache.hadoop.hbase.io.hfile.CacheConfig;
+import org.apache.hadoop.hbase.master.RegionPlan;
+import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos;
+import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.CheckPermissionsRequest;
+import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.CheckPermissionsResponse;
+import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.GetUserPermissionsRequest;
+import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.GetUserPermissionsResponse;
+import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.GrantRequest;
+import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.GrantResponse;
+import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.RevokeRequest;
+import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.RevokeResponse;
+import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.WALEntry;
+import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription;
+import org.apache.hadoop.hbase.protobuf.generated.QuotaProtos.Quotas;
+import org.apache.hadoop.hbase.protobuf.generated.SecureBulkLoadProtos.CleanupBulkLoadRequest;
+import org.apache.hadoop.hbase.protobuf.generated.SecureBulkLoadProtos.PrepareBulkLoadRequest;
+import org.apache.hadoop.hbase.regionserver.DeleteTracker;
+import org.apache.hadoop.hbase.regionserver.InternalScanner;
+import org.apache.hadoop.hbase.regionserver.KeyValueScanner;
+import org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress;
+import org.apache.hadoop.hbase.regionserver.Region;
+import org.apache.hadoop.hbase.regionserver.Region.Operation;
+import org.apache.hadoop.hbase.regionserver.RegionScanner;
+import org.apache.hadoop.hbase.regionserver.ScanType;
+import org.apache.hadoop.hbase.regionserver.Store;
+import org.apache.hadoop.hbase.regionserver.StoreFile;
+import org.apache.hadoop.hbase.regionserver.StoreFile.Reader;
+import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequest;
+import org.apache.hadoop.hbase.regionserver.wal.HLogKey;
+import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
+import org.apache.hadoop.hbase.replication.ReplicationEndpoint;
+import org.apache.hadoop.hbase.security.access.RangerAccessControlLists;
+import org.apache.hadoop.hbase.util.Pair;
+import org.apache.hadoop.hbase.wal.WALKey;
+import org.apache.ranger.plugin.classloader.RangerPluginClassLoader;
+
+import com.google.common.collect.ImmutableList;
+import com.google.protobuf.RpcCallback;
+import com.google.protobuf.RpcController;
+import com.google.protobuf.Service;
+
+public class RangerAuthorizationCoprocessor implements MasterObserver, RegionObserver, RegionServerObserver, BulkLoadObserver, AccessControlProtos.AccessControlService.Interface, CoprocessorService, Coprocessor {
+
+ public static final Log LOG = LogFactory.getLog(RangerAuthorizationCoprocessor.class);
+ private static final String RANGER_PLUGIN_TYPE = "hbase";
+ private static final String[] RANGER_PLUGIN_LIB_DIR = new String[] {"lib/ranger-hbase-plugin"};
+ private static final String RANGER_HBASE_AUTHORIZER_IMPL_CLASSNAME = "org.apache.ranger.authorization.hbase.RangerAuthorizationCoprocessorImpl";
+ private static final String ACCESSCONTROLLISTS_CLASSNAME = "org.apache.hadoop.hbase.security.access.AccessControlLists";
+
+ private static RangerPluginClassLoader rangerPluginClassLoader = null;
+
+ private Object impl = null;
+ private MasterObserver implMasterObserver = null;
+ private RegionObserver implRegionObserver = null;
+ private RegionServerObserver implRegionServerObserver = null;
+ private BulkLoadObserver implBulkLoadObserver = null;
+ private AccessControlProtos.AccessControlService.Interface implAccessControlService = null;
+ private CoprocessorService implCoprocessorService = null;
+
+ public RangerAuthorizationCoprocessor() {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.RangerAuthorizationCoprocessor()");
+ }
+
+ this.init();
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.RangerAuthorizationCoprocessor()");
+ }
+ }
+
+ public void init(){
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.init()");
+ }
+
+ try {
+
+ rangerPluginClassLoader = RangerPluginClassLoader.getInstance(RANGER_PLUGIN_TYPE, this.getClass());
+
+ @SuppressWarnings("unchecked")
+ Class<?> cls = Class.forName(RANGER_HBASE_AUTHORIZER_IMPL_CLASSNAME, true, rangerPluginClassLoader);
+
+ activatePluginClassLoader();
+
+ impl = cls.newInstance();
+ implMasterObserver = (MasterObserver)impl;
+ implRegionObserver = (RegionObserver)impl;
+ implRegionServerObserver = (RegionServerObserver)impl;
+ implBulkLoadObserver = (BulkLoadObserver)impl;
+ implAccessControlService = (AccessControlProtos.AccessControlService.Interface)impl;
+ implCoprocessorService = (CoprocessorService)impl;
+
+ } catch (Exception e) {
+ // check what need to be done
+ LOG.error("Error Enabling RangerHdfsPluing", e);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.init()");
+ }
+ }
+
+ @Override
+ public Service getService() {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.getService()");
+ }
+ Service ret = null;
+ try {
+ activatePluginClassLoader();
+ ret = implCoprocessorService.getService();
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.getService()" + ret);
+ }
+
+ return ret;
+ }
+
+
+ @Override
+ public void postScannerClose(ObserverContext<RegionCoprocessorEnvironment> c, InternalScanner s) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postScannerClose()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postScannerClose(c, s);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postScannerClose()");
+ }
+ }
+
+ @Override
+ public RegionScanner postScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c, Scan scan, RegionScanner s) throws IOException {
+ RegionScanner ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postScannerOpen()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.postScannerOpen(c, scan, s);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postScannerOpen()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void postStartMaster(ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException {
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postStartMaster()");
+ }
+
+ try {
+ //activatePluginClassLoader();
+ //implMasterObserver.postStartMaster(ctx);
+ RangerAccessControlLists.init(ctx.getEnvironment().getMasterServices());
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postStartMaster()");
+ }
+
+ }
+
+ @Override
+ public void preAddColumn(ObserverContext<MasterCoprocessorEnvironment> c,TableName tableName, HColumnDescriptor column) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preAddColumn()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preAddColumn(c, tableName, column);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preAddColumn()");
+ }
+ }
+
+ @Override
+ public Result preAppend(ObserverContext<RegionCoprocessorEnvironment> c, Append append) throws IOException {
+ Result ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preAppend()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.preAppend(c, append);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preAppend()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void preAssign(ObserverContext<MasterCoprocessorEnvironment> c, HRegionInfo regionInfo) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preAssign()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preAssign(c, regionInfo);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preAssign()");
+ }
+ }
+
+ @Override
+ public void preBalance(ObserverContext<MasterCoprocessorEnvironment> c) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preBalance()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preBalance(c);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preBalance()");
+ }
+ }
+
+ @Override
+ public boolean preBalanceSwitch(ObserverContext<MasterCoprocessorEnvironment> c, boolean newValue) throws IOException {
+ boolean ret = false;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preBalanceSwitch()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implMasterObserver.preBalanceSwitch(c, newValue);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preBalanceSwitch()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void preBulkLoadHFile(ObserverContext<RegionCoprocessorEnvironment> ctx, List<Pair<byte[], String>> familyPaths) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preBulkLoadHFile()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preBulkLoadHFile(ctx, familyPaths);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preBulkLoadHFile()");
+ }
+
+ }
+
+ @Override
+ public boolean preCheckAndDelete(ObserverContext<RegionCoprocessorEnvironment> c, byte[] row, byte[] family, byte[] qualifier, CompareOp compareOp, ByteArrayComparable comparator, Delete delete, boolean result) throws IOException {
+ boolean ret = false;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preCheckAndDelete()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.preCheckAndDelete(c, row, family, qualifier, compareOp,comparator, delete, result);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preCheckAndDelete()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public boolean preCheckAndPut(ObserverContext<RegionCoprocessorEnvironment> c, byte[] row, byte[] family, byte[] qualifier, CompareOp compareOp, ByteArrayComparable comparator, Put put, boolean result) throws IOException {
+ boolean ret = false;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preCheckAndPut()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.preCheckAndPut(c, row, family, qualifier, compareOp, comparator,put, result);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preCheckAndPut()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void preCloneSnapshot(ObserverContext<MasterCoprocessorEnvironment> ctx, SnapshotDescription snapshot, HTableDescriptor hTableDescriptor) throws IOException {
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preCloneSnapshot()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preCloneSnapshot(ctx, snapshot, hTableDescriptor);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preCloneSnapshot()");
+ }
+ }
+
+ @Override
+ public void preClose(ObserverContext<RegionCoprocessorEnvironment> e,boolean abortRequested) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preClose()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preClose(e, abortRequested);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preClose()");
+ }
+ }
+
+ @Override
+ public InternalScanner preCompact(ObserverContext<RegionCoprocessorEnvironment> e, Store store, InternalScanner scanner, ScanType scanType) throws IOException {
+ InternalScanner ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preCompact()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.preCompact(e, store, scanner, scanType);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preCompact()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void preCompactSelection(ObserverContext<RegionCoprocessorEnvironment> e, Store store,List<StoreFile> candidates) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preCompactSelection()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preCompactSelection(e, store, candidates);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preCompactSelection()");
+ }
+ }
+
+ @Override
+ public void preCreateTable(ObserverContext<MasterCoprocessorEnvironment> c, HTableDescriptor desc, HRegionInfo[] regions) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preCreateTable()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preCreateTable(c, desc, regions);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preCreateTable()");
+ }
+ }
+
+ @Override
+ public void preDelete(ObserverContext<RegionCoprocessorEnvironment> c, Delete delete, WALEdit edit, Durability durability) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preDelete()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preDelete(c, delete, edit, durability);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preDelete()");
+ }
+ }
+
+ @Override
+ public void preDeleteColumn(ObserverContext<MasterCoprocessorEnvironment> c,TableName tableName, byte[] col) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preDeleteColumn()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preDeleteColumn(c, tableName, col);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preDeleteColumn()");
+ }
+ }
+
+ @Override
+ public void preDeleteSnapshot(ObserverContext<MasterCoprocessorEnvironment> ctx, SnapshotDescription snapshot) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preDeleteSnapshot()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preDeleteSnapshot(ctx, snapshot);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preDeleteSnapshot()");
+ }
+ }
+
+ @Override
+ public void preDeleteTable(ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preDeleteTable()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preDeleteTable(c, tableName);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preDeleteTable()");
+ }
+ }
+
+ @Override
+ public void preDisableTable(ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preDisableTable()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preDisableTable(c, tableName);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preDisableTable()");
+ }
+ }
+
+ @Override
+ public void preEnableTable(ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preEnableTable()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preEnableTable(c, tableName);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preEnableTable()");
+ }
+ }
+
+ @Override
+ public boolean preExists(ObserverContext<RegionCoprocessorEnvironment> c, Get get, boolean exists) throws IOException {
+ boolean ret = false;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preExists()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.preExists(c, get, exists);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preExists()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void preFlush(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preFlush()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preFlush(e);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preFlush()");
+ }
+ }
+
+ @Override
+ public void preGetClosestRowBefore( ObserverContext<RegionCoprocessorEnvironment> c, byte[] row, byte[] family, Result result) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preGetClosestRowBefore()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preGetClosestRowBefore(c, row, family, result);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preGetClosestRowBefore()");
+ }
+ }
+
+ @Override
+ public Result preIncrement(ObserverContext<RegionCoprocessorEnvironment> c, Increment increment) throws IOException {
+ Result ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preIncrement()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.preIncrement(c, increment);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preIncrement()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public long preIncrementColumnValue(ObserverContext<RegionCoprocessorEnvironment> c, byte[] row,byte[] family, byte[] qualifier, long amount, boolean writeToWAL) throws IOException {
+ long ret;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preIncrementColumnValue()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.preIncrementColumnValue(c, row, family, qualifier, amount,writeToWAL);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preIncrementColumnValue()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void preModifyColumn( ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName, HColumnDescriptor descriptor) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preModifyColumn()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preModifyColumn(c, tableName, descriptor);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preModifyColumn()");
+ }
+ }
+
+ @Override
+ public void preModifyTable(ObserverContext<MasterCoprocessorEnvironment> c, TableName tableName, HTableDescriptor htd) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preModifyTable()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preModifyTable(c, tableName, htd);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preModifyTable()");
+ }
+ }
+
+ @Override
+ public void preMove(ObserverContext<MasterCoprocessorEnvironment> c, HRegionInfo region, ServerName srcServer, ServerName destServer) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preMove()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preMove(c, region, srcServer, destServer);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preMove()");
+ }
+ }
+
+ @Override
+ public void preOpen(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preOpen()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preOpen(e);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preOpen()");
+ }
+ }
+
+ @Override
+ public void preRestoreSnapshot( ObserverContext<MasterCoprocessorEnvironment> ctx, SnapshotDescription snapshot, HTableDescriptor hTableDescriptor) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preRestoreSnapshot()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preRestoreSnapshot(ctx, snapshot, hTableDescriptor);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preRestoreSnapshot()");
+ }
+ }
+
+ @Override
+ public void preScannerClose(ObserverContext<RegionCoprocessorEnvironment> c, InternalScanner s) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preScannerClose()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preScannerClose(c, s);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preScannerClose()");
+ }
+ }
+
+ @Override
+ public boolean preScannerNext(ObserverContext<RegionCoprocessorEnvironment> c, InternalScanner s, List<Result> result, int limit, boolean hasNext) throws IOException {
+ boolean ret = false;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preScannerNext()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.preScannerNext(c, s, result, limit, hasNext);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preScannerNext()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public RegionScanner preScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c, Scan scan, RegionScanner s) throws IOException {
+ RegionScanner ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preScannerOpen()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.preScannerOpen(c, scan, s);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preScannerOpen()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void preShutdown(ObserverContext<MasterCoprocessorEnvironment> c) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preShutdown()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preShutdown(c);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preShutdown()");
+ }
+ }
+
+ @Override
+ public void preSnapshot(ObserverContext<MasterCoprocessorEnvironment> ctx, SnapshotDescription snapshot, HTableDescriptor hTableDescriptor) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preSnapshot()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preSnapshot(ctx, snapshot, hTableDescriptor);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preSnapshot()");
+ }
+ }
+
+ @Override
+ public void preSplit(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preSplit()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preSplit(e);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preSplit()");
+ }
+ }
+
+ @Override
+ public void preStopMaster(ObserverContext<MasterCoprocessorEnvironment> c) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preStopMaster()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preStopMaster(c);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preStopMaster()");
+ }
+ }
+
+ @Override
+ public void preStopRegionServer( ObserverContext<RegionServerCoprocessorEnvironment> env) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preStopRegionServer()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionServerObserver.preStopRegionServer(env);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preStopRegionServer()");
+ }
+ }
+
+ @Override
+ public void preUnassign(ObserverContext<MasterCoprocessorEnvironment> c, HRegionInfo regionInfo, boolean force) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preUnassign()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preUnassign(c, regionInfo, force);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preUnassign()");
+ }
+ }
+
+ @Override
+ public void preSetUserQuota(ObserverContext<MasterCoprocessorEnvironment> ctx, String userName, Quotas quotas) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preSetUserQuota()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preSetUserQuota(ctx, userName, quotas);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preSetUserQuota()");
+ }
+ }
+
+ @Override
+ public void preSetUserQuota( ObserverContext<MasterCoprocessorEnvironment> ctx, String userName, TableName tableName, Quotas quotas) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preSetUserQuota()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preSetUserQuota(ctx, userName, tableName, quotas);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preSetUserQuota()");
+ }
+ }
+
+ @Override
+ public void preSetUserQuota(ObserverContext<MasterCoprocessorEnvironment> ctx, String userName, String namespace, Quotas quotas) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preSetUserQuota()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preSetUserQuota(ctx, userName, namespace, quotas);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preSetUserQuota()");
+ }
+ }
+
+ @Override
+ public void preSetTableQuota(ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName, Quotas quotas) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preSetTableQuota()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preSetTableQuota(ctx, tableName, quotas);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preSetTableQuota()");
+ }
+ }
+
+ @Override
+ public void preSetNamespaceQuota(ObserverContext<MasterCoprocessorEnvironment> ctx, String namespace, Quotas quotas) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preSetNamespaceQuota()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preSetNamespaceQuota(ctx, namespace, quotas);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preSetNamespaceQuota()");
+ }
+ }
+
+ @Override
+ public void start(CoprocessorEnvironment env) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.start()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.start(env);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.start()");
+ }
+ }
+
+ @Override
+ public void prePut(ObserverContext<RegionCoprocessorEnvironment> c, Put put, WALEdit edit, Durability durability) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.prePut()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.prePut(c, put, edit, durability);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.prePut()");
+ }
+ }
+
+ @Override
+ public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> rEnv, Get get, List<Cell> result) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preGetOp()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preGetOp(rEnv, get, result);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preGetOp()");
+ }
+ }
+
+ @Override
+ public void preRegionOffline( ObserverContext<MasterCoprocessorEnvironment> c,HRegionInfo regionInfo) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preRegionOffline()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preRegionOffline(c, regionInfo);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preRegionOffline()");
+ }
+ }
+
+ @Override
+ public void preCreateNamespace(ObserverContext<MasterCoprocessorEnvironment> ctx,NamespaceDescriptor ns) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preCreateNamespace()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preCreateNamespace(ctx, ns);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preCreateNamespace()");
+ }
+ }
+
+ @Override
+ public void preDeleteNamespace( ObserverContext<MasterCoprocessorEnvironment> ctx, String namespace) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preDeleteNamespace()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preDeleteNamespace(ctx, namespace);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preDeleteNamespace()");
+ }
+ }
+
+ @Override
+ public void preModifyNamespace(ObserverContext<MasterCoprocessorEnvironment> ctx, NamespaceDescriptor ns) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preModifyNamespace()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preModifyNamespace(ctx, ns);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preModifyNamespace()");
+ }
+ }
+
+ @Override
+ public void postGetTableDescriptors(ObserverContext<MasterCoprocessorEnvironment> ctx, List<TableName> tableNamesList, List<HTableDescriptor> descriptors, String regex) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postGetTableDescriptors()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.postGetTableDescriptors(ctx, tableNamesList, descriptors, regex);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postGetTableDescriptors()");
+ }
+ }
+
+ @Override
+ public void preMerge(ObserverContext<RegionServerCoprocessorEnvironment> ctx, Region regionA, Region regionB) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preMerge()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionServerObserver.preMerge(ctx, regionA, regionB);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preMerge()");
+ }
+ }
+
+ @Override
+ public void prePrepareBulkLoad(ObserverContext<RegionCoprocessorEnvironment> ctx, PrepareBulkLoadRequest request) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.prePrepareBulkLoad()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implBulkLoadObserver.prePrepareBulkLoad(ctx, request);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.prePrepareBulkLoad()");
+ }
+ }
+
+ @Override
+ public void preCleanupBulkLoad(ObserverContext<RegionCoprocessorEnvironment> ctx, CleanupBulkLoadRequest request) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preCleanupBulkLoad()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implBulkLoadObserver.preCleanupBulkLoad(ctx, request);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preCleanupBulkLoad()");
+ }
+ }
+
+ @Override
+ public void grant(RpcController controller, GrantRequest request, RpcCallback<GrantResponse> done) {
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.grant()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implAccessControlService.grant(controller, request, done);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.grant()");
+ }
+ }
+
+ @Override
+ public void revoke(RpcController controller, RevokeRequest request, RpcCallback<RevokeResponse> done) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.revoke()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implAccessControlService.revoke(controller, request, done);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.revoke()");
+ }
+ }
+
+ @Override
+ public void checkPermissions(RpcController controller, CheckPermissionsRequest request, RpcCallback<CheckPermissionsResponse> done) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.checkPermissions()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implAccessControlService.checkPermissions(controller, request, done);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.checkPermissions()");
+ }
+ }
+
+ @Override
+ public void getUserPermissions(RpcController controller, GetUserPermissionsRequest request, RpcCallback<GetUserPermissionsResponse> done) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.getUserPermissions()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implAccessControlService.getUserPermissions(controller, request, done);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.getUserPermissions()");
+ }
+ }
+
+ @Override
+ public void stop(CoprocessorEnvironment env) throws IOException {
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.stop()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.stop(env);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.stop()");
+ }
+ }
+
+ @Override
+ public void postMerge(ObserverContext<RegionServerCoprocessorEnvironment> c, Region regionA, Region regionB, Region mergedRegion) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postMerge()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionServerObserver.postMerge(c,regionA, regionB, mergedRegion);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postMerge()");
+ }
+ }
+
+ @Override
+ public void preMergeCommit(ObserverContext<RegionServerCoprocessorEnvironment> ctx, Region regionA, Region regionB, List<Mutation> metaEntries) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preMergeCommit()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionServerObserver.preMergeCommit(ctx ,regionA, regionB, metaEntries);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preMergeCommit()");
+ }
+ }
+
+ @Override
+ public void postMergeCommit(ObserverContext<RegionServerCoprocessorEnvironment> ctx, Region regionA, Region regionB, Region mergedRegion) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postMergeCommit()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionServerObserver.postMergeCommit(ctx ,regionA, regionB, mergedRegion);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postMergeCommit()");
+ }
+ }
+
+ @Override
+ public void preRollBackMerge(ObserverContext<RegionServerCoprocessorEnvironment> ctx,Region regionA, Region regionB) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preRollBackMerge()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionServerObserver.preRollBackMerge(ctx ,regionA, regionB);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preRollBackMerge()");
+ }
+ }
+
+ @Override
+ public void postRollBackMerge(ObserverContext<RegionServerCoprocessorEnvironment> ctx, Region regionA, Region regionB) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postRollBackMerge()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionServerObserver.postRollBackMerge(ctx ,regionA, regionB);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postRollBackMerge()");
+ }
+ }
+
+ @Override
+ public void preRollWALWriterRequest(ObserverContext<RegionServerCoprocessorEnvironment> ctx) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preRollWALWriterRequest()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionServerObserver.preRollWALWriterRequest(ctx);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preRollWALWriterRequest()");
+ }
+ }
+
+ @Override
+ public void postRollWALWriterRequest(ObserverContext<RegionServerCoprocessorEnvironment> ctx) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postRollWALWriterRequest()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionServerObserver.postRollWALWriterRequest(ctx);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postRollWALWriterRequest()");
+ }
+ }
+
+ @Override
+ public ReplicationEndpoint postCreateReplicationEndPoint(ObserverContext<RegionServerCoprocessorEnvironment> ctx, ReplicationEndpoint endpoint) {
+
+ ReplicationEndpoint ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postCreateReplicationEndPoint()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionServerObserver.postCreateReplicationEndPoint(ctx,endpoint);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postCreateReplicationEndPoint()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void preReplicateLogEntries(ObserverContext<RegionServerCoprocessorEnvironment> ctx, List<WALEntry> entries, CellScanner cells) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preReplicateLogEntries()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionServerObserver.preReplicateLogEntries(ctx, entries, cells);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preReplicateLogEntries()");
+ }
+ }
+
+ @Override
+ public void postReplicateLogEntries(ObserverContext<RegionServerCoprocessorEnvironment> ctx, List<WALEntry> entries, CellScanner cells) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postReplicateLogEntries()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionServerObserver.postReplicateLogEntries(ctx, entries, cells);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postReplicateLogEntries()");
+ }
+ }
+
+ @Override
+ public void postOpen(ObserverContext<RegionCoprocessorEnvironment> c) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postOpen()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postOpen(c);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postOpen()");
+ }
+ }
+
+ @Override
+ public void postLogReplay(ObserverContext<RegionCoprocessorEnvironment> c) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postLogReplay()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postLogReplay(c);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postLogReplay()");
+ }
+ }
+
+ @Override
+ public InternalScanner preFlushScannerOpen( ObserverContext<RegionCoprocessorEnvironment> c, Store store, KeyValueScanner memstoreScanner, InternalScanner s) throws IOException {
+
+ InternalScanner ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preFlushScannerOpen()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.preFlushScannerOpen(c, store, memstoreScanner, s);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preFlushScannerOpen()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public InternalScanner preFlush(ObserverContext<RegionCoprocessorEnvironment> c, Store store, InternalScanner scanner) throws IOException {
+
+ InternalScanner ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preFlush()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.preFlush(c, store, scanner);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preFlush()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void postFlush(ObserverContext<RegionCoprocessorEnvironment> c) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postFlush()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postFlush(c);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postFlush()");
+ }
+ }
+
+ @Override
+ public void postFlush(ObserverContext<RegionCoprocessorEnvironment> c, Store store, StoreFile resultFile) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postFlush()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postFlush(c, store, resultFile);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postFlush()");
+ }
+ }
+
+ @Override
+ public void preCompactSelection(ObserverContext<RegionCoprocessorEnvironment> c, Store store, List<StoreFile> candidates, CompactionRequest request) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preCompactSelection()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preCompactSelection(c, store, candidates, request);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preCompactSelection()");
+ }
+ }
+
+ @Override
+ public void postCompactSelection(ObserverContext<RegionCoprocessorEnvironment> c, Store store, ImmutableList<StoreFile> selected, CompactionRequest request) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postCompactSelection()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postCompactSelection(c, store, selected, request);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postCompactSelection()");
+ }
+ }
+
+ @Override
+ public void postCompactSelection( ObserverContext<RegionCoprocessorEnvironment> c, Store store, ImmutableList<StoreFile> selected) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postCompactSelection()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postCompactSelection(c, store, selected);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postCompactSelection()");
+ }
+ }
+
+ @Override
+ public InternalScanner preCompact(ObserverContext<RegionCoprocessorEnvironment> c, Store store, InternalScanner scanner, ScanType scanType, CompactionRequest request) throws IOException {
+
+ InternalScanner ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preCompact()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preCompact(c, store, scanner, scanType, request);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preCompact()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public InternalScanner preCompactScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c, Store store, List<? extends KeyValueScanner> scanners, ScanType scanType,
+ long earliestPutTs, InternalScanner s, CompactionRequest request) throws IOException {
+ InternalScanner ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preCompactScannerOpen()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preCompactScannerOpen(c, store, scanners, scanType, earliestPutTs, s,request);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preCompactScannerOpen()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public InternalScanner preCompactScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c, Store store, List<? extends KeyValueScanner> scanners, ScanType scanType,
+ long earliestPutTs, InternalScanner s) throws IOException {
+ InternalScanner ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preCompactScannerOpen()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preCompactScannerOpen(c, store, scanners, scanType, earliestPutTs, s);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preCompactScannerOpen()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void postCompact(ObserverContext<RegionCoprocessorEnvironment> c, Store store, StoreFile resultFile, CompactionRequest request) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postCompact()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postCompact(c, store, resultFile, request);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postCompact()");
+ }
+ }
+
+ @Override
+ public void postCompact(ObserverContext<RegionCoprocessorEnvironment> c, Store store, StoreFile resultFile) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postCompact()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postCompact(c, store, resultFile);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postCompact()");
+ }
+ }
+
+ @Override
+ public void preSplit(ObserverContext<RegionCoprocessorEnvironment> c, byte[] splitRow) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preSplit()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preSplit(c, splitRow);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preSplit()");
+ }
+ }
+
+ @Override
+ public void postSplit(ObserverContext<RegionCoprocessorEnvironment> c, Region l, Region r) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postSplit()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postSplit(c, l, r);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postSplit()");
+ }
+ }
+
+ @Override
+ public void preSplitBeforePONR(ObserverContext<RegionCoprocessorEnvironment> ctx, byte[] splitKey, List<Mutation> metaEntries) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preSplitBeforePONR()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preSplitBeforePONR(ctx, splitKey, metaEntries);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preSplitBeforePONR()");
+ }
+ }
+
+ @Override
+ public void preSplitAfterPONR(ObserverContext<RegionCoprocessorEnvironment> ctx) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preSplitAfterPONR()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preSplitAfterPONR(ctx);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preSplitAfterPONR()");
+ }
+ }
+
+ @Override
+ public void preRollBackSplit(ObserverContext<RegionCoprocessorEnvironment> ctx) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preRollBackSplit()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preRollBackSplit(ctx);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preRollBackSplit()");
+ }
+ }
+
+ @Override
+ public void postRollBackSplit(ObserverContext<RegionCoprocessorEnvironment> ctx) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postRollBackSplit()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postRollBackSplit(ctx);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postRollBackSplit()");
+ }
+ }
+
+ @Override
+ public void postCompleteSplit(ObserverContext<RegionCoprocessorEnvironment> ctx) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postCompleteSplit()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postCompleteSplit(ctx);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postCompleteSplit()");
+ }
+ }
+
+ @Override
+ public void postClose(ObserverContext<RegionCoprocessorEnvironment> c, boolean abortRequested) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postClose()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postClose(c,abortRequested);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postClose()");
+ }
+ }
+
+ @Override
+ public void postGetClosestRowBefore(ObserverContext<RegionCoprocessorEnvironment> c, byte[] row, byte[] family, Result result) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postGetClosestRowBefore()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postGetClosestRowBefore(c, row, family, result);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postGetClosestRowBefore()");
+ }
+ }
+
+ @Override
+ public void postGetOp(ObserverContext<RegionCoprocessorEnvironment> c, Get get, List<Cell> result) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postGetOp()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postGetOp(c, get, result);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postGetOp()");
+ }
+ }
+
+ @Override
+ public boolean postExists(ObserverContext<RegionCoprocessorEnvironment> c, Get get, boolean exists) throws IOException {
+
+ boolean ret = false;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postExists()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.postExists(c, get, exists);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postExists()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void postPut(ObserverContext<RegionCoprocessorEnvironment> c, Put put, WALEdit edit, Durability durability) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postPut()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postPut(c, put, edit, durability);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postPut()");
+ }
+ }
+
+ @Override
+ public void prePrepareTimeStampForDeleteVersion( ObserverContext<RegionCoprocessorEnvironment> c, Mutation mutation, Cell cell, byte[] byteNow, Get get) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.prePrepareTimeStampForDeleteVersion()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.prePrepareTimeStampForDeleteVersion(c, mutation, cell, byteNow, get);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.prePrepareTimeStampForDeleteVersion()");
+ }
+ }
+
+ @Override
+ public void postDelete(ObserverContext<RegionCoprocessorEnvironment> c, Delete delete, WALEdit edit, Durability durability) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postDelete()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postDelete(c, delete, edit, durability);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postDelete()");
+ }
+ }
+
+ @Override
+ public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preBatchMutate()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preBatchMutate(c, miniBatchOp);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preBatchMutate()");
+ }
+ }
+
+ @Override
+ public void postBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postBatchMutate()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postBatchMutate(c, miniBatchOp);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postBatchMutate()");
+ }
+ }
+
+ @Override
+ public void postStartRegionOperation(ObserverContext<RegionCoprocessorEnvironment> ctx, Operation operation) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postStartRegionOperation()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postStartRegionOperation(ctx, operation);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postStartRegionOperation()");
+ }
+ }
+
+ @Override
+ public void postCloseRegionOperation(ObserverContext<RegionCoprocessorEnvironment> ctx, Operation operation) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postCloseRegionOperation()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postCloseRegionOperation(ctx, operation);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postCloseRegionOperation()");
+ }
+ }
+
+ @Override
+ public void postBatchMutateIndispensably(ObserverContext<RegionCoprocessorEnvironment> ctx, MiniBatchOperationInProgress<Mutation> miniBatchOp, boolean success) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postBatchMutateIndispensably()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postBatchMutateIndispensably(ctx, miniBatchOp, success);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postBatchMutateIndispensably()");
+ }
+ }
+
+ @Override
+ public boolean preCheckAndPutAfterRowLock(ObserverContext<RegionCoprocessorEnvironment> c, byte[] row, byte[] family, byte[] qualifier, CompareOp compareOp,
+ ByteArrayComparable comparator, Put put, boolean result) throws IOException {
+ boolean ret = false;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preCheckAndPutAfterRowLock()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.preCheckAndPutAfterRowLock(c, row, family, qualifier, compareOp, comparator, put, result);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preCheckAndPutAfterRowLock()");
+ }
+ return ret;
+ }
+
+ @Override
+ public boolean postCheckAndPut(ObserverContext<RegionCoprocessorEnvironment> c, byte[] row, byte[] family, byte[] qualifier, CompareOp compareOp,
+ ByteArrayComparable comparator, Put put, boolean result) throws IOException {
+ boolean ret = false;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postCheckAndPut()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.postCheckAndPut(c, row, family, qualifier, compareOp, comparator, put, result);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postCheckAndPut()");
+ }
+ return ret;
+ }
+
+ @Override
+ public boolean preCheckAndDeleteAfterRowLock(ObserverContext<RegionCoprocessorEnvironment> c, byte[] row, byte[] family, byte[] qualifier, CompareOp compareOp,
+ ByteArrayComparable comparator, Delete delete, boolean result) throws IOException {
+ boolean ret = false;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preCheckAndDeleteAfterRowLock()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.preCheckAndDeleteAfterRowLock(c, row, family, qualifier, compareOp, comparator, delete, result);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preCheckAndDeleteAfterRowLock()");
+ }
+ return ret;
+ }
+
+ @Override
+ public boolean postCheckAndDelete(ObserverContext<RegionCoprocessorEnvironment> c, byte[] row,byte[] family, byte[] qualifier, CompareOp compareOp,
+ ByteArrayComparable comparator, Delete delete, boolean result) throws IOException {
+ boolean ret = false;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postCheckAndDelete()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.postCheckAndDelete(c, row, family, qualifier, compareOp, comparator, delete, result);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postCheckAndDelete()");
+ }
+ return ret;
+ }
+
+ @Override
+ public long postIncrementColumnValue(ObserverContext<RegionCoprocessorEnvironment> c, byte[] row, byte[] family, byte[] qualifier, long amount, boolean writeToWAL, long result) throws IOException {
+ long ret = 0;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postIncrementColumnValue()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.postIncrementColumnValue(c, row, family, qualifier, amount, writeToWAL, result);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postIncrementColumnValue()");
+ }
+ return ret;
+ }
+
+ @Override
+ public Result preAppendAfterRowLock(ObserverContext<RegionCoprocessorEnvironment> c, Append append) throws IOException {
+ Result ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preAppendAfterRowLock()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.preAppendAfterRowLock(c, append);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preAppendAfterRowLock()");
+ }
+ return ret;
+ }
+
+ @Override
+ public Result postAppend(ObserverContext<RegionCoprocessorEnvironment> c, Append append, Result result) throws IOException {
+ Result ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postAppend()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.postAppend(c, append, result);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postAppend()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public Result preIncrementAfterRowLock(ObserverContext<RegionCoprocessorEnvironment> c, Increment increment) throws IOException {
+ Result ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preIncrementAfterRowLock()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.preIncrementAfterRowLock(c, increment);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preIncrementAfterRowLock()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public Result postIncrement(ObserverContext<RegionCoprocessorEnvironment> c, Increment increment, Result result) throws IOException {
+ Result ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postIncrement()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.postIncrement(c, increment, result );
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postIncrement()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public KeyValueScanner preStoreScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c, Store store, Scan scan, NavigableSet<byte[]> targetCols, KeyValueScanner s) throws IOException {
+ KeyValueScanner ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preStoreScannerOpen()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.preStoreScannerOpen(c, store, scan, targetCols, s);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preStoreScannerOpen()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public boolean postScannerNext( ObserverContext<RegionCoprocessorEnvironment> c, InternalScanner s, List<Result> result, int limit, boolean hasNext) throws IOException {
+ boolean ret = false;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postScannerNext()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.postScannerNext(c, s, result, limit, hasNext);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postScannerNext()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public boolean postScannerFilterRow( ObserverContext<RegionCoprocessorEnvironment> c, InternalScanner s, byte[] currentRow, int offset, short length, boolean hasMore) throws IOException {
+
+ boolean ret = false;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postScannerFilterRow()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.postScannerFilterRow(c, s, currentRow, offset, length, hasMore);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postScannerFilterRow()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void preWALRestore(ObserverContext<? extends RegionCoprocessorEnvironment> ctx, HRegionInfo info, WALKey logKey, WALEdit logEdit) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preWALRestore()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.preWALRestore(ctx, info, logKey, logEdit);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preWALRestore()");
+ }
+ }
+
+ @Override
+ public void postWALRestore( ObserverContext<? extends RegionCoprocessorEnvironment> ctx, HRegionInfo info, WALKey logKey, WALEdit logEdit) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postWALRestore()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implRegionObserver.postWALRestore(ctx, info, logKey, logEdit);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postWALRestore()");
+ }
+ }
+
+ @Override
+ public boolean postBulkLoadHFile(ObserverContext<RegionCoprocessorEnvironment> ctx, List<Pair<byte[], String>> familyPaths, boolean hasLoaded) throws IOException {
+
+ boolean ret = false;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postBulkLoadHFile()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.postBulkLoadHFile(ctx, familyPaths, hasLoaded);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postBulkLoadHFile()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public Reader preStoreFileReaderOpen(ObserverContext<RegionCoprocessorEnvironment> ctx, FileSystem fs, Path p, FSDataInputStreamWrapper in, long size,
+ CacheConfig cacheConf, Reference r, Reader reader) throws IOException {
+ Reader ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preStoreFileReaderOpen()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.preStoreFileReaderOpen(ctx, fs, p, in, size, cacheConf, r, reader);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preStoreFileReaderOpen()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public Reader postStoreFileReaderOpen(ObserverContext<RegionCoprocessorEnvironment> ctx, FileSystem fs, Path p, FSDataInputStreamWrapper in, long size,
+ CacheConfig cacheConf, Reference r, Reader reader) throws IOException {
+ Reader ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postStoreFileReaderOpen()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.postStoreFileReaderOpen(ctx, fs, p, in, size, cacheConf, r, reader);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postStoreFileReaderOpen()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public Cell postMutationBeforeWAL(ObserverContext<RegionCoprocessorEnvironment> ctx, MutationType opType, Mutation mutation, Cell oldCell, Cell newCell) throws IOException {
+ Cell ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postMutationBeforeWAL()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.postMutationBeforeWAL(ctx, opType, mutation, oldCell, newCell);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postMutationBeforeWAL()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public DeleteTracker postInstantiateDeleteTracker( ObserverContext<RegionCoprocessorEnvironment> ctx, DeleteTracker delTracker) throws IOException {
+ DeleteTracker ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postInstantiateDeleteTracker()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = implRegionObserver.postInstantiateDeleteTracker(ctx, delTracker);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postInstantiateDeleteTracker()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void postCreateTable(ObserverContext<MasterCoprocessorEnvironment> ctx, HTableDescriptor desc, HRegionInfo[] regions) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postCreateTable()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.postCreateTable(ctx, desc, regions);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postCreateTable()");
+ }
+ }
+
+ @Override
+ public void preCreateTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx, HTableDescriptor desc, HRegionInfo[] regions) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preCreateTableHandler()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preCreateTableHandler(ctx, desc, regions);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preCreateTableHandler()");
+ }
+ }
+
+ @Override
+ public void postCreateTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx, HTableDescriptor desc, HRegionInfo[] regions) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postCreateTableHandler()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.postCreateTableHandler(ctx, desc, regions);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postCreateTableHandler()");
+ }
+ }
+
+ @Override
+ public void postDeleteTable(ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postDeleteTable()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.postDeleteTable(ctx, tableName);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postDeleteTable()");
+ }
+ }
+
+ @Override
+ public void preDeleteTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx,TableName tableName) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preDeleteTableHandler()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preDeleteTableHandler(ctx, tableName);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preDeleteTableHandler()");
+ }
+ }
+
+ @Override
+ public void postDeleteTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postDeleteTableHandler()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.postDeleteTableHandler(ctx, tableName);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postDeleteTableHandler()");
+ }
+ }
+
+ @Override
+ public void preTruncateTable(ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preTruncateTable()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preTruncateTable(ctx, tableName);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preTruncateTable()");
+ }
+ }
+
+ @Override
+ public void postTruncateTable(ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postTruncateTable()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.postTruncateTable(ctx, tableName);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postTruncateTable()");
+ }
+ }
+
+ @Override
+ public void preTruncateTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preTruncateTableHandler()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preTruncateTableHandler(ctx, tableName);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preTruncateTableHandler()");
+ }
+ }
+
+ @Override
+ public void postTruncateTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postTruncateTableHandler()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.postTruncateTableHandler(ctx, tableName);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postTruncateTableHandler()");
+ }
+ }
+
+ @Override
+ public void postModifyTable(ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName, HTableDescriptor htd) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postModifyTable()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.postModifyTable(ctx, tableName, htd);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postModifyTable()");
+ }
+ }
+
+ @Override
+ public void preModifyTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx,TableName tableName, HTableDescriptor htd) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preModifyTableHandler()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preModifyTableHandler(ctx, tableName, htd);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preModifyTableHandler()");
+ }
+ }
+
+ @Override
+ public void postModifyTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName, HTableDescriptor htd) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postModifyTableHandler()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.postModifyTableHandler(ctx, tableName, htd);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postModifyTableHandler()");
+ }
+ }
+
+ @Override
+ public void postAddColumn(ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName, HColumnDescriptor column) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postAddColumn()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.postAddColumn(ctx, tableName, column);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postAddColumn()");
+ }
+ }
+
+ @Override
+ public void preAddColumnHandler(ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName, HColumnDescriptor column) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preAddColumnHandler()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preAddColumnHandler(ctx, tableName, column);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preAddColumnHandler()");
+ }
+ }
+
+ @Override
+ public void postAddColumnHandler(ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName, HColumnDescriptor column) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postAddColumnHandler()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.postAddColumnHandler(ctx, tableName, column);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postAddColumnHandler()");
+ }
+ }
+
+ @Override
+ public void postModifyColumn(ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName, HColumnDescriptor descriptor) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postModifyColumn()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.postModifyColumn(ctx, tableName, descriptor);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postModifyColumn()");
+ }
+ }
+
+ @Override
+ public void preModifyColumnHandler(ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName, HColumnDescriptor descriptor) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.preModifyColumnHandler()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.preModifyColumnHandler(ctx, tableName, descriptor);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.preModifyColumnHandler()");
+ }
+ }
+
+ @Override
+ public void postModifyColumnHandler(ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName, HColumnDescriptor descriptor) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postModifyColumnHandler()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ implMasterObserver.postModifyColumnHandler(ctx, tableName, descriptor);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerAuthorizationCoprocessor.postModifyColumnHandler()");
+ }
+ }
+
+ @Override
+ public void postDeleteColumn(ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName, byte[] c) throws IOException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerAuthorizationCoprocessor.postDeleteColumn()");
+ }
+
+ try {
+ activatePluginClassLoader();
+
<TRUNCATED>
[2/6] incubator-ranger git commit: RANGER-586: Ranger plugins should
not add dependent libraries to component's CLASSPATH
Posted by rm...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-hdfs-plugin-shim/dependency-reduced-pom.xml
----------------------------------------------------------------------
diff --git a/ranger-hdfs-plugin-shim/dependency-reduced-pom.xml b/ranger-hdfs-plugin-shim/dependency-reduced-pom.xml
new file mode 100644
index 0000000..5f0e7c9
--- /dev/null
+++ b/ranger-hdfs-plugin-shim/dependency-reduced-pom.xml
@@ -0,0 +1,188 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>ranger</artifactId>
+ <groupId>org.apache.ranger</groupId>
+ <version>0.5.0</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>security_plugins.ranger-hdfs-plugin-shim</groupId>
+ <artifactId>ranger-hdfs-plugin-shim</artifactId>
+ <name>Hdfs Security Plugin Shim</name>
+ <description>Hdfs Security Plugins Shim</description>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <archive>
+ <index>true</index>
+ <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
+ <manifest>
+ <addDefaultImplementationEntries />
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-shade-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <artifactSet>
+ <includes>
+ <include>javassist:javassist:jar:</include>
+ </includes>
+ </artifactSet>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.2.4</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.2</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.1.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.calcite</groupId>
+ <artifactId>calcite-core</artifactId>
+ <version>0.9.2-incubating</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.calcite</groupId>
+ <artifactId>calcite-avatica</artifactId>
+ <version>0.9.2-incubating</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tez</groupId>
+ <artifactId>tez-api</artifactId>
+ <version>0.5.2</version>
+ <scope>compile</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tez</groupId>
+ <artifactId>tez-runtime-library</artifactId>
+ <version>0.5.2</version>
+ <scope>compile</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tez</groupId>
+ <artifactId>tez-runtime-internals</artifactId>
+ <version>0.5.2</version>
+ <scope>compile</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tez</groupId>
+ <artifactId>tez-mapreduce</artifactId>
+ <version>0.5.2</version>
+ <scope>compile</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-common</artifactId>
+ <version>2.7.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-hdfs</artifactId>
+ <version>2.7.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hbase</groupId>
+ <artifactId>hbase-server</artifactId>
+ <version>1.1.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-common</artifactId>
+ <version>1.2.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-service</artifactId>
+ <version>1.2.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugins-audit</groupId>
+ <artifactId>ranger-plugins-audit</artifactId>
+ <version>0.5.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugins-common</groupId>
+ <artifactId>ranger-plugins-common</artifactId>
+ <version>0.5.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugin-classloader</groupId>
+ <artifactId>ranger-plugin-classloader</artifactId>
+ <version>0.5.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>hamcrest-core</artifactId>
+ <groupId>org.hamcrest</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.8.4</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>objenesis</artifactId>
+ <groupId>org.objenesis</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>hamcrest-core</artifactId>
+ <groupId>org.hamcrest</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+</project>
+
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-hdfs-plugin-shim/pom.xml
----------------------------------------------------------------------
diff --git a/ranger-hdfs-plugin-shim/pom.xml b/ranger-hdfs-plugin-shim/pom.xml
new file mode 100644
index 0000000..a44abb3
--- /dev/null
+++ b/ranger-hdfs-plugin-shim/pom.xml
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>security_plugins.ranger-hdfs-plugin-shim</groupId>
+ <artifactId>ranger-hdfs-plugin-shim</artifactId>
+ <name>Hdfs Security Plugin Shim</name>
+ <description>Hdfs Security Plugins Shim</description>
+ <packaging>jar</packaging>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <parent>
+ <groupId>org.apache.ranger</groupId>
+ <artifactId>ranger</artifactId>
+ <version>0.5.0</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <dependencies>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>${commons.logging.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-common</artifactId>
+ <version>${hadoop.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-hdfs</artifactId>
+ <version>${hadoop.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugins-audit</groupId>
+ <artifactId>ranger-plugins-audit</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugins-common</groupId>
+ <artifactId>ranger-plugins-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugin-classloader</groupId>
+ <artifactId>ranger-plugin-classloader</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-hdfs-plugin-shim/src/main/java/org/apache/ranger/authorization/hadoop/RangerHdfsAuthorizer.java
----------------------------------------------------------------------
diff --git a/ranger-hdfs-plugin-shim/src/main/java/org/apache/ranger/authorization/hadoop/RangerHdfsAuthorizer.java b/ranger-hdfs-plugin-shim/src/main/java/org/apache/ranger/authorization/hadoop/RangerHdfsAuthorizer.java
new file mode 100644
index 0000000..ca69834
--- /dev/null
+++ b/ranger-hdfs-plugin-shim/src/main/java/org/apache/ranger/authorization/hadoop/RangerHdfsAuthorizer.java
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.authorization.hadoop;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hdfs.server.namenode.INodeAttributeProvider;
+import org.apache.hadoop.hdfs.server.namenode.INodeAttributes;
+import org.apache.ranger.plugin.classloader.RangerPluginClassLoader;
+
+public class RangerHdfsAuthorizer extends INodeAttributeProvider {
+ private static final Log LOG = LogFactory.getLog(RangerHdfsAuthorizer.class);
+
+ private static final String RANGER_PLUGIN_TYPE = "hdfs";
+ private static final String[] RANGER_PLUGIN_LIB_DIR = new String[] {"lib/ranger-hdfs-plugin"};
+ private static final String RANGER_HDFS_AUTHORIZER_IMPL_CLASSNAME = "org.apache.ranger.authorization.hadoop.RangerHdfsAuthorizerImpl";
+
+ private INodeAttributeProvider rangerHdfsAuthorizerImpl = null;
+ private static RangerPluginClassLoader rangerPluginClassLoader = null;
+
+ public RangerHdfsAuthorizer() {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHdfsAuthorizer.RangerHdfsAuthorizer()");
+ }
+
+ this.init();
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHdfsAuthorizer.RangerHdfsAuthorizer()");
+ }
+ }
+
+ public void init(){
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHdfsAuthorizer.init()");
+ }
+
+ try {
+
+ rangerPluginClassLoader = RangerPluginClassLoader.getInstance(RANGER_PLUGIN_TYPE, this.getClass());
+
+ @SuppressWarnings("unchecked")
+ Class<INodeAttributeProvider> cls = (Class<INodeAttributeProvider>) Class.forName(RANGER_HDFS_AUTHORIZER_IMPL_CLASSNAME, true, rangerPluginClassLoader);
+
+ activatePluginClassLoader();
+
+ rangerHdfsAuthorizerImpl = cls.newInstance();
+ } catch (Exception e) {
+ // check what need to be done
+ LOG.error("Error Enabling RangerHdfsPluing", e);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHdfsAuthorizer.init()");
+ }
+ }
+
+ @Override
+ public void start() {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHdfsAuthorizer.start()");
+ }
+
+ try {
+ activatePluginClassLoader();
+
+ rangerHdfsAuthorizerImpl.start();
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHdfsAuthorizer.start()");
+ }
+ }
+
+ @Override
+ public void stop() {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHdfsAuthorizer.stop()");
+ }
+
+ try {
+ activatePluginClassLoader();
+
+ rangerHdfsAuthorizerImpl.stop();
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHdfsAuthorizer.stop()");
+ }
+ }
+
+ @Override
+ public INodeAttributes getAttributes(String fullPath, INodeAttributes inode) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHdfsAuthorizer.getAttributes(" + fullPath + ")");
+ }
+
+ INodeAttributes ret = null;
+
+ try {
+ activatePluginClassLoader();
+
+ ret = rangerHdfsAuthorizerImpl.getAttributes(fullPath,inode); // return default attributes
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHdfsAuthorizer.getAttributes(" + fullPath + "): " + ret);
+ }
+
+ return ret;
+ }
+
+ @Override
+ public INodeAttributes getAttributes(String[] pathElements, INodeAttributes inode) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHdfsAuthorizer.getAttributes(pathElementsCount=" + (pathElements == null ? 0 : pathElements.length) + ")");
+ }
+
+ INodeAttributes ret = null;
+
+ try {
+ activatePluginClassLoader();
+
+ ret = rangerHdfsAuthorizerImpl.getAttributes(pathElements,inode);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHdfsAuthorizer.getAttributes(pathElementsCount=" + (pathElements == null ? 0 : pathElements.length) + "): " + ret);
+ }
+
+ return ret;
+ }
+
+ @Override
+ public AccessControlEnforcer getExternalAccessControlEnforcer(AccessControlEnforcer defaultEnforcer) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHdfsAuthorizer.getExternalAccessControlEnforcer()");
+ }
+
+ AccessControlEnforcer ret = null;
+
+ try {
+ activatePluginClassLoader();
+
+ ret = rangerHdfsAuthorizerImpl.getExternalAccessControlEnforcer(defaultEnforcer);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHdfsAuthorizer.getExternalAccessControlEnforcer()");
+ }
+
+ return ret;
+ }
+
+ private void activatePluginClassLoader() {
+ if(rangerPluginClassLoader != null) {
+ rangerPluginClassLoader.activate();
+ }
+ }
+
+ private void deactivatePluginClassLoader() {
+ if(rangerPluginClassLoader != null) {
+ rangerPluginClassLoader.deactivate();
+ }
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-hive-plugin-shim/pom.xml
----------------------------------------------------------------------
diff --git a/ranger-hive-plugin-shim/pom.xml b/ranger-hive-plugin-shim/pom.xml
new file mode 100644
index 0000000..1ff8349
--- /dev/null
+++ b/ranger-hive-plugin-shim/pom.xml
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>security_plugins.ranger-hive-plugin-shim</groupId>
+ <artifactId>ranger-hive-plugin-shim</artifactId>
+ <name>Hive Security Plugin Shim</name>
+ <description>Hive Security Plugins Shim</description>
+ <packaging>jar</packaging>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <parent>
+ <groupId>org.apache.ranger</groupId>
+ <artifactId>ranger</artifactId>
+ <version>0.5.0</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <dependencies>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>${commons.logging.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-common</artifactId>
+ <version>${hadoop.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-hdfs</artifactId>
+ <version>${hadoop.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-common</artifactId>
+ <version>${hive.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-service</artifactId>
+ <version>${hive.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-exec</artifactId>
+ <version>${hive.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-metastore</artifactId>
+ <version>${hive.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-jdbc</artifactId>
+ <version>${hive.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-jdbc</artifactId>
+ <version>${hive.version}</version>
+ <classifier>standalone</classifier>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugins-audit</groupId>
+ <artifactId>ranger-plugins-audit</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugins-common</groupId>
+ <artifactId>ranger-plugins-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugin-classloader</groupId>
+ <artifactId>ranger-plugin-classloader</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-hive-plugin-shim/src/main/java/com/xasecure/authorization/hive/authorizer/XaSecureHiveAuthorizerFactory.java
----------------------------------------------------------------------
diff --git a/ranger-hive-plugin-shim/src/main/java/com/xasecure/authorization/hive/authorizer/XaSecureHiveAuthorizerFactory.java b/ranger-hive-plugin-shim/src/main/java/com/xasecure/authorization/hive/authorizer/XaSecureHiveAuthorizerFactory.java
new file mode 100644
index 0000000..592b667
--- /dev/null
+++ b/ranger-hive-plugin-shim/src/main/java/com/xasecure/authorization/hive/authorizer/XaSecureHiveAuthorizerFactory.java
@@ -0,0 +1,32 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.xasecure.authorization.hive.authorizer;
+
+import org.apache.ranger.authorization.hive.authorizer.RangerHiveAuthorizerFactory;
+
+/**
+ * This class exists only to provide for seamless upgrade/downgrade capabilities. Coprocessor name is in hbase config files in /etc/.../conf which
+ * is not only out of bounds for any upgrade script but also must be of a form to allow for downgrad! Thus when class names were changed XaSecure* -> Ranger*
+ * this shell class serves to allow for seamles upgrade as well as downgrade.
+ *
+ * This class is final because if one needs to customize coprocessor it is expected that RangerAuthorizationCoprocessor would be modified/extended as that is
+ * the "real" coprocessor! This class, hence, should NEVER be more than an EMPTY shell!
+ */
+public final class XaSecureHiveAuthorizerFactory extends RangerHiveAuthorizerFactory {
+}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-hive-plugin-shim/src/main/java/org/apache/ranger/authorization/hive/authorizer/RangerHiveAuthorizerFactory.java
----------------------------------------------------------------------
diff --git a/ranger-hive-plugin-shim/src/main/java/org/apache/ranger/authorization/hive/authorizer/RangerHiveAuthorizerFactory.java b/ranger-hive-plugin-shim/src/main/java/org/apache/ranger/authorization/hive/authorizer/RangerHiveAuthorizerFactory.java
new file mode 100644
index 0000000..00c1ef2
--- /dev/null
+++ b/ranger-hive-plugin-shim/src/main/java/org/apache/ranger/authorization/hive/authorizer/RangerHiveAuthorizerFactory.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.authorization.hive.authorizer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.ql.security.HiveAuthenticationProvider;
+import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthorizer;
+import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthorizerFactory;
+import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzPluginException;
+import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveMetastoreClientFactory;
+import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzSessionContext;
+import org.apache.ranger.plugin.classloader.RangerPluginClassLoader;
+
+
+public class RangerHiveAuthorizerFactory implements HiveAuthorizerFactory {
+
+ private static final Log LOG = LogFactory.getLog(RangerHiveAuthorizerFactory.class);
+
+ private static final String RANGER_PLUGIN_TYPE = "hive";
+ private static final String[] RANGER_PLUGIN_LIB_DIR = new String[] {"lib/ranger-hive-plugin"};
+ private static final String RANGER_HIVE_AUTHORIZER_IMPL_CLASSNAME = "org.apache.ranger.authorization.hive.authorizer.RangerHiveAuthorizerFactoryImpl";
+
+ private HiveAuthorizerFactory rangerHiveAuthorizerFactoryImpl = null;
+ private RangerPluginClassLoader rangerPluginClassLoader = null;
+
+
+ public RangerHiveAuthorizerFactory() {
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHiveAuthorizerFactory.RangerHiveAuthorizerFactory()");
+ }
+
+ this.init();
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHiveAuthorizerFactory.RangerHiveAuthorizerFactory()");
+ }
+ }
+
+ public void init(){
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHiveAuthorizerFactory.init()");
+ }
+
+ try {
+
+ rangerPluginClassLoader = RangerPluginClassLoader.getInstance(RANGER_PLUGIN_TYPE, this.getClass());
+
+ @SuppressWarnings("unchecked")
+ Class<HiveAuthorizerFactory> cls = (Class<HiveAuthorizerFactory>) Class.forName(RANGER_HIVE_AUTHORIZER_IMPL_CLASSNAME, true, rangerPluginClassLoader);
+
+ activatePluginClassLoader();
+
+ rangerHiveAuthorizerFactoryImpl = cls.newInstance();
+
+ } catch (Exception e) {
+ // check what need to be done
+ LOG.error("Error Enabling RangerHivePluing", e);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHiveAuthorizerFactory.init()");
+ }
+ }
+
+ @Override
+ public HiveAuthorizer createHiveAuthorizer(HiveMetastoreClientFactory metastoreClientFactory,
+ HiveConf conf,
+ HiveAuthenticationProvider hiveAuthenticator,
+ HiveAuthzSessionContext sessionContext)
+ throws HiveAuthzPluginException {
+
+ HiveAuthorizer ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerHiveAuthorizerFactory.createHiveAuthorizer()");
+ }
+
+ try {
+ activatePluginClassLoader();
+ ret = rangerHiveAuthorizerFactoryImpl.createHiveAuthorizer(metastoreClientFactory, conf, hiveAuthenticator, sessionContext);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerHiveAuthorizerFactory.createHiveAuthorizer()");
+ }
+
+ return ret;
+ }
+
+ private void activatePluginClassLoader() {
+ if(rangerPluginClassLoader != null) {
+ rangerPluginClassLoader.activate();
+ }
+ }
+
+ private void deactivatePluginClassLoader() {
+ if(rangerPluginClassLoader != null) {
+ rangerPluginClassLoader.deactivate();
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-kafka-plugin-shim/pom.xml
----------------------------------------------------------------------
diff --git a/ranger-kafka-plugin-shim/pom.xml b/ranger-kafka-plugin-shim/pom.xml
new file mode 100644
index 0000000..2d29868
--- /dev/null
+++ b/ranger-kafka-plugin-shim/pom.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
+ license agreements. See the NOTICE file distributed with this work for additional
+ information regarding copyright ownership. The ASF licenses this file to
+ You under the Apache License, Version 2.0 (the "License"); you may not use
+ this file except in compliance with the License. You may obtain a copy of
+ the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+ by applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ OF ANY KIND, either express or implied. See the License for the specific
+ language governing permissions and limitations under the License. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>security_plugins.ranger-kafka-plugin-shim</groupId>
+ <artifactId>ranger-kafka-plugin-shim</artifactId>
+ <name>KAFKA Security Plugin Shim</name>
+ <description>KAFKA Security Plugin shim</description>
+ <packaging>jar</packaging>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <parent>
+ <groupId>org.apache.ranger</groupId>
+ <artifactId>ranger</artifactId>
+ <version>0.5.0</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <dependencies>
+ <dependency>
+ <groupId>security_plugins.ranger-plugins-common</groupId>
+ <artifactId>ranger-plugins-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugins-audit</groupId>
+ <artifactId>ranger-plugins-audit</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugin-classloader</groupId>
+ <artifactId>ranger-plugin-classloader</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ranger</groupId>
+ <artifactId>credentialbuilder</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.kafka</groupId>
+ <artifactId>kafka_2.10</artifactId>
+ <version>${kafka.version}</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-kafka-plugin-shim/src/main/java/org/apache/ranger/authorization/kafka/authorizer/RangerKafkaAuthorizer.java
----------------------------------------------------------------------
diff --git a/ranger-kafka-plugin-shim/src/main/java/org/apache/ranger/authorization/kafka/authorizer/RangerKafkaAuthorizer.java b/ranger-kafka-plugin-shim/src/main/java/org/apache/ranger/authorization/kafka/authorizer/RangerKafkaAuthorizer.java
new file mode 100644
index 0000000..f7004e4
--- /dev/null
+++ b/ranger-kafka-plugin-shim/src/main/java/org/apache/ranger/authorization/kafka/authorizer/RangerKafkaAuthorizer.java
@@ -0,0 +1,248 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.authorization.kafka.authorizer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ranger.plugin.classloader.RangerPluginClassLoader;
+
+import scala.collection.immutable.Set;
+import kafka.network.RequestChannel.Session;
+import kafka.security.auth.Acl;
+import kafka.security.auth.Authorizer;
+import kafka.security.auth.KafkaPrincipal;
+import kafka.security.auth.Operation;
+import kafka.security.auth.Resource;
+import kafka.server.KafkaConfig;
+
+
+//public class RangerKafkaAuthorizer extends Authorizer {
+public class RangerKafkaAuthorizer implements Authorizer {
+ private static final Log LOG = LogFactory.getLog(RangerKafkaAuthorizer.class);
+
+ private static final String RANGER_PLUGIN_TYPE = "kafka";
+ private static final String[] RANGER_PLUGIN_LIB_DIR = new String[] {"lib/ranger-kafka-plugin"};
+ private static final String RANGER_KAFKA_AUTHORIZER_IMPL_CLASSNAME = "org.apache.ranger.authorization.kafka.authorizer.RangerKafkaAuthorizerImpl";
+
+ private Authorizer rangerKakfaAuthorizerImpl = null;
+ private static RangerPluginClassLoader rangerPluginClassLoader = null;
+
+ public RangerKafkaAuthorizer() {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerKafkaAuthorizer.RangerKafkaAuthorizer()");
+ }
+
+ this.init();
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerKafkaAuthorizer.RangerKafkaAuthorizer()");
+ }
+ }
+
+ public void init(){
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerKafkaAuthorizer.init()");
+ }
+
+ try {
+
+ rangerPluginClassLoader = RangerPluginClassLoader.getInstance(RANGER_PLUGIN_TYPE, this.getClass());
+
+ @SuppressWarnings("unchecked")
+ Class<Authorizer> cls = (Class<Authorizer>) Class.forName(RANGER_KAFKA_AUTHORIZER_IMPL_CLASSNAME, true, rangerPluginClassLoader);
+
+ activatePluginClassLoader();
+
+ rangerKakfaAuthorizerImpl = cls.newInstance();
+ } catch (Exception e) {
+ // check what need to be done
+ LOG.error("Error Enabling RangerKafkaPluing", e);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerKafkaAuthorizer.init()");
+ }
+ }
+
+
+ @Override
+ public void initialize(KafkaConfig kafkaConfig) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerKafkaAuthorizer.initialize()");
+ }
+
+ try {
+ activatePluginClassLoader();
+
+ rangerKakfaAuthorizerImpl.initialize(kafkaConfig);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerKafkaAuthorizer.initialize()");
+ }
+ }
+
+ @Override
+ public boolean authorize(Session session, Operation operation,Resource resource) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerKafkaAuthorizer.authorize()");
+ }
+
+ boolean ret = false;
+
+ try {
+ activatePluginClassLoader();
+
+ ret = rangerKakfaAuthorizerImpl.authorize(session, operation, resource);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerKafkaAuthorizer.authorize()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void addAcls(Set<Acl> acls, Resource resource) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerKafkaAuthorizer.addAcls()");
+ }
+
+ try {
+ activatePluginClassLoader();
+
+ rangerKakfaAuthorizerImpl.addAcls(acls, resource);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerKafkaAuthorizer.addAcls()");
+ }
+ }
+
+ @Override
+ public boolean removeAcls(Set<Acl> acls, Resource resource) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerKafkaAuthorizer.removeAcls()");
+ }
+ boolean ret = false;
+ try {
+ activatePluginClassLoader();
+
+ ret = rangerKakfaAuthorizerImpl.removeAcls(acls, resource);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerKafkaAuthorizer.removeAcls()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public boolean removeAcls(Resource resource) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerKafkaAuthorizer.removeAcls()");
+ }
+ boolean ret = false;
+ try {
+ activatePluginClassLoader();
+
+ ret = rangerKakfaAuthorizerImpl.removeAcls(resource);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerKafkaAuthorizer.removeAcls()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public Set<Acl> getAcls(Resource resource) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerKafkaAuthorizer.getAcls()");
+ }
+
+ Set<Acl> ret = null;
+
+ try {
+ activatePluginClassLoader();
+
+ ret = rangerKakfaAuthorizerImpl.getAcls(resource);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerKafkaAuthorizer.getAcls()");
+ }
+
+ return ret;
+ }
+
+ @Override
+ public Set<Acl> getAcls(KafkaPrincipal principal) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerKafkaAuthorizer.getAcls()");
+ }
+
+ Set<Acl> ret = null;
+
+ try {
+ activatePluginClassLoader();
+
+ ret = rangerKakfaAuthorizerImpl.getAcls(principal);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerKafkaAuthorizer.getAcls()");
+ }
+
+ return ret;
+ }
+
+ private void activatePluginClassLoader() {
+ if(rangerPluginClassLoader != null) {
+ rangerPluginClassLoader.activate();
+ }
+ }
+
+ private void deactivatePluginClassLoader() {
+ if(rangerPluginClassLoader != null) {
+ rangerPluginClassLoader.deactivate();
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-knox-plugin-shim/pom.xml
----------------------------------------------------------------------
diff --git a/ranger-knox-plugin-shim/pom.xml b/ranger-knox-plugin-shim/pom.xml
new file mode 100644
index 0000000..eef7913
--- /dev/null
+++ b/ranger-knox-plugin-shim/pom.xml
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>security_plugins.ranger-knox-plugin-shim</groupId>
+ <artifactId>ranger-knox-plugin-shim</artifactId>
+ <name>Knox Security Plugin Shim</name>
+ <description>Knox Security Plugins Shim</description>
+ <packaging>jar</packaging>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <parent>
+ <groupId>org.apache.ranger</groupId>
+ <artifactId>ranger</artifactId>
+ <version>0.5.0</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.knox</groupId>
+ <artifactId>gateway-spi</artifactId>
+ <version>0.5.0</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>${javax.servlet.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-integration</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-mapper-asl</artifactId>
+ <version>${codehaus.jackson.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-core-asl</artifactId>
+ <version>${codehaus.jackson.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugins-common</groupId>
+ <artifactId>ranger-plugins-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugin-classloader</groupId>
+ <artifactId>ranger-plugin-classloader</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugins-audit</groupId>
+ <artifactId>ranger-plugins-audit</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-knox-plugin-shim/src/main/java/com/xasecure/pdp/knox/filter/XASecurePDPKnoxFilter.java
----------------------------------------------------------------------
diff --git a/ranger-knox-plugin-shim/src/main/java/com/xasecure/pdp/knox/filter/XASecurePDPKnoxFilter.java b/ranger-knox-plugin-shim/src/main/java/com/xasecure/pdp/knox/filter/XASecurePDPKnoxFilter.java
new file mode 100644
index 0000000..6b9d6fd
--- /dev/null
+++ b/ranger-knox-plugin-shim/src/main/java/com/xasecure/pdp/knox/filter/XASecurePDPKnoxFilter.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.xasecure.pdp.knox.filter;
+
+import org.apache.ranger.authorization.knox.RangerPDPKnoxFilter;
+
+public class XASecurePDPKnoxFilter extends RangerPDPKnoxFilter {
+}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-knox-plugin-shim/src/main/java/org/apache/ranger/authorization/knox/RangerPDPKnoxFilter.java
----------------------------------------------------------------------
diff --git a/ranger-knox-plugin-shim/src/main/java/org/apache/ranger/authorization/knox/RangerPDPKnoxFilter.java b/ranger-knox-plugin-shim/src/main/java/org/apache/ranger/authorization/knox/RangerPDPKnoxFilter.java
new file mode 100644
index 0000000..caf3d6b
--- /dev/null
+++ b/ranger-knox-plugin-shim/src/main/java/org/apache/ranger/authorization/knox/RangerPDPKnoxFilter.java
@@ -0,0 +1,153 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ranger.authorization.knox;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ranger.plugin.classloader.RangerPluginClassLoader;
+
+public class RangerPDPKnoxFilter implements Filter {
+
+ private static final Log LOG = LogFactory.getLog(RangerPDPKnoxFilter.class);
+
+ private static final String RANGER_PLUGIN_TYPE = "knox";
+ private static final String[] RANGER_PLUGIN_LIB_DIR = new String[] {"lib/ranger-hdfs-plugin"};
+ private static final String RANGER_PDP_KNOX_FILTER_IMPL_CLASSNAME = "org.apache.ranger.authorization.knox.RangerPDPKnoxFilter";
+
+ private RangerPDPKnoxFilter rangerPDPKnoxFilteImpl = null;
+ private static RangerPluginClassLoader rangerPluginClassLoader = null;
+
+ public RangerPDPKnoxFilter() {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerPDPKnoxFilter.RangerPDPKnoxFilter()");
+ }
+
+ this.init0();
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPDPKnoxFilter.RangerPDPKnoxFilter()");
+ }
+ }
+
+ public void init0(){
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerPDPKnoxFilter.init()");
+ }
+
+ try {
+ rangerPluginClassLoader = RangerPluginClassLoader.getInstance(RANGER_PLUGIN_TYPE, this.getClass());
+
+ @SuppressWarnings("unchecked")
+ Class<Filter> cls = (Class<Filter>) Class.forName(RANGER_PDP_KNOX_FILTER_IMPL_CLASSNAME, true, rangerPluginClassLoader);
+
+ activatePluginClassLoader();
+
+ rangerPDPKnoxFilteImpl = (RangerPDPKnoxFilter) cls.newInstance();
+ } catch (Exception e) {
+ // check what need to be done
+ LOG.error("Error Enabling RangerKnoxPlugin", e);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPDPKnoxFilter.init()");
+ }
+ }
+
+ @Override
+ public void destroy() {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerPDPKnoxFilter.destroy()");
+ }
+
+ try {
+ activatePluginClassLoader();
+
+ rangerPDPKnoxFilteImpl.destroy();
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPDPKnoxFilter.destroy()");
+ }
+ }
+
+ @Override
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerPDPKnoxFilter.doFilter()");
+ }
+
+ try {
+ activatePluginClassLoader();
+
+ rangerPDPKnoxFilteImpl.doFilter(servletRequest, servletResponse, filterChain);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPDPKnoxFilter.doFilter()");
+ }
+ }
+
+ @Override
+ public void init(FilterConfig fiterConfig) throws ServletException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerPDPKnoxFilter.init()");
+ }
+
+ try {
+ activatePluginClassLoader();
+
+ rangerPDPKnoxFilteImpl.init(fiterConfig);
+ } finally {
+ deactivatePluginClassLoader();
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPDPKnoxFilter.init()");
+ }
+ }
+
+
+ private void activatePluginClassLoader() {
+ if(rangerPluginClassLoader != null) {
+ rangerPluginClassLoader.activate();
+ }
+ }
+
+ private void deactivatePluginClassLoader() {
+ if(rangerPluginClassLoader != null) {
+ rangerPluginClassLoader.deactivate();
+ }
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-plugin-classloader/pom.xml
----------------------------------------------------------------------
diff --git a/ranger-plugin-classloader/pom.xml b/ranger-plugin-classloader/pom.xml
new file mode 100644
index 0000000..a0ef4af
--- /dev/null
+++ b/ranger-plugin-classloader/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>security_plugins.ranger-plugin-classloader</groupId>
+ <artifactId>ranger-plugin-classloader</artifactId>
+ <version>0.5.0</version>
+ <name>ranger-plugin-classloader</name>
+ <description>Ranger Plugin ClassLoader</description>
+ <packaging>jar</packaging>
+ <url>http://maven.apache.org</url>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <parent>
+ <groupId>org.apache.ranger</groupId>
+ <artifactId>ranger</artifactId>
+ <version>0.5.0</version>
+ </parent>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <!--
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>${commons.logging.version}</version>
+ </dependency>
+ -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j-api.version}</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-plugin-classloader/src/main/java/org/apache/ranger/plugin/classloader/RangerPluginClassLoader.java
----------------------------------------------------------------------
diff --git a/ranger-plugin-classloader/src/main/java/org/apache/ranger/plugin/classloader/RangerPluginClassLoader.java b/ranger-plugin-classloader/src/main/java/org/apache/ranger/plugin/classloader/RangerPluginClassLoader.java
new file mode 100644
index 0000000..a099743
--- /dev/null
+++ b/ranger-plugin-classloader/src/main/java/org/apache/ranger/plugin/classloader/RangerPluginClassLoader.java
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.plugin.classloader;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Enumeration;
+
+//import org.apache.commons.logging.Log;
+//import org.apache.commons.logging.LogFactory;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RangerPluginClassLoader extends URLClassLoader {
+ private static Logger LOG = LoggerFactory.getLogger(RangerPluginClassLoader.class);
+
+ private static volatile RangerPluginClassLoader me = null;
+ private static MyClassLoader componentClassLoader = null;
+ //private static ThreadLocal<MyClassLoader> componentClassLoader = new ThreadLocal<MyClassLoader>();
+
+ public RangerPluginClassLoader(String pluginType, Class<?> pluginClass ) throws Exception {
+ super(RangerPluginClassLoaderUtil.getInstance().getPluginFilesForServiceTypeAndPluginclass(pluginType, pluginClass), null);
+ //componentClassLoader.set(new MyClassLoader(Thread.currentThread().getContextClassLoader()));
+ componentClassLoader = new MyClassLoader(Thread.currentThread().getContextClassLoader());
+ }
+
+ public static RangerPluginClassLoader getInstance(String pluginType, Class<?> pluginClass ) throws Exception {
+ RangerPluginClassLoader ret = me;
+ if ( ret == null) {
+ synchronized(RangerPluginClassLoader.class) {
+ ret = me;
+ if ( ret == null){
+ me = ret = new RangerPluginClassLoader(pluginType,pluginClass);
+ }
+ }
+ }
+ return ret;
+ }
+
+ @Override
+ public Class<?> findClass(String name) throws ClassNotFoundException {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerPluginClassLoader.findClass(" + name + ")");
+ }
+
+ Class<?> ret = null;
+
+ try {
+ // first we try to find a class inside the child classloader
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("RangerPluginClassLoader.findClass(" + name + "): calling childClassLoader().findClass() ");
+ }
+
+ ret = super.findClass(name);
+ } catch( Throwable e ) {
+ // Use the Component ClassLoader findclass to load when childClassLoader fails to find
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("RangerPluginClassLoader.findClass(" + name + "): calling componentClassLoader.findClass()");
+ }
+
+ MyClassLoader savedClassLoader = getComponentClassLoader();
+ if (savedClassLoader != null) {
+ ret = savedClassLoader.findClass(name);
+ }
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPluginClassLoader.findClass(" + name + "): " + ret);
+ }
+ return ret;
+ }
+
+ @Override
+ public synchronized Class<?> loadClass(String name) throws ClassNotFoundException {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerPluginClassLoader.loadClass(" + name + ")" );
+ }
+
+ Class<?> ret = null;
+
+ try {
+ // first we try to load a class inside the child classloader
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("RangerPluginClassLoader.loadClass(" + name + "): calling childClassLoader.findClass()");
+ }
+ ret = super.loadClass(name);
+ } catch(Throwable e) {
+ // Use the Component ClassLoader loadClass to load when childClassLoader fails to find
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("RangerPluginClassLoader.loadClass(" + name + "): calling componentClassLoader.loadClass()");
+ }
+
+ MyClassLoader savedClassLoader = getComponentClassLoader();
+
+ if(savedClassLoader != null) {
+ ret = savedClassLoader.loadClass(name);
+ }
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPluginClassLoader.loadClass" + name + "): " + ret);
+ }
+
+ return ret;
+ }
+
+ @Override
+ public URL findResource(String name) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerPluginClassLoader.findResource(" + name + ") ");
+ }
+
+ URL ret = super.findResource(name);
+
+ if (ret == null) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("RangerPluginClassLoader.findResource(" + name + "): calling componentClassLoader.getResources()");
+ }
+
+ MyClassLoader savedClassLoader = getComponentClassLoader();
+ if (savedClassLoader != null) {
+ ret = savedClassLoader.getResource(name);
+ }
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPluginClassLoader.findResource(" + name + "): " + ret);
+ }
+
+ return ret;
+ }
+
+ @Override
+ public Enumeration<URL> findResources(String name) throws IOException {
+ Enumeration<URL> ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerPluginClassLoader.findResources(" + name + ") ");
+ }
+
+ ret = new MergeEnumeration(findResourcesUsingChildClassLoader(name),findResourcesUsingComponentClassLoader(name));
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPluginClassLoader.findResources(" + name + ") ");
+ }
+
+ return ret;
+ }
+
+ public Enumeration<URL> findResourcesUsingChildClassLoader(String name) {
+
+ Enumeration<URL> ret = null;
+
+ try {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("RangerPluginClassLoader.findResourcesUsingChildClassLoader(" + name + "): calling childClassLoader.findResources()");
+ }
+
+ ret = super.findResources(name);
+
+ } catch ( Throwable t) {
+ //Ignore any exceptions. Null / Empty return is handle in following statements
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("RangerPluginClassLoader.findResourcesUsingChildClassLoader(" + name + "): class not found in child. Falling back to componentClassLoader", t);
+ }
+ }
+ return ret;
+ }
+
+ public Enumeration<URL> findResourcesUsingComponentClassLoader(String name) {
+
+ Enumeration<URL> ret = null;
+
+ try {
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("RangerPluginClassLoader.findResourcesUsingComponentClassLoader(" + name + "): calling componentClassLoader.getResources()");
+ }
+
+ MyClassLoader savedClassLoader = getComponentClassLoader();
+
+ if (savedClassLoader != null) {
+ ret = savedClassLoader.getResources(name);
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPluginClassLoader.findResourcesUsingComponentClassLoader(" + name + "): " + ret);
+ }
+ } catch( Throwable t) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("RangerPluginClassLoader.findResourcesUsingComponentClassLoader(" + name + "): class not found in componentClassLoader.", t);
+ }
+ }
+
+ return ret;
+ }
+
+ public void activate() {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerPluginClassLoader.activate()");
+ }
+
+ //componentClassLoader.set(new MyClassLoader(Thread.currentThread().getContextClassLoader()));
+
+ Thread.currentThread().setContextClassLoader(this);
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPluginClassLoader.activate()");
+ }
+ }
+
+ public void deactivate() {
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerPluginClassLoader.deactivate()");
+ }
+
+ MyClassLoader savedClassLoader = getComponentClassLoader();
+
+ if(savedClassLoader != null && savedClassLoader.getParent() != null) {
+ Thread.currentThread().setContextClassLoader(savedClassLoader.getParent());
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPluginClassLoader.deactivate()");
+ }
+ }
+
+ private MyClassLoader getComponentClassLoader() {
+ return componentClassLoader;
+ //return componentClassLoader.get();
+ }
+
+ static class MyClassLoader extends ClassLoader {
+ public MyClassLoader(ClassLoader realClassLoader) {
+ super(realClassLoader);
+ }
+
+ @Override
+ public Class<?> findClass(String name) throws ClassNotFoundException {
+ return super.findClass(name);
+ }
+ }
+
+ class MergeEnumeration implements Enumeration<URL> {
+
+ Enumeration<URL> e1 = null;
+ Enumeration<URL> e2 = null;
+
+ public MergeEnumeration(Enumeration<URL> e1, Enumeration<URL> e2 ) {
+ this.e1 = e1;
+ this.e2 = e2;
+ }
+
+ @Override
+ public boolean hasMoreElements() {
+ return ( (e1 != null && e1.hasMoreElements() ) || ( e2 != null && e2.hasMoreElements()) );
+ }
+
+ @Override
+ public URL nextElement() {
+ URL ret = null;
+ if (e1 != null && e1.hasMoreElements())
+ ret = e1.nextElement();
+ else if ( e2 != null && e2.hasMoreElements() ) {
+ ret = e2.nextElement();
+ }
+ return ret;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-plugin-classloader/src/main/java/org/apache/ranger/plugin/classloader/RangerPluginClassLoaderUtil.java
----------------------------------------------------------------------
diff --git a/ranger-plugin-classloader/src/main/java/org/apache/ranger/plugin/classloader/RangerPluginClassLoaderUtil.java b/ranger-plugin-classloader/src/main/java/org/apache/ranger/plugin/classloader/RangerPluginClassLoaderUtil.java
new file mode 100644
index 0000000..178c83e
--- /dev/null
+++ b/ranger-plugin-classloader/src/main/java/org/apache/ranger/plugin/classloader/RangerPluginClassLoaderUtil.java
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.plugin.classloader;
+
+
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+
+//import org.apache.commons.logging.Log;
+//import org.apache.commons.logging.LogFactory;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RangerPluginClassLoaderUtil {
+
+ private static final Logger LOG = LoggerFactory.getLogger(RangerPluginClassLoaderUtil.class) ;
+
+ private static RangerPluginClassLoaderUtil config = null;
+ private static String rangerPluginLibDir = "ranger-%-plugin-impl";
+
+ public static RangerPluginClassLoaderUtil getInstance() {
+ RangerPluginClassLoaderUtil result = config;
+ if (result == null) {
+ synchronized (RangerPluginClassLoaderUtil.class) {
+ result = config;
+ if (result == null) {
+ config = result = new RangerPluginClassLoaderUtil();
+ }
+ }
+ }
+ return result;
+ }
+
+ public URL[] getPluginFilesForServiceType(String serviceType, String libDir) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerPluginClassLoaderUtil.getPluginFilesForServiceType(" + serviceType + ")");
+ }
+
+ List<URL> ret = new ArrayList<URL>();
+
+ getFilesInDirectory(libDir,ret);
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPluginClassLoaderUtil.getPluginFilesForServiceType(" + serviceType + "): " + ret.size() + " files");
+ }
+
+ return ret.toArray(new URL[] { });
+ }
+
+ public URL[] getPluginFilesForServiceTypeAndPluginclass( String serviceType, Class<?> pluginClass) throws Exception {
+
+ URL[] ret = null;
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerPluginClassLoaderUtil.getPluginFilesForServiceTypeAndPluginclass(" + serviceType + ")" + " Pluging Class :" + pluginClass.getName());
+ }
+
+ String[] libDirs = new String[] { getPluginImplJarPath(serviceType, pluginClass) };
+
+ ret = getPluginFilesForServiceType(serviceType, libDirs);
+
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPluginClassLoaderUtil.getPluginFilesForServiceTypeAndPluginclass(" + serviceType + ")" + " Pluging Class :" + pluginClass.getName());
+ }
+
+ return ret;
+
+ }
+
+ public URL[] getPluginFilesForServiceType(String serviceType, String[] libDirs) throws Exception {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerPluginClassLoaderUtil.getPluginFilesForServiceType(" + serviceType + ")");
+ }
+
+ List<URL> ret = new ArrayList<URL>();
+ for ( String libDir : libDirs) {
+ getFilesInDirectory(libDir,ret);
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPluginClassLoaderUtil.getPluginFilesForServiceType(" + serviceType + "): " + ret.size() + " files");
+ }
+
+ return ret.toArray(new URL[] { });
+ }
+
+ public void getFilesInDirectory(String dirPath, List<URL> files) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerPluginClassLoaderUtil.getFilesInDirectory(" + dirPath + ")");
+ }
+
+ if ( dirPath != null) {
+ try {
+
+ File[] dirFiles = new File(dirPath).listFiles();
+
+ if(dirFiles != null) {
+ for(File dirFile : dirFiles) {
+ try {
+ URL jarPath = dirFile.toURI().toURL();
+
+ LOG.warn("getFilesInDirectory('" + dirPath + "'): adding " + dirFile.getAbsolutePath());
+
+ files.add(jarPath);
+ } catch(Exception excp) {
+ LOG.warn("getFilesInDirectory('" + dirPath + "'): failed to get URI for file " + dirFile.getAbsolutePath(), excp);
+ }
+ }
+ }
+ } catch(Exception excp) {
+ LOG.warn("getFilesInDirectory('" + dirPath + "'): error", excp);
+ }
+ } else {
+ LOG.warn("getFilesInDirectory('" + dirPath + "'): could not find directory in CLASSPATH");
+ }
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPluginClassLoaderUtil.getFilesInDirectory(" + dirPath + ")");
+ }
+ }
+
+ private String getPluginImplJarPath(String serviceType, Class<?> pluginClass) throws Exception {
+
+ String ret = null;
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerPluginClassLoaderUtil.getPluginImplJarPath for Class (" + pluginClass.getName() + ")");
+ }
+
+ URI uri = pluginClass.getProtectionDomain().getCodeSource().getLocation().toURI();
+
+ Path path = Paths.get(URI.create(uri.toString()));
+
+ ret = path.getParent().toString() +"/"+ rangerPluginLibDir.replaceAll("%", serviceType);
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPluginClassLoaderUtil.getPluginImplJarPath for Class (" + pluginClass.getName() + " PATH :" + ret + ")");
+ }
+
+ return ret;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-plugin-classloader/src/main/java/org/apache/ranger/plugin/classloader/RangerPluginProxyGenerator.java
----------------------------------------------------------------------
diff --git a/ranger-plugin-classloader/src/main/java/org/apache/ranger/plugin/classloader/RangerPluginProxyGenerator.java b/ranger-plugin-classloader/src/main/java/org/apache/ranger/plugin/classloader/RangerPluginProxyGenerator.java
new file mode 100644
index 0000000..d042efa
--- /dev/null
+++ b/ranger-plugin-classloader/src/main/java/org/apache/ranger/plugin/classloader/RangerPluginProxyGenerator.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.plugin.classloader;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+//import org.apache.commons.logging.Log;
+//import org.apache.commons.logging.LogFactory;
+
+public class RangerPluginProxyGenerator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(RangerPluginProxyGenerator.class) ;
+
+ private static RangerPluginProxyGenerator ret = null;
+
+ public static RangerPluginProxyGenerator getInstance() {
+ RangerPluginProxyGenerator result = ret ;
+ if (result == null) {
+ synchronized (RangerPluginProxyGenerator.class) {
+ result = ret;
+ if (result == null) {
+ ret = result = new RangerPluginProxyGenerator();
+ }
+ }
+ }
+ return ret;
+ }
+
+
+ public static Class<?> getPluginProxyClass(ClassLoader classLoader, Class<?>... interfaces ) throws Throwable {
+
+ Class<?> ret = null;
+
+ ret = Proxy.getProxyClass(classLoader, interfaces);
+
+ return ret;
+
+ }
+
+ public static Object getPluginProxyInstance(ClassLoader classLoader, Class<?>[] impl ) throws Throwable {
+
+ Object ret = null;
+
+ InvocationHandler rangerInvocationHandler = RangerPluginProxyGenerator.getInstance().new RangerPluginMethodInvocationHandler(impl);
+
+ ret = Proxy.newProxyInstance(classLoader, impl, rangerInvocationHandler);
+
+ return ret;
+ }
+
+ class RangerPluginMethodInvocationHandler implements InvocationHandler {
+ private final Object impl;
+
+ public RangerPluginMethodInvocationHandler(Object impl) {
+ this.impl = impl;
+ }
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ Object ret = null;
+
+ ret = method.invoke(impl, args);
+
+ return ret;
+ }
+
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/Impl/TestChildFistClassLoader.java
----------------------------------------------------------------------
diff --git a/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/Impl/TestChildFistClassLoader.java b/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/Impl/TestChildFistClassLoader.java
new file mode 100644
index 0000000..de45520
--- /dev/null
+++ b/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/Impl/TestChildFistClassLoader.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.plugin.classloader.test.Impl;
+
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import org.apache.ranger.plugin.classloader.RangerPluginClassLoader;
+import org.apache.ranger.plugin.classloader.test.TestPlugin;
+import org.apache.ranger.plugin.classloader.test.TestPrintParent;
+
+public class TestChildFistClassLoader {
+
+ public static void main(String [] args){
+ TestPrintParent testPrint = new TestPrintParent();
+ System.out.println(testPrint.getString());
+ File file = null;
+ URL[] urls = null;
+ try {
+ file = new File(".." + File.separatorChar + "TestPluginImpl.class");
+ URL url = file.toPath().toUri().toURL();
+ urls = new URL[] {url};
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ String[] libdirs = new String[] { file.getAbsolutePath() };
+
+ try {
+ @SuppressWarnings("resource")
+ RangerPluginClassLoader rangerPluginClassLoader = new RangerPluginClassLoader("hdfs", TestChildFistClassLoader.class);
+ TestPlugin testPlugin = (TestPlugin) rangerPluginClassLoader.loadClass("org.apache.ranger.plugin.classloader.test.Impl.TestPluginImpl").newInstance();
+ System.out.println(testPlugin.print());
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/Impl/TestPluginImpl.java
----------------------------------------------------------------------
diff --git a/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/Impl/TestPluginImpl.java b/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/Impl/TestPluginImpl.java
new file mode 100644
index 0000000..cbb3c67
--- /dev/null
+++ b/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/Impl/TestPluginImpl.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.plugin.classloader.test.Impl;
+
+import org.apache.ranger.plugin.classloader.test.TestPlugin;
+
+public class TestPluginImpl implements TestPlugin {
+
+ @Override
+ public String print() {
+ String ret = new TestPrint().getString();
+ return ret;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/Impl/TestPrint.java
----------------------------------------------------------------------
diff --git a/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/Impl/TestPrint.java b/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/Impl/TestPrint.java
new file mode 100644
index 0000000..8626ec4
--- /dev/null
+++ b/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/Impl/TestPrint.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.plugin.classloader.test.Impl;
+
+public class TestPrint {
+
+ public String getString(){
+ String ret = "Class Loaded by RangerPlugingClassLoader";
+ return ret;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/TestPlugin.java
----------------------------------------------------------------------
diff --git a/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/TestPlugin.java b/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/TestPlugin.java
new file mode 100644
index 0000000..145d7a5
--- /dev/null
+++ b/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/TestPlugin.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.plugin.classloader.test;
+
+public interface TestPlugin {
+ public String print();
+}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/TestPrintParent.java
----------------------------------------------------------------------
diff --git a/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/TestPrintParent.java b/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/TestPrintParent.java
new file mode 100644
index 0000000..9524dfa
--- /dev/null
+++ b/ranger-plugin-classloader/src/test/java/org/apache/ranger/plugin/classloader/test/TestPrintParent.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.plugin.classloader.test;
+
+public class TestPrintParent {
+
+ public String getString(){
+ String ret = "Loaded by Component ClassLoader";
+ return ret;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-storm-plugin-shim/pom.xml
----------------------------------------------------------------------
diff --git a/ranger-storm-plugin-shim/pom.xml b/ranger-storm-plugin-shim/pom.xml
new file mode 100644
index 0000000..9fa0ce8
--- /dev/null
+++ b/ranger-storm-plugin-shim/pom.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>security_plugins.ranger-storm-plugin-shim</groupId>
+ <artifactId>ranger-storm-plugin-shim</artifactId>
+ <name>Storm Security Plugin shim</name>
+ <description>Storm Security Plugins shim</description>
+ <packaging>jar</packaging>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <parent>
+ <groupId>org.apache.ranger</groupId>
+ <artifactId>ranger</artifactId>
+ <version>0.5.0</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.storm</groupId>
+ <artifactId>storm-core</artifactId>
+ <version>${storm.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugins-common</groupId>
+ <artifactId>ranger-plugins-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugins-audit</groupId>
+ <artifactId>ranger-plugins-audit</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ranger</groupId>
+ <artifactId>credentialbuilder</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-hdfs</artifactId>
+ <version>${hadoop.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ <version>${commons.cli.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.htrace</groupId>
+ <artifactId>htrace-core</artifactId>
+ <version>${htrace-core.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugins-common</groupId>
+ <artifactId>ranger-plugins-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>security_plugins.ranger-plugin-classloader</groupId>
+ <artifactId>ranger-plugin-classloader</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebe83454/ranger-storm-plugin-shim/src/main/java/com/xasecure/authorization/storm/authorizer/XaSecureStormAuthorizer.java
----------------------------------------------------------------------
diff --git a/ranger-storm-plugin-shim/src/main/java/com/xasecure/authorization/storm/authorizer/XaSecureStormAuthorizer.java b/ranger-storm-plugin-shim/src/main/java/com/xasecure/authorization/storm/authorizer/XaSecureStormAuthorizer.java
new file mode 100644
index 0000000..723dd79
--- /dev/null
+++ b/ranger-storm-plugin-shim/src/main/java/com/xasecure/authorization/storm/authorizer/XaSecureStormAuthorizer.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.xasecure.authorization.storm.authorizer;
+
+import org.apache.ranger.authorization.storm.authorizer.RangerStormAuthorizer;
+
+/**
+ * This class exists only to provide for seamless upgrade/downgrade capabilities. Class name is in storm conf which must allow for seamles upgrade and downgrade.
+ * Thus when class names were changed XaSecure* -> Ranger* this shell class serves to allow for seamles upgrade as well as downgrade.
+ *
+ * This class is final because if one needs to customize coprocessor it is expected that RangerStormAuthorizer would be modified/extended as that is
+ * the "real" authorizer! This class, hence, should NEVER be more than an EMPTY shell!
+ */
+final public class XaSecureStormAuthorizer extends RangerStormAuthorizer {
+}