You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by br...@apache.org on 2013/10/17 17:03:40 UTC
git commit: SENTRY-36 - Create sentry-binding-solr module (Gregory
Chanan via Brock Noland)
Updated Branches:
refs/heads/master 1824f7808 -> 44f44e1b1
SENTRY-36 - Create sentry-binding-solr module (Gregory Chanan via Brock Noland)
Project: http://git-wip-us.apache.org/repos/asf/incubator-sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-sentry/commit/44f44e1b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/44f44e1b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/44f44e1b
Branch: refs/heads/master
Commit: 44f44e1b1131ae11ca93587b77f8c7851b02899a
Parents: 1824f78
Author: Brock Noland <br...@apache.org>
Authored: Thu Oct 17 10:03:29 2013 -0500
Committer: Brock Noland <br...@apache.org>
Committed: Thu Oct 17 10:03:29 2013 -0500
----------------------------------------------------------------------
pom.xml | 6 +
sentry-binding/pom.xml | 1 +
sentry-binding/sentry-binding-solr/pom.xml | 65 +++++
.../authz/SentrySolrAuthorizationException.java | 23 ++
.../binding/solr/authz/SolrAuthzBinding.java | 103 +++++++
.../sentry/binding/solr/conf/SolrAuthzConf.java | 82 ++++++
.../binding/solr/TestSolrAuthzBinding.java | 265 +++++++++++++++++++
.../src/test/resources/log4j.properties | 31 +++
.../src/test/resources/sentry-site.xml | 29 ++
.../src/test/resources/test-authz-provider.ini | 33 +++
sentry-dist/pom.xml | 4 +
sentry-dist/src/main/assembly/src.xml | 1 +
.../file/ResourceAuthorizationProvider.java | 2 +-
13 files changed, 644 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/44f44e1b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index a713c41..cc41c76 100644
--- a/pom.xml
+++ b/pom.xml
@@ -246,6 +246,12 @@ limitations under the License.
</dependency>
<dependency>
<groupId>org.apache.sentry</groupId>
+ <artifactId>sentry-binding-solr</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sentry</groupId>
<artifactId>sentry-provider-common</artifactId>
<version>${project.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/44f44e1b/sentry-binding/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-binding/pom.xml b/sentry-binding/pom.xml
index af2efa4..f8172bf 100644
--- a/sentry-binding/pom.xml
+++ b/sentry-binding/pom.xml
@@ -31,6 +31,7 @@ limitations under the License.
<modules>
<module>sentry-binding-hive</module>
+ <module>sentry-binding-solr</module>
</modules>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/44f44e1b/sentry-binding/sentry-binding-solr/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-solr/pom.xml b/sentry-binding/sentry-binding-solr/pom.xml
new file mode 100644
index 0000000..554ee8a
--- /dev/null
+++ b/sentry-binding/sentry-binding-solr/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.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.
+-->
+<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>
+
+ <parent>
+ <groupId>org.apache.sentry</groupId>
+ <artifactId>sentry-binding</artifactId>
+ <version>1.3.0-incubating-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>sentry-binding-solr</artifactId>
+ <name>Sentry Binding for Solr</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sentry</groupId>
+ <artifactId>sentry-core-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sentry</groupId>
+ <artifactId>sentry-core-model-search</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sentry</groupId>
+ <artifactId>sentry-provider-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sentry</groupId>
+ <artifactId>sentry-provider-file</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sentry</groupId>
+ <artifactId>sentry-provider-policy-search</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-common</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/44f44e1b/sentry-binding/sentry-binding-solr/src/main/java/org/apache/sentry/binding/solr/authz/SentrySolrAuthorizationException.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-solr/src/main/java/org/apache/sentry/binding/solr/authz/SentrySolrAuthorizationException.java b/sentry-binding/sentry-binding-solr/src/main/java/org/apache/sentry/binding/solr/authz/SentrySolrAuthorizationException.java
new file mode 100644
index 0000000..134eaeb
--- /dev/null
+++ b/sentry-binding/sentry-binding-solr/src/main/java/org/apache/sentry/binding/solr/authz/SentrySolrAuthorizationException.java
@@ -0,0 +1,23 @@
+/*
+ * 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.sentry.binding.solr.authz;
+
+public class SentrySolrAuthorizationException extends Exception {
+ public SentrySolrAuthorizationException(String message) {
+ super(message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/44f44e1b/sentry-binding/sentry-binding-solr/src/main/java/org/apache/sentry/binding/solr/authz/SolrAuthzBinding.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-solr/src/main/java/org/apache/sentry/binding/solr/authz/SolrAuthzBinding.java b/sentry-binding/sentry-binding-solr/src/main/java/org/apache/sentry/binding/solr/authz/SolrAuthzBinding.java
new file mode 100644
index 0000000..506176c
--- /dev/null
+++ b/sentry-binding/sentry-binding-solr/src/main/java/org/apache/sentry/binding/solr/authz/SolrAuthzBinding.java
@@ -0,0 +1,103 @@
+/*
+ * 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.sentry.binding.solr.authz;
+
+import java.lang.reflect.Constructor;
+import java.util.Arrays;
+import java.util.Set;
+
+import org.apache.sentry.core.common.AuthorizationProvider;
+import org.apache.sentry.core.common.Subject;
+import org.apache.sentry.core.model.search.Collection;
+import org.apache.sentry.core.model.search.SearchModelAction;
+import org.apache.sentry.binding.solr.conf.SolrAuthzConf;
+import org.apache.sentry.binding.solr.conf.SolrAuthzConf.AuthzConfVars;
+import org.apache.sentry.provider.common.PolicyEngine;
+import org.apache.sentry.provider.common.ProviderBackend;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SolrAuthzBinding {
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SolrAuthzBinding.class);
+
+ private final SolrAuthzConf authzConf;
+ private final AuthorizationProvider authProvider;
+
+ public SolrAuthzBinding (SolrAuthzConf authzConf) throws Exception {
+ this.authzConf = authzConf;
+ this.authProvider = getAuthProvider();
+ }
+
+ // Instantiate the configured authz provider
+ private AuthorizationProvider getAuthProvider() throws Exception {
+ // get the provider class and resources from the authz config
+ String authProviderName = authzConf.get(AuthzConfVars.AUTHZ_PROVIDER.getVar());
+ String resourceName =
+ authzConf.get(AuthzConfVars.AUTHZ_PROVIDER_RESOURCE.getVar());
+ String providerBackendName =
+ authzConf.get(AuthzConfVars.AUTHZ_PROVIDER_BACKEND.getVar());
+ String policyEngineName =
+ authzConf.get(AuthzConfVars.AUTHZ_POLICY_ENGINE.getVar());
+
+ LOG.debug("Using authorization provider " + authProviderName +
+ " with resource " + resourceName + ", policy engine "
+ + policyEngineName + ", provider backend " + providerBackendName);
+ // load the provider backend class
+ Constructor<?> providerBackendConstructor =
+ Class.forName(providerBackendName).getDeclaredConstructor(String.class);
+ providerBackendConstructor.setAccessible(true);
+ ProviderBackend providerBackend =
+ (ProviderBackend) providerBackendConstructor.newInstance(new Object[] {resourceName});
+
+ // load the policy engine class
+ Constructor<?> policyConstructor =
+ Class.forName(policyEngineName).getDeclaredConstructor(ProviderBackend.class);
+ policyConstructor.setAccessible(true);
+ PolicyEngine policyEngine =
+ (PolicyEngine) policyConstructor.newInstance(new Object[] {providerBackend});
+
+ // load the authz provider class
+ Constructor<?> constrctor =
+ Class.forName(authProviderName).getDeclaredConstructor(String.class, PolicyEngine.class);
+ constrctor.setAccessible(true);
+ return (AuthorizationProvider) constrctor.newInstance(new Object[] {resourceName, policyEngine});
+ }
+
+
+ /**
+ * Authorize access to an index/collection
+ * @param subject
+ * @param collection
+ * @param actions
+ * @throws SentrySolrAuthorizationException
+ */
+ public void authorizeCollection(Subject subject, Collection collection, Set<SearchModelAction> actions) throws SentrySolrAuthorizationException {
+ boolean isDebug = LOG.isDebugEnabled();
+ if(isDebug) {
+ LOG.debug("Going to authorize collection " + collection.getName() +
+ " for subject " + subject.getName());
+ LOG.debug("Actions: " + actions);
+ }
+
+ if (!authProvider.hasAccess(subject, Arrays.asList(new Collection[] {collection}), actions)) {
+ throw new SentrySolrAuthorizationException("User " + subject.getName() +
+ " does not have privileges for " + collection.getName());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/44f44e1b/sentry-binding/sentry-binding-solr/src/main/java/org/apache/sentry/binding/solr/conf/SolrAuthzConf.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-solr/src/main/java/org/apache/sentry/binding/solr/conf/SolrAuthzConf.java b/sentry-binding/sentry-binding-solr/src/main/java/org/apache/sentry/binding/solr/conf/SolrAuthzConf.java
new file mode 100644
index 0000000..c40c379
--- /dev/null
+++ b/sentry-binding/sentry-binding-solr/src/main/java/org/apache/sentry/binding/solr/conf/SolrAuthzConf.java
@@ -0,0 +1,82 @@
+/*
+ * 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.sentry.binding.solr.conf;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.hadoop.conf.Configuration;
+import org.mortbay.log.Log;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class SolrAuthzConf extends Configuration {
+
+ /**
+ * Config setting definitions
+ */
+ public static enum AuthzConfVars {
+ AUTHZ_PROVIDER("sentry.provider",
+ "org.apache.sentry.provider.file.ResourceAuthorizationProvider"),
+ AUTHZ_PROVIDER_RESOURCE("sentry.solr.provider.resource", ""),
+ AUTHZ_PROVIDER_BACKEND("sentry.solr.provider.backend", "org.apache.sentry.provider.file.SimpleFileProviderBackend"),
+ AUTHZ_POLICY_ENGINE("sentry.solr.policy.engine", "org.apache.sentry.provider.search.SimpleSearchPolicyEngine");
+
+ private final String varName;
+ private final String defaultVal;
+
+ AuthzConfVars(String varName, String defaultVal) {
+ this.varName = varName;
+ this.defaultVal = defaultVal;
+ }
+
+ public String getVar() {
+ return varName;
+ }
+
+ public String getDefault() {
+ return defaultVal;
+ }
+
+ public static String getDefault(String varName) {
+ for (AuthzConfVars oneVar : AuthzConfVars.values()) {
+ if(oneVar.getVar().equalsIgnoreCase(varName)) {
+ return oneVar.getDefault();
+ }
+ }
+ return null;
+ }
+ }
+
+ @SuppressWarnings("unused")
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SolrAuthzConf.class);
+ public static final String AUTHZ_SITE_FILE = "sentry-site.xml";
+
+ public SolrAuthzConf(URL solrAuthzSiteURL) {
+ super(false);
+ addResource(solrAuthzSiteURL);
+ }
+
+ @Override
+ public String get(String varName) {
+ return get(varName, AuthzConfVars.getDefault(varName));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/44f44e1b/sentry-binding/sentry-binding-solr/src/test/java/org/apache/sentry/binding/solr/TestSolrAuthzBinding.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-solr/src/test/java/org/apache/sentry/binding/solr/TestSolrAuthzBinding.java b/sentry-binding/sentry-binding-solr/src/test/java/org/apache/sentry/binding/solr/TestSolrAuthzBinding.java
new file mode 100644
index 0000000..0dc3da1
--- /dev/null
+++ b/sentry-binding/sentry-binding-solr/src/test/java/org/apache/sentry/binding/solr/TestSolrAuthzBinding.java
@@ -0,0 +1,265 @@
+/*
+ * 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.sentry.binding.solr;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
+import java.lang.reflect.InvocationTargetException;
+
+import junit.framework.Assert;
+import static junit.framework.Assert.assertTrue;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.sentry.core.common.Subject;
+import org.apache.sentry.core.model.search.Collection;
+import org.apache.sentry.core.model.search.SearchModelAction;
+import org.apache.sentry.provider.file.PolicyFiles;
+import org.apache.sentry.binding.solr.authz.SolrAuthzBinding;
+import org.apache.sentry.binding.solr.conf.SolrAuthzConf;
+import org.apache.sentry.binding.solr.conf.SolrAuthzConf.AuthzConfVars;
+import org.apache.sentry.binding.solr.authz.SentrySolrAuthorizationException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.io.Files;
+import com.google.common.io.Resources;
+
+/**
+ * Test for solr authz binding
+ */
+public class TestSolrAuthzBinding {
+ private static final String RESOURCE_PATH = "test-authz-provider.ini";
+ private SolrAuthzConf authzConf = new SolrAuthzConf(Resources.getResource("sentry-site.xml"));
+ private File baseDir;
+
+ private Collection infoCollection = new Collection("info");
+ private Collection generalInfoCollection = new Collection("generalInfo");
+
+ private Subject corporal1 = new Subject("corporal1");
+ private Subject sergeant1 = new Subject("sergeant1");
+ private Subject general1 = new Subject("general1");
+
+ private EnumSet querySet = EnumSet.of(SearchModelAction.QUERY);
+ private EnumSet updateSet = EnumSet.of(SearchModelAction.UPDATE);
+ private EnumSet allSet = EnumSet.of(SearchModelAction.ALL);
+ private EnumSet allOfSet = EnumSet.allOf(SearchModelAction.class);
+ private EnumSet emptySet = EnumSet.noneOf(SearchModelAction.class);
+
+ @Before
+ public void setUp() throws Exception {
+ baseDir = Files.createTempDir();
+ PolicyFiles.copyToDir(baseDir, RESOURCE_PATH);
+ authzConf.set(AuthzConfVars.AUTHZ_PROVIDER_RESOURCE.getVar(), new File(baseDir, RESOURCE_PATH).getPath());
+ }
+
+ @After
+ public void teardown() {
+ if(baseDir != null) {
+ FileUtils.deleteQuietly(baseDir);
+ }
+ }
+
+ private void setUsableAuthzConf(SolrAuthzConf conf) {
+ conf.set(AuthzConfVars.AUTHZ_PROVIDER.getVar(), "org.apache.sentry.provider.file.LocalGroupResourceAuthorizationProvider");
+ conf.set(AuthzConfVars.AUTHZ_PROVIDER_RESOURCE.getVar(), new File(baseDir, RESOURCE_PATH).getPath());
+ conf.set(AuthzConfVars.AUTHZ_PROVIDER_BACKEND.getVar(), AuthzConfVars.AUTHZ_PROVIDER_BACKEND.getDefault());
+ conf.set(AuthzConfVars.AUTHZ_POLICY_ENGINE.getVar(), AuthzConfVars.AUTHZ_POLICY_ENGINE.getDefault());
+ }
+
+ /**
+ * Test that incorrect specification of classes for
+ * AUTHZ_PROVIDER, AUTHZ_PROVIDER_BACKEND, and AUTHZ_POLICY_ENGINE
+ * correctly throw ClassNotFoundExceptions
+ */
+ @Test
+ public void testClassNotFound() throws Exception {
+ SolrAuthzConf solrAuthzConf =
+ new SolrAuthzConf(Resources.getResource("sentry-site.xml"));
+ setUsableAuthzConf(solrAuthzConf);
+ // verify it is usable
+ new SolrAuthzBinding(solrAuthzConf);
+
+ // give a bogus provider
+ solrAuthzConf.set(AuthzConfVars.AUTHZ_PROVIDER.getVar(), "org.apache.sentry.provider.BogusProvider");
+ try {
+ new SolrAuthzBinding(solrAuthzConf);
+ Assert.fail("Expected ClassNotFoundException");
+ } catch (ClassNotFoundException e) {}
+
+ setUsableAuthzConf(solrAuthzConf);
+ // give a bogus provider backend
+ solrAuthzConf.set(AuthzConfVars.AUTHZ_PROVIDER_BACKEND.getVar(), "org.apache.sentry.provider.file.BogusProviderBackend");
+ try {
+ new SolrAuthzBinding(solrAuthzConf);
+ Assert.fail("Expected ClassNotFoundException");
+ } catch (ClassNotFoundException e) {}
+
+ setUsableAuthzConf(solrAuthzConf);
+ // give a bogus policy enine
+ solrAuthzConf.set(AuthzConfVars.AUTHZ_POLICY_ENGINE.getVar(), "org.apache.sentry.provider.solr.BogusPolicyEngine");
+ try {
+ new SolrAuthzBinding(solrAuthzConf);
+ Assert.fail("Expected ClassNotFoundException");
+ } catch (ClassNotFoundException e) {}
+ }
+
+ /**
+ * Test that incorrect specification of the provider resource
+ * throws an exception
+ */
+ @Test
+ public void testResourceNotFound() throws Exception {
+ SolrAuthzConf solrAuthzConf =
+ new SolrAuthzConf(Resources.getResource("sentry-site.xml"));
+ setUsableAuthzConf(solrAuthzConf);
+
+ // bogus specification
+ solrAuthzConf.set(AuthzConfVars.AUTHZ_PROVIDER_RESOURCE.getVar(), new File(baseDir, "test-authz-bogus-provider.ini").getPath());
+ try {
+ new SolrAuthzBinding(solrAuthzConf);
+ Assert.fail("Expected InvocationTargetException");
+ } catch (InvocationTargetException e) {
+ assertTrue(e.getTargetException() instanceof FileNotFoundException);
+ }
+
+ // missing specification
+ solrAuthzConf.unset(AuthzConfVars.AUTHZ_PROVIDER_RESOURCE.getVar());
+ try {
+ new SolrAuthzBinding(solrAuthzConf);
+ Assert.fail("Expected InvocationTargetException");
+ } catch (InvocationTargetException e) {
+ assertTrue(e.getTargetException() instanceof IllegalArgumentException);
+ }
+ }
+
+ /**
+ * Verify that an definition of only the AuthorizationProvider
+ * (not ProviderBackend or PolicyEngine) works.
+ */
+ @Test
+ public void testAuthProviderOnlySolrAuthzConfs() throws Exception {
+ new SolrAuthzBinding(authzConf);
+ }
+
+ /**
+ * Test that a full sentry-site definition works.
+ */
+ @Test
+ public void testSolrAuthzConfs() throws Exception {
+ SolrAuthzConf solrAuthzConf =
+ new SolrAuthzConf(Resources.getResource("sentry-site.xml"));
+ setUsableAuthzConf(solrAuthzConf);
+ new SolrAuthzBinding(solrAuthzConf);
+ }
+
+ private void expectAuthException(SolrAuthzBinding binding, Subject subject,
+ Collection collection, EnumSet<SearchModelAction> action) throws Exception {
+ try {
+ binding.authorizeCollection(new Subject("bogus"), infoCollection, querySet);
+ Assert.fail("Expected SentrySolrAuthorizationException");
+ } catch(SentrySolrAuthorizationException e) {
+ }
+ }
+
+ /**
+ * Test that a user that doesn't exist throws an exception
+ * when trying to authorize
+ */
+ @Test
+ public void testNoUser() throws Exception {
+ SolrAuthzConf solrAuthzConf =
+ new SolrAuthzConf(Resources.getResource("sentry-site.xml"));
+ setUsableAuthzConf(solrAuthzConf);
+ SolrAuthzBinding binding = new SolrAuthzBinding(solrAuthzConf);
+ expectAuthException(binding, new Subject("bogus"), infoCollection, querySet);
+ }
+
+ /**
+ * Test that a bogus collection name throws an exception
+ */
+ @Test
+ public void testNoCollection() throws Exception {
+ SolrAuthzConf solrAuthzConf =
+ new SolrAuthzConf(Resources.getResource("sentry-site.xml"));
+ setUsableAuthzConf(solrAuthzConf);
+ SolrAuthzBinding binding = new SolrAuthzBinding(solrAuthzConf);
+ expectAuthException(binding, corporal1, new Collection("bogus"), querySet);
+ }
+
+ /**
+ * Test if no action is attempted an exception is thrown
+ */
+ @Test
+ public void testNoAction() throws Exception {
+ SolrAuthzConf solrAuthzConf =
+ new SolrAuthzConf(Resources.getResource("sentry-site.xml"));
+ setUsableAuthzConf(solrAuthzConf);
+ SolrAuthzBinding binding = new SolrAuthzBinding(solrAuthzConf);
+ try {
+ binding.authorizeCollection(corporal1, infoCollection, emptySet);
+ Assert.fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ /**
+ * Test that standard unauthorized attempts fail
+ */
+ @Test
+ public void testAuthException() throws Exception {
+ SolrAuthzConf solrAuthzConf =
+ new SolrAuthzConf(Resources.getResource("sentry-site.xml"));
+ setUsableAuthzConf(solrAuthzConf);
+ SolrAuthzBinding binding = new SolrAuthzBinding(solrAuthzConf);
+ expectAuthException(binding, corporal1, infoCollection, updateSet);
+ expectAuthException(binding, corporal1, infoCollection, allSet);
+ expectAuthException(binding, corporal1, generalInfoCollection, querySet);
+ expectAuthException(binding, corporal1, generalInfoCollection, updateSet);
+ expectAuthException(binding, corporal1, generalInfoCollection, allSet);
+ expectAuthException(binding, sergeant1, infoCollection, allSet);
+ expectAuthException(binding, sergeant1, generalInfoCollection, querySet);
+ expectAuthException(binding, sergeant1, generalInfoCollection, updateSet);
+ expectAuthException(binding, sergeant1, generalInfoCollection, allSet);
+ }
+
+ /**
+ * Test that standard authorized attempts succeed
+ */
+ @Test
+ public void testAuthAllowed() throws Exception {
+ SolrAuthzConf solrAuthzConf =
+ new SolrAuthzConf(Resources.getResource("sentry-site.xml"));
+ setUsableAuthzConf(solrAuthzConf);
+ SolrAuthzBinding binding = new SolrAuthzBinding(solrAuthzConf);
+ binding.authorizeCollection(corporal1, infoCollection, querySet);
+ binding.authorizeCollection(sergeant1, infoCollection, querySet);
+ binding.authorizeCollection(sergeant1, infoCollection, updateSet);
+ binding.authorizeCollection(general1, infoCollection, querySet);
+ binding.authorizeCollection(general1, infoCollection, updateSet);
+ binding.authorizeCollection(general1, infoCollection, allSet);
+ binding.authorizeCollection(general1, infoCollection, allOfSet);
+ binding.authorizeCollection(general1, generalInfoCollection, querySet);
+ binding.authorizeCollection(general1, generalInfoCollection, updateSet);
+ binding.authorizeCollection(general1, generalInfoCollection, allSet);
+ binding.authorizeCollection(general1, generalInfoCollection, allOfSet);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/44f44e1b/sentry-binding/sentry-binding-solr/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-solr/src/test/resources/log4j.properties b/sentry-binding/sentry-binding-solr/src/test/resources/log4j.properties
new file mode 100644
index 0000000..c41373c
--- /dev/null
+++ b/sentry-binding/sentry-binding-solr/src/test/resources/log4j.properties
@@ -0,0 +1,31 @@
+#
+# 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.
+#
+
+# Define some default values that can be overridden by system properties.
+#
+# For testing, it may also be convenient to specify
+
+log4j.rootLogger=DEBUG,console
+
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.target=System.err
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%d (%t) [%p - %l] %m%n
+
+log4j.logger.org.apache.hadoop.conf.Configuration=INFO
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/44f44e1b/sentry-binding/sentry-binding-solr/src/test/resources/sentry-site.xml
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-solr/src/test/resources/sentry-site.xml b/sentry-binding/sentry-binding-solr/src/test/resources/sentry-site.xml
new file mode 100644
index 0000000..5d7e555
--- /dev/null
+++ b/sentry-binding/sentry-binding-solr/src/test/resources/sentry-site.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
+<!--
+ 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.
+-->
+
+<configuration>
+ <property>
+ <name>sentry.provider</name>
+ <value>org.apache.sentry.provider.file.LocalGroupResourceAuthorizationProvider</value>
+ </property>
+ <property>
+ <name>sentry.solr.provider.resource</name>
+ <value>classpath:test-authz-provider.ini</value>
+ </property>
+</configuration>
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/44f44e1b/sentry-binding/sentry-binding-solr/src/test/resources/test-authz-provider.ini
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-solr/src/test/resources/test-authz-provider.ini b/sentry-binding/sentry-binding-solr/src/test/resources/test-authz-provider.ini
new file mode 100644
index 0000000..db9af6e
--- /dev/null
+++ b/sentry-binding/sentry-binding-solr/src/test/resources/test-authz-provider.ini
@@ -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.
+
+[groups]
+corporal = corporal_role
+sergeant = corporal_role, sergeant_role
+general = corporal_role, sergeant_role, general_role
+
+[roles]
+#test that specification of a bogus action doesn't affect further specifications
+corporal_role = collection=info->action=FOOBAR, \
+ collection=info->action=query
+sergeant_role = collection=info->action=update
+general_role = collection=*->action=*
+
+[users]
+corporal1=corporal
+sergeant1=sergeant
+general1=general
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/44f44e1b/sentry-dist/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-dist/pom.xml b/sentry-dist/pom.xml
index 895b03c..7a27b82 100644
--- a/sentry-dist/pom.xml
+++ b/sentry-dist/pom.xml
@@ -44,6 +44,10 @@ limitations under the License.
</dependency>
<dependency>
<groupId>org.apache.sentry</groupId>
+ <artifactId>sentry-binding-solr</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sentry</groupId>
<artifactId>sentry-provider-common</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/44f44e1b/sentry-dist/src/main/assembly/src.xml
----------------------------------------------------------------------
diff --git a/sentry-dist/src/main/assembly/src.xml b/sentry-dist/src/main/assembly/src.xml
index 91f5696..f1ebaf5 100644
--- a/sentry-dist/src/main/assembly/src.xml
+++ b/sentry-dist/src/main/assembly/src.xml
@@ -38,6 +38,7 @@
<includes>
<include>org.apache.sentry:sentry-binding</include>
<include>org.apache.sentry:sentry-binding-hive</include>
+ <include>org.apache.sentry:sentry-binding-solr</include>
<include>org.apache.sentry:sentry-core</include>
<include>org.apache.sentry:sentry-core-common</include>
<include>org.apache.sentry:sentry-core-model-db</include>
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/44f44e1b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/ResourceAuthorizationProvider.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/ResourceAuthorizationProvider.java b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/ResourceAuthorizationProvider.java
index 4e12b70..3933314 100644
--- a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/ResourceAuthorizationProvider.java
+++ b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/ResourceAuthorizationProvider.java
@@ -74,7 +74,7 @@ public abstract class ResourceAuthorizationProvider implements AuthorizationProv
Preconditions.checkNotNull(authorizableHierarchy, "Authorizable cannot be null");
Preconditions.checkArgument(!authorizableHierarchy.isEmpty(), "Authorizable cannot be empty");
Preconditions.checkNotNull(actions, "Actions cannot be null");
- Preconditions.checkNotNull(!actions.isEmpty(), "Actions cannot be empty");
+ Preconditions.checkArgument(!actions.isEmpty(), "Actions cannot be empty");
return doHasAccess(subject, authorizableHierarchy, actions);
}