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/15 00:20:37 UTC

[2/2] git commit: SENTRY-27: Refactor to be able to support different provider backends (e.g. db vs file) (Gregory Chanan via Brock Noland)

SENTRY-27: Refactor to be able to support different provider backends (e.g. db vs file) (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/fe5fb70f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/fe5fb70f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/fe5fb70f

Branch: refs/heads/master
Commit: fe5fb70f65c8400a2bba82e8c7399085246e81ef
Parents: ed7b753
Author: Brock Noland <br...@apache.org>
Authored: Mon Oct 14 17:20:27 2013 -0500
Committer: Brock Noland <br...@apache.org>
Committed: Mon Oct 14 17:20:27 2013 -0500

----------------------------------------------------------------------
 pom.xml                                         |   7 +-
 sentry-binding/sentry-binding-hive/pom.xml      |   4 +
 .../binding/hive/authz/HiveAuthzBinding.java    |  28 ++-
 .../sentry/binding/hive/conf/HiveAuthzConf.java |   2 +
 .../binding/hive/MockUserToGroupMapping.java    |   2 +-
 .../binding/hive/TestHiveAuthzBindings.java     |  27 ++-
 sentry-dist/pom.xml                             |   4 +
 sentry-dist/src/main/assembly/src.xml           |   1 +
 sentry-provider/pom.xml                         |   1 +
 sentry-provider/sentry-provider-common/pom.xml  |  62 +++++
 .../provider/common/GroupMappingService.java    |  30 +++
 .../provider/common/PermissionFactory.java      |  26 ++
 .../sentry/provider/common/PolicyEngine.java    |  46 ++++
 .../sentry/provider/common/ProviderBackend.java |  38 +++
 .../sentry/provider/common/RoleValidator.java   |  26 ++
 .../apache/sentry/provider/common/Roles.java    |  50 ++++
 .../common/MockGroupMappingServiceProvider.java |  45 ++++
 sentry-provider/sentry-provider-file/pom.xml    |  20 +-
 .../provider/file/GroupMappingService.java      |  30 ---
 .../file/HadoopGroupMappingService.java         |   1 +
 ...adoopGroupResourceAuthorizationProvider.java |  47 ++++
 .../provider/file/LocalGroupMappingService.java |   1 +
 ...LocalGroupResourceAuthorizationProvider.java |  34 +++
 .../sentry/provider/file/PermissionFactory.java |  26 --
 .../sentry/provider/file/PolicyEngine.java      |  39 ---
 .../file/ResourceAuthorizationProvider.java     |  12 +-
 .../sentry/provider/file/RoleValidator.java     |  26 --
 .../org/apache/sentry/provider/file/Roles.java  |  50 ----
 .../file/SimpleFileProviderBackend.java         | 243 +++++++++++++++++++
 .../provider/file/SimplePolicyParser.java       | 239 ------------------
 .../file/AbstractTestSimplePolicyEngine.java    | 162 -------------
 .../file/MockGroupMappingServiceProvider.java   |  45 ----
 .../sentry-provider-policy-db/pom.xml           |   6 +-
 .../provider/db/AbstractDBRoleValidator.java    |   2 +-
 .../provider/db/DBWildcardPermission.java       |   2 +-
 ...adoopGroupResourceAuthorizationProvider.java |  44 ----
 ...LocalGroupResourceAuthorizationProvider.java |  35 ---
 .../provider/db/SimpleDBPolicyEngine.java       |  32 ++-
 .../db/AbstractTestSimplePolicyEngine.java      | 163 +++++++++++++
 .../sentry/provider/db/DBPolicyFileBackend.java |  26 ++
 .../provider/db/TestPolicyParsingNegative.java  |  20 +-
 ...sourceAuthorizationProviderGeneralCases.java |   5 +-
 ...sourceAuthorizationProviderSpecialCases.java |   8 +-
 .../db/TestSimpleDBPolicyEngineDFS.java         |   7 +-
 .../db/TestSimpleDBPolicyEngineLocalFS.java     |   3 +-
 .../search/AbstractSearchRoleValidator.java     |   2 +-
 .../search/SearchWildcardPermission.java        |   2 +-
 .../e2e/hive/hiveserver/HiveServerFactory.java  |   2 +-
 48 files changed, 965 insertions(+), 768 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 9b73a21..a713c41 100644
--- a/pom.xml
+++ b/pom.xml
@@ -243,7 +243,12 @@ limitations under the License.
         <artifactId>sentry-binding-hive</artifactId>
         <version>${project.version}</version>
         <scope>test</scope>
-       </dependency>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.sentry</groupId>
+        <artifactId>sentry-provider-common</artifactId>
+        <version>${project.version}</version>
+      </dependency>
       <dependency>
         <groupId>org.apache.sentry</groupId>
         <artifactId>sentry-provider-file</artifactId>

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-binding/sentry-binding-hive/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/pom.xml b/sentry-binding/sentry-binding-hive/pom.xml
index 16b12dd..2b09a47 100644
--- a/sentry-binding/sentry-binding-hive/pom.xml
+++ b/sentry-binding/sentry-binding-hive/pom.xml
@@ -72,6 +72,10 @@ limitations under the License.
     </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>

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/HiveAuthzBinding.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/HiveAuthzBinding.java b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/HiveAuthzBinding.java
index 36d2fd1..d0ec4de 100644
--- a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/HiveAuthzBinding.java
+++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/HiveAuthzBinding.java
@@ -40,6 +40,8 @@ import org.apache.sentry.core.model.db.DBModelAction;
 import org.apache.sentry.core.model.db.DBModelAuthorizable;
 import org.apache.sentry.core.model.db.DBModelAuthorizable.AuthorizableType;
 import org.apache.sentry.core.model.db.Server;
+import org.apache.sentry.provider.common.PolicyEngine;
+import org.apache.sentry.provider.common.ProviderBackend;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.sentry.binding.hive.conf.InvalidConfigurationException;
@@ -127,14 +129,34 @@ public class HiveAuthzBinding {
     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);
+      " 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(String.class, ProviderBackend.class);
+    policyConstructor.setAccessible(true);
+    PolicyEngine policyEngine =
+      (PolicyEngine) policyConstructor.newInstance(new Object[] {serverName, providerBackend});
+
 
     // load the authz provider class
     Constructor<?> constrctor =
-        Class.forName(authProviderName).getDeclaredConstructor(String.class, String.class);
+      Class.forName(authProviderName).getDeclaredConstructor(String.class, PolicyEngine.class);
     constrctor.setAccessible(true);
-    return (AuthorizationProvider) constrctor.newInstance(new Object[] {resourceName, serverName});
+    return (AuthorizationProvider) constrctor.newInstance(new Object[] {resourceName, policyEngine});
   }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/conf/HiveAuthzConf.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/conf/HiveAuthzConf.java b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/conf/HiveAuthzConf.java
index ab1b4d3..7df12a6 100644
--- a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/conf/HiveAuthzConf.java
+++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/conf/HiveAuthzConf.java
@@ -44,6 +44,8 @@ public class HiveAuthzConf extends Configuration {
     AUTHZ_PROVIDER("sentry.provider",
       "org.apache.sentry.provider.file.ResourceAuthorizationProvider"),
     AUTHZ_PROVIDER_RESOURCE("sentry.hive.provider.resource", ""),
+    AUTHZ_PROVIDER_BACKEND("sentry.hive.provider.backend", "org.apache.sentry.provider.file.SimpleFileProviderBackend"),
+    AUTHZ_POLICY_ENGINE("sentry.hive.policy.engine", "org.apache.sentry.provider.db.SimpleDBPolicyEngine"),
     AUTHZ_SERVER_NAME("sentry.hive.server", "HS2"),
     AUTHZ_RESTRICT_DEFAULT_DB("sentry.hive.restrict.defaultDB", "false"),
     SENTRY_TESTING_MODE("sentry.hive.testing.mode", "false"),

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/MockUserToGroupMapping.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/MockUserToGroupMapping.java b/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/MockUserToGroupMapping.java
index 881712b..83432ca 100644
--- a/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/MockUserToGroupMapping.java
+++ b/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/MockUserToGroupMapping.java
@@ -19,7 +19,7 @@ package org.apache.sentry.binding.hive;
 
 import java.util.List;
 
-import org.apache.sentry.provider.file.GroupMappingService;
+import org.apache.sentry.provider.common.GroupMappingService;
 
 import com.google.common.collect.Lists;
 

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestHiveAuthzBindings.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestHiveAuthzBindings.java b/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestHiveAuthzBindings.java
index 506abf8..6b2166b 100644
--- a/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestHiveAuthzBindings.java
+++ b/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestHiveAuthzBindings.java
@@ -106,7 +106,7 @@ public class TestHiveAuthzBindings {
 
     // create auth configuration
     authzConf.set(AuthzConfVars.AUTHZ_PROVIDER.getVar(),
-        "org.apache.sentry.provider.db.LocalGroupResourceAuthorizationProvider");
+        "org.apache.sentry.provider.file.LocalGroupResourceAuthorizationProvider");
     authzConf.set(AuthzConfVars.AUTHZ_PROVIDER_RESOURCE.getVar(),
         new File(baseDir, RESOURCE_PATH).getPath());
     authzConf.set(AuthzConfVars.AUTHZ_SERVER_NAME.getVar(), SERVER1);
@@ -342,4 +342,29 @@ public class TestHiveAuthzBindings {
     authzConf.set(AuthzConfVars.SENTRY_TESTING_MODE.getVar(), "false");
     testAuth = new HiveAuthzBinding(hiveConf, authzConf);
   }
+
+  /**
+   * Verify that an existing definition of only the AuthorizationProvider
+   * (not ProviderBackend or PolicyEngine) still works.
+   */
+  @Test
+  public void testDeprecatedHiveAuthzConfs() throws Exception {
+    // verify that a non-existant AuthorizationProvider throws an Exception
+    authzConf.set(AuthzConfVars.AUTHZ_PROVIDER.getVar(),
+      "org.apache.sentry.provider.BogusProvider");
+    try {
+      new HiveAuthzBinding(hiveConf, authzConf);
+      Assert.fail("Expected exception");
+    } catch (ClassNotFoundException e) {}
+
+    // verify HadoopGroupResourceAuthorizationProvider
+    authzConf.set(AuthzConfVars.AUTHZ_PROVIDER.getVar(),
+      "org.apache.sentry.provider.file.HadoopGroupResourceAuthorizationProvider");
+    new HiveAuthzBinding(hiveConf, authzConf);
+
+    // verify LocalGroupResourceAuthorizationProvider
+    authzConf.set(AuthzConfVars.AUTHZ_PROVIDER.getVar(),
+      "org.apache.sentry.provider.file.LocalGroupResourceAuthorizationProvider");
+    new HiveAuthzBinding(hiveConf, authzConf);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-dist/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-dist/pom.xml b/sentry-dist/pom.xml
index b398ce0..895b03c 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-provider-common</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sentry</groupId>
       <artifactId>sentry-provider-file</artifactId>
     </dependency>
     <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/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 60ec346..91f5696 100644
--- a/sentry-dist/src/main/assembly/src.xml
+++ b/sentry-dist/src/main/assembly/src.xml
@@ -43,6 +43,7 @@
         <include>org.apache.sentry:sentry-core-model-db</include>
         <include>org.apache.sentry:sentry-core-model-search</include>
         <include>org.apache.sentry:sentry-provider</include>
+        <include>org.apache.sentry:sentry-provider-common</include>
         <include>org.apache.sentry:sentry-provider-file</include>
         <include>org.apache.sentry:sentry-provider-policy-db</include>
         <include>org.apache.sentry:sentry-provider-policy-search</include>

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-provider/pom.xml b/sentry-provider/pom.xml
index 2667312..2a16800 100644
--- a/sentry-provider/pom.xml
+++ b/sentry-provider/pom.xml
@@ -30,6 +30,7 @@ limitations under the License.
   <packaging>pom</packaging>
 
   <modules>
+    <module>sentry-provider-common</module>
     <module>sentry-provider-file</module>
     <module>sentry-provider-policy-db</module>
     <module>sentry-provider-policy-search</module>

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-common/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-common/pom.xml b/sentry-provider/sentry-provider-common/pom.xml
new file mode 100644
index 0000000..f7be9dd
--- /dev/null
+++ b/sentry-provider/sentry-provider-common/pom.xml
@@ -0,0 +1,62 @@
+<?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-provider</artifactId>
+    <version>1.3.0-incubating-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>sentry-provider-common</artifactId>
+  <name>Sentry Provider Common</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.sentry</groupId>
+      <artifactId>sentry-core-common</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.shiro</groupId>
+      <artifactId>shiro-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+    </dependency>
+  </dependencies>
+
+  <!-- build a test jar -->
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <version>2.2</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>test-jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/GroupMappingService.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/GroupMappingService.java b/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/GroupMappingService.java
new file mode 100644
index 0000000..226cc88
--- /dev/null
+++ b/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/GroupMappingService.java
@@ -0,0 +1,30 @@
+/*
+ * 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.provider.common;
+
+import java.util.List;
+
+/**
+ * Interface so the Groups class is easier to unit test with.
+ */
+public interface GroupMappingService {
+
+  /**
+   * @return non-null list of groups for user
+   */
+  public List<String> getGroups(String user);
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/PermissionFactory.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/PermissionFactory.java b/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/PermissionFactory.java
new file mode 100644
index 0000000..5e7c7dd
--- /dev/null
+++ b/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/PermissionFactory.java
@@ -0,0 +1,26 @@
+/*
+ * 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.provider.common;
+
+import org.apache.shiro.authz.Permission;
+
+/**
+ * Factory for creating Shiro permissions
+ */
+public interface PermissionFactory {
+  Permission createPermission(String permission);
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/PolicyEngine.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/PolicyEngine.java b/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/PolicyEngine.java
new file mode 100644
index 0000000..ce0ea26
--- /dev/null
+++ b/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/PolicyEngine.java
@@ -0,0 +1,46 @@
+/*
+ * 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.provider.common;
+
+import java.util.List;
+
+import org.apache.sentry.core.common.Authorizable;
+
+import com.google.common.collect.ImmutableSetMultimap;
+
+public interface PolicyEngine {
+
+  /**
+   * The permission factory to use in order to compare permissions in {@link getPermission}.
+   * This is typically a factory that returns a permission used to evaluate wildcards.
+   * @return the permission factory
+   */
+  public PermissionFactory getPermissionFactory();
+
+  /**
+   * Get permissions associated with a group. Returns Strings which can be resolved
+   * by the caller. Strings are returned to separate the PolicyFile class from the
+   * type of permissions used in a policy file. Additionally it is possible further
+   * processing of the permissions is needed before resolving to a permission object.
+   * @param authorizeable object
+   * @param group name
+   * @return non-null immutable set of permissions
+   */
+  public ImmutableSetMultimap<String, String> getPermissions(List<? extends Authorizable> authorizables, List<String> groups);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/ProviderBackend.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/ProviderBackend.java b/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/ProviderBackend.java
new file mode 100644
index 0000000..32ac8b2
--- /dev/null
+++ b/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/ProviderBackend.java
@@ -0,0 +1,38 @@
+/*
+ * 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.provider.common;
+
+import javax.annotation.Nullable;
+import java.util.List;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Interface for getting roles from a specific provider backend.
+ */
+public interface ProviderBackend {
+  /**
+   * Process roles from the backend.  Checks the validity of each role
+   * by running it through each validator passed via validators.
+   */
+  public void process(List<? extends RoleValidator> validators);
+
+  /**
+   * Get the roles from the backend.  Requires that process(...) is invoked at
+   * least once prior.
+   */
+  public Roles getRoles();
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/RoleValidator.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/RoleValidator.java b/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/RoleValidator.java
new file mode 100644
index 0000000..efd44f1
--- /dev/null
+++ b/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/RoleValidator.java
@@ -0,0 +1,26 @@
+/*
+ * 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.provider.common;
+
+import javax.annotation.Nullable;
+
+import org.apache.shiro.config.ConfigurationException;
+
+public interface RoleValidator {
+
+  public void validate(@Nullable String database, String role) throws ConfigurationException;
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/Roles.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/Roles.java b/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/Roles.java
new file mode 100644
index 0000000..a8f36a3
--- /dev/null
+++ b/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/Roles.java
@@ -0,0 +1,50 @@
+/*
+ * 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.provider.common;
+
+import javax.annotation.Nullable;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSetMultimap;
+
+/**
+ * Class providing storage of roles
+ */
+public class Roles {
+  private final ImmutableSetMultimap<String, String> globalRoles;
+  private final ImmutableMap<String, ImmutableSetMultimap<String, String>> perDatabaseRoles;
+
+  public Roles() {
+    this(ImmutableSetMultimap.<String, String>of(),
+        ImmutableMap.<String, ImmutableSetMultimap<String, String>>of());
+  }
+
+  public Roles(ImmutableSetMultimap<String, String> globalRoles,
+      ImmutableMap<String, ImmutableSetMultimap<String, String>> perDatabaseRoles) {
+    this.globalRoles = globalRoles;
+    this.perDatabaseRoles = perDatabaseRoles;
+  }
+
+  public ImmutableSetMultimap<String, String> getGlobalRoles() {
+    return globalRoles;
+  }
+
+  public ImmutableMap<String, ImmutableSetMultimap<String, String>> getPerDatabaseRoles() {
+    return perDatabaseRoles;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-common/src/test/java/org/apache/sentry/provider/common/MockGroupMappingServiceProvider.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-common/src/test/java/org/apache/sentry/provider/common/MockGroupMappingServiceProvider.java b/sentry-provider/sentry-provider-common/src/test/java/org/apache/sentry/provider/common/MockGroupMappingServiceProvider.java
new file mode 100644
index 0000000..806b42e
--- /dev/null
+++ b/sentry-provider/sentry-provider-common/src/test/java/org/apache/sentry/provider/common/MockGroupMappingServiceProvider.java
@@ -0,0 +1,45 @@
+/*
+ * 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.provider.common;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.sentry.provider.common.GroupMappingService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Multimap;
+
+public class MockGroupMappingServiceProvider implements GroupMappingService {
+  private static final Logger LOGGER = LoggerFactory
+      .getLogger(MockGroupMappingServiceProvider.class);
+  private final Multimap<String, String> userToGroupMap;
+
+  public MockGroupMappingServiceProvider(Multimap<String, String> userToGroupMap) {
+    this.userToGroupMap = userToGroupMap;
+  }
+
+  @Override
+  public List<String> getGroups(String user) {
+    Collection<String> groups = userToGroupMap.get(user);
+    LOGGER.info("Mapping " + user + " to " + groups);
+    return Lists.newArrayList(groups);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-file/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-file/pom.xml b/sentry-provider/sentry-provider-file/pom.xml
index a3d010a..a804952 100644
--- a/sentry-provider/sentry-provider-file/pom.xml
+++ b/sentry-provider/sentry-provider-file/pom.xml
@@ -63,26 +63,8 @@ limitations under the License.
     </dependency>
     <dependency>
       <groupId>org.apache.sentry</groupId>
-      <artifactId>sentry-core-model-db</artifactId>
+      <artifactId>sentry-provider-common</artifactId>
     </dependency>
   </dependencies>
 
-  <!-- build a test jar -->
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-jar-plugin</artifactId>
-        <version>2.2</version>
-        <executions>
-          <execution>
-            <goals>
-              <goal>test-jar</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-     </plugins>
-   </build>
-
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/GroupMappingService.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/GroupMappingService.java b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/GroupMappingService.java
deleted file mode 100644
index 6af2edf..0000000
--- a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/GroupMappingService.java
+++ /dev/null
@@ -1,30 +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.sentry.provider.file;
-
-import java.util.List;
-
-/**
- * Interface so the Groups class is easier to unit test with.
- */
-public interface GroupMappingService {
-
-  /**
-   * @return non-null list of groups for user
-   */
-  public List<String> getGroups(String user);
-}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/HadoopGroupMappingService.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/HadoopGroupMappingService.java b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/HadoopGroupMappingService.java
index 1bbb125..4db465d 100644
--- a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/HadoopGroupMappingService.java
+++ b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/HadoopGroupMappingService.java
@@ -21,6 +21,7 @@ import java.util.Collections;
 import java.util.List;
 
 import org.apache.hadoop.security.Groups;
+import org.apache.sentry.provider.common.GroupMappingService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/HadoopGroupResourceAuthorizationProvider.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/HadoopGroupResourceAuthorizationProvider.java b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/HadoopGroupResourceAuthorizationProvider.java
new file mode 100644
index 0000000..24c0a5a
--- /dev/null
+++ b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/HadoopGroupResourceAuthorizationProvider.java
@@ -0,0 +1,47 @@
+/*
+ * 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.provider.file;
+
+import java.io.IOException;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.security.Groups;
+import org.apache.sentry.provider.common.GroupMappingService;
+import org.apache.sentry.provider.common.PolicyEngine;
+import org.apache.sentry.provider.file.HadoopGroupMappingService;
+import org.apache.sentry.provider.file.ResourceAuthorizationProvider;
+
+import com.google.common.annotations.VisibleForTesting;
+
+public class HadoopGroupResourceAuthorizationProvider extends
+  ResourceAuthorizationProvider {
+
+  // resource parameter present so that other AuthorizationProviders (e.g.
+  // LocalGroupResourceAuthorizationProvider) has the same constructor params.
+  public HadoopGroupResourceAuthorizationProvider(String resource, PolicyEngine policy) throws IOException {
+    this(policy, new HadoopGroupMappingService(
+        Groups.getUserToGroupsMappingService(new Configuration())));
+  }
+
+  @VisibleForTesting
+  public HadoopGroupResourceAuthorizationProvider(PolicyEngine policy,
+      GroupMappingService groupService) {
+    super(policy, groupService);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/LocalGroupMappingService.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/LocalGroupMappingService.java b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/LocalGroupMappingService.java
index fa3e804..c399117 100644
--- a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/LocalGroupMappingService.java
+++ b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/LocalGroupMappingService.java
@@ -27,6 +27,7 @@ import java.util.Map.Entry;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
+import org.apache.sentry.provider.common.GroupMappingService;
 import org.apache.shiro.config.Ini;
 import org.apache.shiro.config.Ini.Section;
 import org.slf4j.Logger;

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/LocalGroupResourceAuthorizationProvider.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/LocalGroupResourceAuthorizationProvider.java b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/LocalGroupResourceAuthorizationProvider.java
new file mode 100644
index 0000000..96f260e
--- /dev/null
+++ b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/LocalGroupResourceAuthorizationProvider.java
@@ -0,0 +1,34 @@
+/*
+ * 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.provider.file;
+
+import org.apache.sentry.provider.common.PolicyEngine;
+import org.apache.sentry.provider.file.LocalGroupMappingService;
+import org.apache.sentry.provider.file.ResourceAuthorizationProvider;
+import java.io.IOException;
+
+import org.apache.hadoop.fs.Path;
+
+
+public class LocalGroupResourceAuthorizationProvider extends
+  ResourceAuthorizationProvider {
+
+  public LocalGroupResourceAuthorizationProvider(String resource, PolicyEngine policy) throws IOException {
+    super(policy, new LocalGroupMappingService(new Path(resource)));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PermissionFactory.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PermissionFactory.java b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PermissionFactory.java
deleted file mode 100644
index 44624e7..0000000
--- a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PermissionFactory.java
+++ /dev/null
@@ -1,26 +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.sentry.provider.file;
-
-import org.apache.shiro.authz.Permission;
-
-/**
- * Factory for creating Shiro permissions
- */
-public interface PermissionFactory {
-  Permission createPermission(String permission);
-}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyEngine.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyEngine.java b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyEngine.java
deleted file mode 100644
index ecf954e..0000000
--- a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyEngine.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.sentry.provider.file;
-
-import java.util.List;
-
-import org.apache.sentry.core.common.Authorizable;
-
-import com.google.common.collect.ImmutableSetMultimap;
-
-public interface PolicyEngine {
-
-  /**
-   * Get permissions associated with a group. Returns Strings which can be resolved
-   * by the caller. Strings are returned to separate the PolicyFile class from the
-   * type of permissions used in a policy file. Additionally it's possible further
-   * processing of the permissions is needed before resolving to a permission object.
-   * @param authorizeable object
-   * @param group name
-   * @return non-null immutable set of permissions
-   */
-  public ImmutableSetMultimap<String, String> getPermissions(List<? extends Authorizable> authorizables, List<String> groups);
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/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 dd63b85..4e12b70 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
@@ -28,10 +28,9 @@ import org.apache.sentry.core.common.Action;
 import org.apache.sentry.core.common.Authorizable;
 import org.apache.sentry.core.common.AuthorizationProvider;
 import org.apache.sentry.core.common.Subject;
-import org.apache.sentry.core.model.db.Database;
-import org.apache.sentry.core.model.db.Server;
-import org.apache.sentry.core.model.db.ServerResource;
-import org.apache.sentry.core.model.db.Table;
+import org.apache.sentry.provider.common.GroupMappingService;
+import org.apache.sentry.provider.common.PermissionFactory;
+import org.apache.sentry.provider.common.PolicyEngine;
 import org.apache.shiro.authz.Permission;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -49,11 +48,10 @@ public abstract class ResourceAuthorizationProvider implements AuthorizationProv
   private final PermissionFactory permissionFactory;
 
   public ResourceAuthorizationProvider(PolicyEngine policy,
-      GroupMappingService groupService, PermissionFactory permissionFactory) {
-    Preconditions.checkNotNull(permissionFactory, "Permission factory cannot be null");
+      GroupMappingService groupService) {
     this.policy = policy;
     this.groupService = groupService;
-    this.permissionFactory = permissionFactory;
+    this.permissionFactory = policy.getPermissionFactory();
   }
 
   /***

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/RoleValidator.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/RoleValidator.java b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/RoleValidator.java
deleted file mode 100644
index 323a18a..0000000
--- a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/RoleValidator.java
+++ /dev/null
@@ -1,26 +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.sentry.provider.file;
-
-import javax.annotation.Nullable;
-
-import org.apache.shiro.config.ConfigurationException;
-
-public interface RoleValidator {
-
-  public void validate(@Nullable String database, String role) throws ConfigurationException;
-}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/Roles.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/Roles.java b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/Roles.java
deleted file mode 100644
index 2c47232..0000000
--- a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/Roles.java
+++ /dev/null
@@ -1,50 +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.sentry.provider.file;
-
-import javax.annotation.Nullable;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSetMultimap;
-
-/**
- * Class providing storage of roles
- */
-public class Roles {
-  private final ImmutableSetMultimap<String, String> globalRoles;
-  private final ImmutableMap<String, ImmutableSetMultimap<String, String>> perDatabaseRoles;
-
-  public Roles() {
-    this(ImmutableSetMultimap.<String, String>of(),
-        ImmutableMap.<String, ImmutableSetMultimap<String, String>>of());
-  }
-
-  public Roles(ImmutableSetMultimap<String, String> globalRoles,
-      ImmutableMap<String, ImmutableSetMultimap<String, String>> perDatabaseRoles) {
-    this.globalRoles = globalRoles;
-    this.perDatabaseRoles = perDatabaseRoles;
-  }
-
-  public ImmutableSetMultimap<String, String> getGlobalRoles() {
-    return globalRoles;
-  }
-
-  public ImmutableMap<String, ImmutableSetMultimap<String, String>> getPerDatabaseRoles() {
-    return perDatabaseRoles;
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/SimpleFileProviderBackend.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/SimpleFileProviderBackend.java b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/SimpleFileProviderBackend.java
new file mode 100644
index 0000000..373050e
--- /dev/null
+++ b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/SimpleFileProviderBackend.java
@@ -0,0 +1,243 @@
+/*
+ * 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.provider.file;
+
+import static org.apache.sentry.provider.file.PolicyFileConstants.DATABASES;
+import static org.apache.sentry.provider.file.PolicyFileConstants.GROUPS;
+import static org.apache.sentry.provider.file.PolicyFileConstants.ROLES;
+import static org.apache.sentry.provider.file.PolicyFileConstants.ROLE_SPLITTER;
+import static org.apache.sentry.provider.file.PolicyFileConstants.USERS;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URI;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.Nullable;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.sentry.core.common.Authorizable;
+import org.apache.sentry.provider.common.ProviderBackend;
+import org.apache.sentry.provider.common.Roles;
+import org.apache.sentry.provider.common.RoleValidator;
+import org.apache.shiro.config.ConfigurationException;
+import org.apache.shiro.config.Ini;
+import org.apache.shiro.util.PermissionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSetMultimap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Sets;
+
+public class SimpleFileProviderBackend implements ProviderBackend {
+
+  private static final Logger LOGGER = LoggerFactory
+      .getLogger(SimpleFileProviderBackend.class);
+
+
+
+  private final FileSystem fileSystem;
+  private final Path resourcePath;
+  private final List<Path> perDbResources = Lists.newArrayList();
+  private Roles rolesStorage;
+  private final Configuration conf;
+  private boolean processed;
+
+  public SimpleFileProviderBackend(String resourcePath) throws IOException {
+    this(new Configuration(), new Path(resourcePath));
+  }
+
+  @VisibleForTesting
+  public SimpleFileProviderBackend(Configuration conf, Path resourcePath) throws IOException {
+    this.resourcePath = resourcePath;
+    this.fileSystem = resourcePath.getFileSystem(conf);
+    this.rolesStorage = new Roles();
+    this.conf = conf;
+    this.processed = false;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  public void process(List<? extends RoleValidator> validators) {
+    LOGGER.info("Parsing " + resourcePath);
+    Roles roles = new Roles();
+    try {
+      perDbResources.clear();
+      Ini ini = PolicyFiles.loadFromPath(fileSystem, resourcePath);
+      if(LOGGER.isDebugEnabled()) {
+        for(String sectionName : ini.getSectionNames()) {
+          LOGGER.debug("Section: " + sectionName);
+          Ini.Section section = ini.get(sectionName);
+          for(String key : section.keySet()) {
+            String value = section.get(key);
+            LOGGER.debug(key + " = " + value);
+          }
+        }
+      }
+      ImmutableSetMultimap<String, String> globalRoles;
+      Map<String, ImmutableSetMultimap<String, String>> perDatabaseRoles = Maps.newHashMap();
+      globalRoles = parseIni(null, ini, validators);
+      Ini.Section filesSection = ini.getSection(DATABASES);
+      if(filesSection == null) {
+        LOGGER.info("Section " + DATABASES + " needs no further processing");
+      } else {
+        for(Map.Entry<String, String> entry : filesSection.entrySet()) {
+          String database = Strings.nullToEmpty(entry.getKey()).trim().toLowerCase();
+          Path perDbPolicy = new Path(Strings.nullToEmpty(entry.getValue()).trim());
+          if(isRelative(perDbPolicy)) {
+            perDbPolicy = new Path(resourcePath.getParent(), perDbPolicy);
+          }
+          try {
+            LOGGER.info("Parsing " + perDbPolicy);
+            Ini perDbIni = PolicyFiles.loadFromPath(perDbPolicy.getFileSystem(conf), perDbPolicy);
+            if(perDbIni.containsKey(USERS)) {
+              throw new ConfigurationException("Per-db policy files cannot contain " + USERS + " section");
+            }
+            if(perDbIni.containsKey(DATABASES)) {
+              throw new ConfigurationException("Per-db policy files cannot contain " + DATABASES + " section");
+            }
+            ImmutableSetMultimap<String, String> currentDbRoles = parseIni(database, perDbIni, validators);
+            perDatabaseRoles.put(database, currentDbRoles);
+            perDbResources.add(perDbPolicy);
+          } catch (Exception e) {
+            LOGGER.error("Error processing key " + entry.getKey() + ", skipping " + entry.getValue(), e);
+          }
+        }
+      }
+      roles = new Roles(globalRoles, ImmutableMap.copyOf(perDatabaseRoles));
+    } catch (Exception e) {
+      LOGGER.error("Error processing file, ignoring " + resourcePath, e);
+    }
+    rolesStorage = roles;
+    this.processed = true;
+  }
+  /**
+   * Relative for our purposes is no scheme, no authority
+   * and a non-absolute path portion.
+   */
+  private boolean isRelative(Path path) {
+    URI uri = path.toUri();
+    return uri.getAuthority() == null && uri.getScheme() == null && !path.isUriPathAbsolute();
+  }
+
+  protected long getModificationTime() throws IOException {
+    // if resource path has been deleted, throw all exceptions
+    long result = fileSystem.getFileStatus(resourcePath).getModificationTime();
+    for(Path perDbPolicy : perDbResources) {
+      try {
+        result = Math.max(result, fileSystem.getFileStatus(perDbPolicy).getModificationTime());
+      } catch (FileNotFoundException e) {
+        // if a per-db file has been deleted, wait until the main
+        // policy file has been updated before refreshing
+      }
+    }
+    return result;
+  }
+
+  private ImmutableSetMultimap<String, String> parseIni(String database, Ini ini, List<? extends RoleValidator> validators) {
+    Ini.Section privilegesSection = ini.getSection(ROLES);
+    boolean invalidConfiguration = false;
+    if (privilegesSection == null) {
+      LOGGER.warn("Section {} empty for {}", ROLES, resourcePath);
+      invalidConfiguration = true;
+    }
+    Ini.Section groupsSection = ini.getSection(GROUPS);
+    if (groupsSection == null) {
+      LOGGER.warn("Section {} empty for {}", GROUPS, resourcePath);
+      invalidConfiguration = true;
+    }
+    if (!invalidConfiguration) {
+      return parsePermissions(database, privilegesSection, groupsSection, validators);
+    }
+    return ImmutableSetMultimap.of();
+  }
+
+  private ImmutableSetMultimap<String, String> parsePermissions(@Nullable String database,
+      Ini.Section rolesSection, Ini.Section groupsSection, List<? extends RoleValidator> validators) {
+    ImmutableSetMultimap.Builder<String, String> resultBuilder = ImmutableSetMultimap.builder();
+    Multimap<String, String> roleNameToPrivilegeMap = HashMultimap
+        .create();
+    for (Map.Entry<String, String> entry : rolesSection.entrySet()) {
+      String roleName = Strings.nullToEmpty(entry.getKey()).trim();
+      String roleValue = Strings.nullToEmpty(entry.getValue()).trim();
+      boolean invalidConfiguration = false;
+      if (roleName.isEmpty()) {
+        LOGGER.warn("Empty role name encountered in {}", resourcePath);
+        invalidConfiguration = true;
+      }
+      if (roleValue.isEmpty()) {
+        LOGGER.warn("Empty role value encountered in {}", resourcePath);
+        invalidConfiguration = true;
+      }
+      if (roleNameToPrivilegeMap.containsKey(roleName)) {
+        LOGGER.warn("Role {} defined twice in {}", roleName,
+            resourcePath);
+      }
+      Set<String> roles = PermissionUtils
+          .toPermissionStrings(roleValue);
+      if (!invalidConfiguration && roles != null) {
+        for(String role : roles) {
+          for(RoleValidator validator : validators) {
+            validator.validate(database, role.trim());
+          }
+        }
+        roleNameToPrivilegeMap.putAll(roleName, roles);
+      }
+    }
+    Splitter roleSplitter = ROLE_SPLITTER.omitEmptyStrings().trimResults();
+    for (Map.Entry<String, String> entry : groupsSection.entrySet()) {
+      String groupName = Strings.nullToEmpty(entry.getKey()).trim();
+      String groupPrivileges = Strings.nullToEmpty(entry.getValue()).trim();
+      Collection<String> resolvedGroupPrivileges = Sets.newHashSet();
+      for (String roleName : roleSplitter.split(groupPrivileges)) {
+        if (roleNameToPrivilegeMap.containsKey(roleName)) {
+          resolvedGroupPrivileges.addAll(roleNameToPrivilegeMap
+              .get(roleName));
+        } else {
+          LOGGER.warn("Role {} for group {} does not exist in privileges section in {}",
+              new Object[] { roleName, groupName, resourcePath });
+        }
+      }
+      resultBuilder.putAll(groupName, resolvedGroupPrivileges);
+    }
+    return resultBuilder.build();
+  }
+
+  /*
+   * {@inheritDoc}
+   */
+  public Roles getRoles() {
+    if (!processed) throw new UnsupportedOperationException("Process has not been called");
+
+    return rolesStorage;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/SimplePolicyParser.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/SimplePolicyParser.java b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/SimplePolicyParser.java
deleted file mode 100644
index 4bc692a..0000000
--- a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/SimplePolicyParser.java
+++ /dev/null
@@ -1,239 +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.sentry.provider.file;
-
-import static org.apache.sentry.provider.file.PolicyFileConstants.DATABASES;
-import static org.apache.sentry.provider.file.PolicyFileConstants.GROUPS;
-import static org.apache.sentry.provider.file.PolicyFileConstants.ROLES;
-import static org.apache.sentry.provider.file.PolicyFileConstants.ROLE_SPLITTER;
-import static org.apache.sentry.provider.file.PolicyFileConstants.USERS;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.net.URI;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicReference;
-
-import javax.annotation.Nullable;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.Path;
-import org.apache.sentry.core.common.Authorizable;
-import org.apache.sentry.core.model.db.AccessURI;
-import org.apache.sentry.core.model.db.Database;
-import org.apache.shiro.config.ConfigurationException;
-import org.apache.shiro.config.Ini;
-import org.apache.shiro.util.PermissionUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSetMultimap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Sets;
-
-public class SimplePolicyParser {
-
-  private static final Logger LOGGER = LoggerFactory
-      .getLogger(SimplePolicyParser.class);
-
-
-
-  private final FileSystem fileSystem;
-  private final Path resourcePath;
-  private final List<Path> perDbResources = Lists.newArrayList();
-  private final AtomicReference<Roles> rolesReference;
-  private final Configuration conf;
-  private final List<? extends RoleValidator> validators;
-
-  public SimplePolicyParser(String resourcePath, List<? extends RoleValidator> validators) throws IOException {
-    this(new Configuration(), new Path(resourcePath),  validators);
-  }
-
-  @VisibleForTesting
-  public SimplePolicyParser(Configuration conf, Path resourcePath, List<? extends RoleValidator> validators) throws IOException {
-    this.resourcePath = resourcePath;
-    this.fileSystem = resourcePath.getFileSystem(conf);
-    this.rolesReference = new AtomicReference<Roles>();
-    this.rolesReference.set(new Roles());
-    this.conf = conf;
-    this.validators = validators;
-    parse();
-  }
-
-  /**
-   * Parse the resource. Should not be used in the normal course
-   */
-  protected void parse() {
-    LOGGER.info("Parsing " + resourcePath);
-    Roles roles = new Roles();
-    try {
-      perDbResources.clear();
-      Ini ini = PolicyFiles.loadFromPath(fileSystem, resourcePath);
-      if(LOGGER.isDebugEnabled()) {
-        for(String sectionName : ini.getSectionNames()) {
-          LOGGER.debug("Section: " + sectionName);
-          Ini.Section section = ini.get(sectionName);
-          for(String key : section.keySet()) {
-            String value = section.get(key);
-            LOGGER.debug(key + " = " + value);
-          }
-        }
-      }
-      ImmutableSetMultimap<String, String> globalRoles;
-      Map<String, ImmutableSetMultimap<String, String>> perDatabaseRoles = Maps.newHashMap();
-      globalRoles = parseIni(null, ini);
-      Ini.Section filesSection = ini.getSection(DATABASES);
-      if(filesSection == null) {
-        LOGGER.info("Section " + DATABASES + " needs no further processing");
-      } else {
-        for(Map.Entry<String, String> entry : filesSection.entrySet()) {
-          String database = Strings.nullToEmpty(entry.getKey()).trim().toLowerCase();
-          Path perDbPolicy = new Path(Strings.nullToEmpty(entry.getValue()).trim());
-          if(isRelative(perDbPolicy)) {
-            perDbPolicy = new Path(resourcePath.getParent(), perDbPolicy);
-          }
-          try {
-            LOGGER.info("Parsing " + perDbPolicy);
-            Ini perDbIni = PolicyFiles.loadFromPath(perDbPolicy.getFileSystem(conf), perDbPolicy);
-            if(perDbIni.containsKey(USERS)) {
-              throw new ConfigurationException("Per-db policy files cannot contain " + USERS + " section");
-            }
-            if(perDbIni.containsKey(DATABASES)) {
-              throw new ConfigurationException("Per-db policy files cannot contain " + DATABASES + " section");
-            }
-            ImmutableSetMultimap<String, String> currentDbRoles = parseIni(database, perDbIni);
-            perDatabaseRoles.put(database, currentDbRoles);
-            perDbResources.add(perDbPolicy);
-          } catch (Exception e) {
-            LOGGER.error("Error processing key " + entry.getKey() + ", skipping " + entry.getValue(), e);
-          }
-        }
-      }
-      roles = new Roles(globalRoles, ImmutableMap.copyOf(perDatabaseRoles));
-    } catch (Exception e) {
-      LOGGER.error("Error processing file, ignoring " + resourcePath, e);
-    }
-    rolesReference.set(roles);
-  }
-  /**
-   * Relative for our purposes is no scheme, no authority
-   * and a non-absolute path portion.
-   */
-  private boolean isRelative(Path path) {
-    URI uri = path.toUri();
-    return uri.getAuthority() == null && uri.getScheme() == null && !path.isUriPathAbsolute();
-  }
-
-  protected long getModificationTime() throws IOException {
-    // if resource path has been deleted, throw all exceptions
-    long result = fileSystem.getFileStatus(resourcePath).getModificationTime();
-    for(Path perDbPolicy : perDbResources) {
-      try {
-        result = Math.max(result, fileSystem.getFileStatus(perDbPolicy).getModificationTime());
-      } catch (FileNotFoundException e) {
-        // if a per-db file has been deleted, wait until the main
-        // policy file has been updated before refreshing
-      }
-    }
-    return result;
-  }
-
-  private ImmutableSetMultimap<String, String> parseIni(String database, Ini ini) {
-    Ini.Section privilegesSection = ini.getSection(ROLES);
-    boolean invalidConfiguration = false;
-    if (privilegesSection == null) {
-      LOGGER.warn("Section {} empty for {}", ROLES, resourcePath);
-      invalidConfiguration = true;
-    }
-    Ini.Section groupsSection = ini.getSection(GROUPS);
-    if (groupsSection == null) {
-      LOGGER.warn("Section {} empty for {}", GROUPS, resourcePath);
-      invalidConfiguration = true;
-    }
-    if (!invalidConfiguration) {
-      return parsePermissions(database, privilegesSection, groupsSection);
-    }
-    return ImmutableSetMultimap.of();
-  }
-
-  private ImmutableSetMultimap<String, String> parsePermissions(@Nullable String database,
-      Ini.Section rolesSection, Ini.Section groupsSection) {
-    ImmutableSetMultimap.Builder<String, String> resultBuilder = ImmutableSetMultimap.builder();
-    Multimap<String, String> roleNameToPrivilegeMap = HashMultimap
-        .create();
-    for (Map.Entry<String, String> entry : rolesSection.entrySet()) {
-      String roleName = Strings.nullToEmpty(entry.getKey()).trim();
-      String roleValue = Strings.nullToEmpty(entry.getValue()).trim();
-      boolean invalidConfiguration = false;
-      if (roleName.isEmpty()) {
-        LOGGER.warn("Empty role name encountered in {}", resourcePath);
-        invalidConfiguration = true;
-      }
-      if (roleValue.isEmpty()) {
-        LOGGER.warn("Empty role value encountered in {}", resourcePath);
-        invalidConfiguration = true;
-      }
-      if (roleNameToPrivilegeMap.containsKey(roleName)) {
-        LOGGER.warn("Role {} defined twice in {}", roleName,
-            resourcePath);
-      }
-      Set<String> roles = PermissionUtils
-          .toPermissionStrings(roleValue);
-      if (!invalidConfiguration && roles != null) {
-        for(String role : roles) {
-          for(RoleValidator validator : validators) {
-            validator.validate(database, role.trim());
-          }
-        }
-        roleNameToPrivilegeMap.putAll(roleName, roles);
-      }
-    }
-    Splitter roleSplitter = ROLE_SPLITTER.omitEmptyStrings().trimResults();
-    for (Map.Entry<String, String> entry : groupsSection.entrySet()) {
-      String groupName = Strings.nullToEmpty(entry.getKey()).trim();
-      String groupPrivileges = Strings.nullToEmpty(entry.getValue()).trim();
-      Collection<String> resolvedGroupPrivileges = Sets.newHashSet();
-      for (String roleName : roleSplitter.split(groupPrivileges)) {
-        if (roleNameToPrivilegeMap.containsKey(roleName)) {
-          resolvedGroupPrivileges.addAll(roleNameToPrivilegeMap
-              .get(roleName));
-        } else {
-          LOGGER.warn("Role {} for group {} does not exist in privileges section in {}",
-              new Object[] { roleName, groupName, resourcePath });
-        }
-      }
-      resultBuilder.putAll(groupName, resolvedGroupPrivileges);
-    }
-    return resultBuilder.build();
-  }
-
-  public Roles getRoles() {
-    return rolesReference.get();
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-file/src/test/java/org/apache/sentry/provider/file/AbstractTestSimplePolicyEngine.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-file/src/test/java/org/apache/sentry/provider/file/AbstractTestSimplePolicyEngine.java b/sentry-provider/sentry-provider-file/src/test/java/org/apache/sentry/provider/file/AbstractTestSimplePolicyEngine.java
deleted file mode 100644
index aa28bb2..0000000
--- a/sentry-provider/sentry-provider-file/src/test/java/org/apache/sentry/provider/file/AbstractTestSimplePolicyEngine.java
+++ /dev/null
@@ -1,162 +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.sentry.provider.file;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-
-import junit.framework.Assert;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.sentry.core.common.Authorizable;
-import org.apache.sentry.core.model.db.Database;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-import com.google.common.io.Files;
-
-public abstract class AbstractTestSimplePolicyEngine {
-  private static final String PERM_SERVER1_CUSTOMERS_SELECT = "server=server1->db=customers->table=purchases->action=select";
-  private static final String PERM_SERVER1_CUSTOMERS_DB_CUSTOMERS_PARTIAL_SELECT = "server=server1->db=customers->table=purchases_partial->action=select";
-  private static final String PERM_SERVER1_ANALYST_ALL = "server=server1->db=analyst1";
-  private static final String PERM_SERVER1_JUNIOR_ANALYST_ALL = "server=server1->db=jranalyst1";
-  private static final String PERM_SERVER1_JUNIOR_ANALYST_READ = "server=server1->db=jranalyst1->table=*->action=select";
-  private static final String PERM_SERVER1_OTHER_GROUP_DB_CUSTOMERS_SELECT = "server=server1->db=other_group_db->table=purchases->action=select";
-
-  private static final String PERM_SERVER1_ADMIN = "server=server1";
-  private PolicyEngine policy;
-  private static File baseDir;
-  private List<Authorizable> authorizables = Lists.newArrayList();
-
-  @BeforeClass
-  public static void setupClazz() throws IOException {
-    baseDir = Files.createTempDir();
-  }
-
-  @AfterClass
-  public static void teardownClazz() throws IOException {
-    if(baseDir != null) {
-      FileUtils.deleteQuietly(baseDir);
-    }
-  }
-
-  protected void setPolicy(PolicyEngine policy) {
-    this.policy = policy;
-  }
-  protected static File getBaseDir() {
-    return baseDir;
-  }
-  @Before
-  public void setup() throws IOException {
-    afterSetup();
-  }
-  @After
-  public void teardown() throws IOException {
-    beforeTeardown();
-  }
-  protected void afterSetup() throws IOException {
-
-  }
-
-  protected void beforeTeardown() throws IOException {
-
-  }
-
-  @Test
-  public void testManager() throws Exception {
-    Set<String> expected = Sets.newTreeSet(Sets.newHashSet(
-        PERM_SERVER1_CUSTOMERS_SELECT, PERM_SERVER1_ANALYST_ALL,
-        PERM_SERVER1_JUNIOR_ANALYST_ALL, PERM_SERVER1_JUNIOR_ANALYST_READ,
-        PERM_SERVER1_CUSTOMERS_DB_CUSTOMERS_PARTIAL_SELECT
-        ));
-    Assert.assertEquals(expected.toString(),
-        new TreeSet<String>(policy.getPermissions(authorizables, list("manager")).values())
-        .toString());
-  }
-
-  @Test
-  public void testAnalyst() throws Exception {
-    Set<String> expected = Sets.newTreeSet(Sets.newHashSet(
-        PERM_SERVER1_CUSTOMERS_SELECT, PERM_SERVER1_ANALYST_ALL,
-        PERM_SERVER1_JUNIOR_ANALYST_READ));
-    Assert.assertEquals(expected.toString(),
-        new TreeSet<String>(policy.getPermissions(authorizables, list("analyst")).values())
-        .toString());
-  }
-
-  @Test
-  public void testJuniorAnalyst() throws Exception {
-    Set<String> expected = Sets.newTreeSet(Sets
-        .newHashSet(PERM_SERVER1_JUNIOR_ANALYST_ALL,
-            PERM_SERVER1_CUSTOMERS_DB_CUSTOMERS_PARTIAL_SELECT));
-    Assert.assertEquals(expected.toString(),
-        new TreeSet<String>(policy.getPermissions(authorizables, list("jranalyst")).values())
-        .toString());
-  }
-
-  @Test
-  public void testAdmin() throws Exception {
-    Set<String> expected = Sets.newTreeSet(Sets.newHashSet(PERM_SERVER1_ADMIN));
-    Assert.assertEquals(expected.toString(),
-        new TreeSet<String>(policy.getPermissions(authorizables, list("admin")).values())
-        .toString());
-  }
-
-
-  @Test
-  public void testOtherGroup() throws Exception {
-    authorizables.add(new Database("other_group_db"));
-    Set<String> expected = Sets.newTreeSet(Sets.newHashSet(
-        PERM_SERVER1_OTHER_GROUP_DB_CUSTOMERS_SELECT));
-    Assert.assertEquals(expected.toString(),
-        new TreeSet<String>(policy.getPermissions(authorizables, list("other_group")).values())
-        .toString());
-  }
-
-  @Test
-  public void testDbAll() throws Exception {
-    authorizables.add(new Database(Database.ALL.getName()));
-    Set<String> expected = Sets.newTreeSet(Sets
-        .newHashSet(PERM_SERVER1_JUNIOR_ANALYST_ALL,
-            PERM_SERVER1_CUSTOMERS_DB_CUSTOMERS_PARTIAL_SELECT));
-    Assert.assertEquals(expected.toString(),
-        new TreeSet<String>(policy.getPermissions(authorizables, list("jranalyst")).values())
-        .toString());
-  }
-
-  @Test
-  public void testDbAllforOtherGroup() throws Exception {
-    authorizables.add(new Database(Database.ALL.getName()));
-    Set<String> expected = Sets.newTreeSet(Sets.newHashSet(
-        PERM_SERVER1_OTHER_GROUP_DB_CUSTOMERS_SELECT));
-    Assert.assertEquals(expected.toString(),
-        new TreeSet<String>(policy.getPermissions(authorizables, list("other_group")).values())
-        .toString());
-  }
-
-  private static List<String> list(String... values) {
-    return Lists.newArrayList(values);
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-file/src/test/java/org/apache/sentry/provider/file/MockGroupMappingServiceProvider.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-file/src/test/java/org/apache/sentry/provider/file/MockGroupMappingServiceProvider.java b/sentry-provider/sentry-provider-file/src/test/java/org/apache/sentry/provider/file/MockGroupMappingServiceProvider.java
deleted file mode 100644
index 74956fc..0000000
--- a/sentry-provider/sentry-provider-file/src/test/java/org/apache/sentry/provider/file/MockGroupMappingServiceProvider.java
+++ /dev/null
@@ -1,45 +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.sentry.provider.file;
-
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.sentry.provider.file.GroupMappingService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Multimap;
-
-public class MockGroupMappingServiceProvider implements GroupMappingService {
-  private static final Logger LOGGER = LoggerFactory
-      .getLogger(MockGroupMappingServiceProvider.class);
-  private final Multimap<String, String> userToGroupMap;
-
-  public MockGroupMappingServiceProvider(Multimap<String, String> userToGroupMap) {
-    this.userToGroupMap = userToGroupMap;
-  }
-
-  @Override
-  public List<String> getGroups(String user) {
-    Collection<String> groups = userToGroupMap.get(user);
-    LOGGER.info("Mapping " + user + " to " + groups);
-    return Lists.newArrayList(groups);
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-policy-db/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-policy-db/pom.xml b/sentry-provider/sentry-provider-policy-db/pom.xml
index 412c13e..2245d75 100644
--- a/sentry-provider/sentry-provider-policy-db/pom.xml
+++ b/sentry-provider/sentry-provider-policy-db/pom.xml
@@ -74,11 +74,15 @@ limitations under the License.
     </dependency>
     <dependency>
       <groupId>org.apache.sentry</groupId>
-      <artifactId>sentry-provider-file</artifactId>
+      <artifactId>sentry-provider-common</artifactId>
     </dependency>
     <dependency>
       <groupId>org.apache.sentry</groupId>
       <artifactId>sentry-provider-file</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sentry</groupId>
+      <artifactId>sentry-provider-common</artifactId>
       <scope>test</scope>
       <type>test-jar</type>
       <version>${project.version}</version>

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-policy-db/src/main/java/org/apache/sentry/provider/db/AbstractDBRoleValidator.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-policy-db/src/main/java/org/apache/sentry/provider/db/AbstractDBRoleValidator.java b/sentry-provider/sentry-provider-policy-db/src/main/java/org/apache/sentry/provider/db/AbstractDBRoleValidator.java
index 19769eb..3f8241b 100644
--- a/sentry-provider/sentry-provider-policy-db/src/main/java/org/apache/sentry/provider/db/AbstractDBRoleValidator.java
+++ b/sentry-provider/sentry-provider-policy-db/src/main/java/org/apache/sentry/provider/db/AbstractDBRoleValidator.java
@@ -21,7 +21,7 @@ import static org.apache.sentry.provider.file.PolicyFileConstants.PRIVILEGE_PREF
 
 import java.util.List;
 
-import org.apache.sentry.provider.file.RoleValidator;
+import org.apache.sentry.provider.common.RoleValidator;
 import org.apache.sentry.core.model.db.DBModelAuthorizable;
 import org.apache.shiro.config.ConfigurationException;
 

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/fe5fb70f/sentry-provider/sentry-provider-policy-db/src/main/java/org/apache/sentry/provider/db/DBWildcardPermission.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-policy-db/src/main/java/org/apache/sentry/provider/db/DBWildcardPermission.java b/sentry-provider/sentry-provider-policy-db/src/main/java/org/apache/sentry/provider/db/DBWildcardPermission.java
index b49dd6a..1270fb2 100644
--- a/sentry-provider/sentry-provider-policy-db/src/main/java/org/apache/sentry/provider/db/DBWildcardPermission.java
+++ b/sentry-provider/sentry-provider-policy-db/src/main/java/org/apache/sentry/provider/db/DBWildcardPermission.java
@@ -33,8 +33,8 @@ import java.util.List;
 import org.apache.commons.lang.text.StrSubstitutor;
 import org.apache.sentry.core.model.db.AccessConstants;
 import org.apache.sentry.core.model.db.DBModelAuthorizable.AuthorizableType;
+import org.apache.sentry.provider.common.PermissionFactory;
 import org.apache.sentry.provider.file.KeyValue;
-import org.apache.sentry.provider.file.PermissionFactory;
 import org.apache.sentry.provider.file.PolicyFileConstants;
 import org.apache.shiro.authz.Permission;
 import org.slf4j.Logger;