Repository: incubator-sentry Updated Branches: refs/heads/master 0416dc016 -> 67b2146e3
SENTRY-740: Move the class PolicyFileConstants and KeyValue to provider-common (Colin Ma, reviewed by Dapeng Sun) Project: http://git-wip-us.apache.org/repos/asf/incubator-sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-sentry/commit/67b2146e Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/67b2146e Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/67b2146e Branch: refs/heads/master Commit: 67b2146e3b3914a44f45dd92092f835ba99362fd Parents: 0416dc0 Author: Colin Ma <[email protected]> Authored: Tue Jun 2 12:33:09 2015 +0800 Committer: Colin Ma <[email protected]> Committed: Tue Jun 2 12:33:09 2015 +0800 ---------------------------------------------------------------------- .../binding/hive/authz/SentryConfigTool.java | 25 +++--- .../policy/db/AbstractDBPrivilegeValidator.java | 4 +- .../sentry/policy/db/DBModelAuthorizables.java | 2 +- .../sentry/policy/db/DBWildcardPrivilege.java | 16 ++-- .../policy/db/TestDBWildcardPrivilege.java | 8 +- .../AbstractIndexerPrivilegeValidator.java | 4 +- .../indexer/IndexerModelAuthorizables.java | 2 +- .../indexer/IndexerWildcardPrivilege.java | 14 ++- .../indexer/TestIndexerWildcardPrivilege.java | 8 +- .../AbstractSearchPrivilegeValidator.java | 4 +- .../policy/search/SearchModelAuthorizables.java | 2 +- .../policy/search/SearchWildcardPrivilege.java | 14 ++- .../search/TestSearchWildcardPrivilege.java | 8 +- .../policy/sqoop/SqoopModelAuthorizables.java | 2 +- .../policy/sqoop/SqoopWildcardPrivilege.java | 2 +- .../sqoop/TestSqoopWildcardPrivilege.java | 8 +- .../apache/sentry/provider/common/KeyValue.java | 95 ++++++++++++++++++++ .../provider/common/PolicyFileConstants.java | 31 +++++++ .../sentry/provider/common/TestKeyValue.java | 76 ++++++++++++++++ .../apache/sentry/provider/file/KeyValue.java | 89 ------------------ .../provider/file/LocalGroupMappingService.java | 6 +- .../apache/sentry/provider/file/PolicyFile.java | 8 +- .../provider/file/PolicyFileConstants.java | 28 ------ .../sentry/provider/file/PolicyFiles.java | 23 ++--- .../file/SimpleFileProviderBackend.java | 54 +++++------ .../sentry/provider/file/TestKeyValue.java | 76 ---------------- 26 files changed, 307 insertions(+), 302 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryConfigTool.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryConfigTool.java b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryConfigTool.java index ecbd664..4388ca0 100644 --- a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryConfigTool.java +++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryConfigTool.java @@ -17,7 +17,14 @@ package org.apache.sentry.binding.hive.authz; -import com.google.common.collect.Table; +import java.security.CodeSource; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.HashSet; +import java.util.Set; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.GnuParser; @@ -40,7 +47,6 @@ import org.apache.sentry.binding.hive.HiveAuthzBindingHook; import org.apache.sentry.binding.hive.HiveAuthzBindingSessionHook; import org.apache.sentry.binding.hive.conf.HiveAuthzConf; import org.apache.sentry.binding.hive.conf.HiveAuthzConf.AuthzConfVars; - import org.apache.sentry.core.common.SentryConfigurationException; import org.apache.sentry.core.common.Subject; import org.apache.sentry.core.model.db.AccessConstants; @@ -48,22 +54,15 @@ import org.apache.sentry.core.model.db.DBModelAuthorizable; import org.apache.sentry.core.model.db.Server; import org.apache.sentry.policy.db.DBModelAuthorizables; import org.apache.sentry.provider.common.AuthorizationProvider; +import org.apache.sentry.provider.common.KeyValue; import org.apache.sentry.provider.common.ProviderBackendContext; +import org.apache.sentry.provider.common.ProviderConstants; import org.apache.sentry.provider.db.service.thrift.SentryPolicyServiceClient; import org.apache.sentry.provider.db.service.thrift.TSentryRole; -import org.apache.sentry.provider.file.KeyValue; -import org.apache.sentry.provider.file.PolicyFileConstants; import org.apache.sentry.provider.file.SimpleFileProviderBackend; import org.apache.sentry.service.thrift.SentryServiceClientFactory; -import java.security.CodeSource; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.HashSet; -import java.util.Set; +import com.google.common.collect.Table; public class SentryConfigTool { private String sentrySiteFile = null; @@ -294,7 +293,7 @@ public class SentryConfigTool { String column = null; String uri = null; String action = AccessConstants.ALL; - for (String authorizable : PolicyFileConstants.AUTHORIZABLE_SPLITTER. + for (String authorizable : ProviderConstants.AUTHORIZABLE_SPLITTER. trimResults().split(permission)) { KeyValue kv = new KeyValue(authorizable); DBModelAuthorizable a = DBModelAuthorizables.from(kv); http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-policy/sentry-policy-db/src/main/java/org/apache/sentry/policy/db/AbstractDBPrivilegeValidator.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-db/src/main/java/org/apache/sentry/policy/db/AbstractDBPrivilegeValidator.java b/sentry-policy/sentry-policy-db/src/main/java/org/apache/sentry/policy/db/AbstractDBPrivilegeValidator.java index 1b774ee..e940fc3 100644 --- a/sentry-policy/sentry-policy-db/src/main/java/org/apache/sentry/policy/db/AbstractDBPrivilegeValidator.java +++ b/sentry-policy/sentry-policy-db/src/main/java/org/apache/sentry/policy/db/AbstractDBPrivilegeValidator.java @@ -16,8 +16,8 @@ */ package org.apache.sentry.policy.db; -import static org.apache.sentry.provider.file.PolicyFileConstants.AUTHORIZABLE_SPLITTER; -import static org.apache.sentry.provider.file.PolicyFileConstants.PRIVILEGE_PREFIX; +import static org.apache.sentry.provider.common.ProviderConstants.AUTHORIZABLE_SPLITTER; +import static org.apache.sentry.provider.common.ProviderConstants.PRIVILEGE_PREFIX; import java.util.List; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-policy/sentry-policy-db/src/main/java/org/apache/sentry/policy/db/DBModelAuthorizables.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-db/src/main/java/org/apache/sentry/policy/db/DBModelAuthorizables.java b/sentry-policy/sentry-policy-db/src/main/java/org/apache/sentry/policy/db/DBModelAuthorizables.java index e47c733..f07eb11 100644 --- a/sentry-policy/sentry-policy-db/src/main/java/org/apache/sentry/policy/db/DBModelAuthorizables.java +++ b/sentry-policy/sentry-policy-db/src/main/java/org/apache/sentry/policy/db/DBModelAuthorizables.java @@ -24,7 +24,7 @@ import org.apache.sentry.core.model.db.Database; import org.apache.sentry.core.model.db.Server; import org.apache.sentry.core.model.db.Table; import org.apache.sentry.core.model.db.View; -import org.apache.sentry.provider.file.KeyValue; +import org.apache.sentry.provider.common.KeyValue; public class DBModelAuthorizables { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-policy/sentry-policy-db/src/main/java/org/apache/sentry/policy/db/DBWildcardPrivilege.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-db/src/main/java/org/apache/sentry/policy/db/DBWildcardPrivilege.java b/sentry-policy/sentry-policy-db/src/main/java/org/apache/sentry/policy/db/DBWildcardPrivilege.java index e2de7a7..939d9ec 100644 --- a/sentry-policy/sentry-policy-db/src/main/java/org/apache/sentry/policy/db/DBWildcardPrivilege.java +++ b/sentry-policy/sentry-policy-db/src/main/java/org/apache/sentry/policy/db/DBWildcardPrivilege.java @@ -21,9 +21,6 @@ package org.apache.sentry.policy.db; -import static org.apache.sentry.provider.common.ProviderConstants.AUTHORIZABLE_JOINER; -import static org.apache.sentry.provider.common.ProviderConstants.AUTHORIZABLE_SPLITTER; - import java.util.List; import org.apache.sentry.core.common.utils.PathUtils; @@ -31,8 +28,8 @@ import org.apache.sentry.core.model.db.AccessConstants; import org.apache.sentry.core.model.db.DBModelAuthorizable.AuthorizableType; import org.apache.sentry.policy.common.Privilege; import org.apache.sentry.policy.common.PrivilegeFactory; -import org.apache.sentry.provider.file.KeyValue; -import org.apache.sentry.provider.file.PolicyFileConstants; +import org.apache.sentry.provider.common.KeyValue; +import org.apache.sentry.provider.common.ProviderConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,7 +52,8 @@ public class DBWildcardPrivilege implements Privilege { throw new IllegalArgumentException("Wildcard string cannot be null or empty."); } List<KeyValue>parts = Lists.newArrayList(); - for (String authorizable : AUTHORIZABLE_SPLITTER.trimResults().split(wildcardString)) { + for (String authorizable : ProviderConstants.AUTHORIZABLE_SPLITTER.trimResults().split( + wildcardString)) { if (authorizable.isEmpty()) { throw new IllegalArgumentException("Privilege '" + wildcardString + "' has an empty section"); } @@ -123,11 +121,11 @@ public class DBWildcardPrivilege implements Privilege { if(policyPart.getValue().equals(AccessConstants.ALL) || policyPart.getValue().equalsIgnoreCase("ALL") || policyPart.equals(requestPart)) { return true; - } else if (!PolicyFileConstants.PRIVILEGE_NAME.equalsIgnoreCase(policyPart.getKey()) + } else if (!ProviderConstants.PRIVILEGE_NAME.equalsIgnoreCase(policyPart.getKey()) && AccessConstants.ALL.equalsIgnoreCase(requestPart.getValue())) { /* privilege request is to match with any object of given type */ return true; - } else if (!PolicyFileConstants.PRIVILEGE_NAME.equalsIgnoreCase(policyPart.getKey()) + } else if (!ProviderConstants.PRIVILEGE_NAME.equalsIgnoreCase(policyPart.getKey()) && AccessConstants.SOME.equalsIgnoreCase(requestPart.getValue())) { /* privilege request is to match with any object of given type */ return true; @@ -144,7 +142,7 @@ public class DBWildcardPrivilege implements Privilege { @Override public String toString() { - return AUTHORIZABLE_JOINER.join(parts); + return ProviderConstants.AUTHORIZABLE_JOINER.join(parts); } @Override http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-policy/sentry-policy-db/src/test/java/org/apache/sentry/policy/db/TestDBWildcardPrivilege.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-db/src/test/java/org/apache/sentry/policy/db/TestDBWildcardPrivilege.java b/sentry-policy/sentry-policy-db/src/test/java/org/apache/sentry/policy/db/TestDBWildcardPrivilege.java index bc1194e..bf5cec5 100644 --- a/sentry-policy/sentry-policy-db/src/test/java/org/apache/sentry/policy/db/TestDBWildcardPrivilege.java +++ b/sentry-policy/sentry-policy-db/src/test/java/org/apache/sentry/policy/db/TestDBWildcardPrivilege.java @@ -20,13 +20,13 @@ package org.apache.sentry.policy.db; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; -import static org.apache.sentry.provider.file.PolicyFileConstants.AUTHORIZABLE_JOINER; -import static org.apache.sentry.provider.file.PolicyFileConstants.KV_JOINER; -import static org.apache.sentry.provider.file.PolicyFileConstants.KV_SEPARATOR; +import static org.apache.sentry.provider.common.ProviderConstants.AUTHORIZABLE_JOINER; +import static org.apache.sentry.provider.common.ProviderConstants.KV_JOINER; +import static org.apache.sentry.provider.common.ProviderConstants.KV_SEPARATOR; import org.apache.sentry.core.model.db.AccessConstants; import org.apache.sentry.policy.common.Privilege; -import org.apache.sentry.provider.file.KeyValue; +import org.apache.sentry.provider.common.KeyValue; import org.junit.Test; public class TestDBWildcardPrivilege { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-policy/sentry-policy-indexer/src/main/java/org/apache/sentry/policy/indexer/AbstractIndexerPrivilegeValidator.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-indexer/src/main/java/org/apache/sentry/policy/indexer/AbstractIndexerPrivilegeValidator.java b/sentry-policy/sentry-policy-indexer/src/main/java/org/apache/sentry/policy/indexer/AbstractIndexerPrivilegeValidator.java index 6f0012b..8520d1a 100644 --- a/sentry-policy/sentry-policy-indexer/src/main/java/org/apache/sentry/policy/indexer/AbstractIndexerPrivilegeValidator.java +++ b/sentry-policy/sentry-policy-indexer/src/main/java/org/apache/sentry/policy/indexer/AbstractIndexerPrivilegeValidator.java @@ -16,8 +16,8 @@ */ package org.apache.sentry.policy.indexer; -import static org.apache.sentry.provider.file.PolicyFileConstants.AUTHORIZABLE_SPLITTER; -import static org.apache.sentry.provider.file.PolicyFileConstants.PRIVILEGE_PREFIX; +import static org.apache.sentry.provider.common.ProviderConstants.AUTHORIZABLE_SPLITTER; +import static org.apache.sentry.provider.common.ProviderConstants.PRIVILEGE_PREFIX; import java.util.List; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-policy/sentry-policy-indexer/src/main/java/org/apache/sentry/policy/indexer/IndexerModelAuthorizables.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-indexer/src/main/java/org/apache/sentry/policy/indexer/IndexerModelAuthorizables.java b/sentry-policy/sentry-policy-indexer/src/main/java/org/apache/sentry/policy/indexer/IndexerModelAuthorizables.java index 7657327..e561962 100644 --- a/sentry-policy/sentry-policy-indexer/src/main/java/org/apache/sentry/policy/indexer/IndexerModelAuthorizables.java +++ b/sentry-policy/sentry-policy-indexer/src/main/java/org/apache/sentry/policy/indexer/IndexerModelAuthorizables.java @@ -19,7 +19,7 @@ package org.apache.sentry.policy.indexer; import org.apache.sentry.core.model.indexer.Indexer; import org.apache.sentry.core.model.indexer.IndexerModelAuthorizable; import org.apache.sentry.core.model.indexer.IndexerModelAuthorizable.AuthorizableType; -import org.apache.sentry.provider.file.KeyValue; +import org.apache.sentry.provider.common.KeyValue; public class IndexerModelAuthorizables { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-policy/sentry-policy-indexer/src/main/java/org/apache/sentry/policy/indexer/IndexerWildcardPrivilege.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-indexer/src/main/java/org/apache/sentry/policy/indexer/IndexerWildcardPrivilege.java b/sentry-policy/sentry-policy-indexer/src/main/java/org/apache/sentry/policy/indexer/IndexerWildcardPrivilege.java index 5ab1382..ab6b27f 100644 --- a/sentry-policy/sentry-policy-indexer/src/main/java/org/apache/sentry/policy/indexer/IndexerWildcardPrivilege.java +++ b/sentry-policy/sentry-policy-indexer/src/main/java/org/apache/sentry/policy/indexer/IndexerWildcardPrivilege.java @@ -21,16 +21,13 @@ package org.apache.sentry.policy.indexer; -import static org.apache.sentry.provider.file.PolicyFileConstants.AUTHORIZABLE_JOINER; -import static org.apache.sentry.provider.file.PolicyFileConstants.AUTHORIZABLE_SPLITTER; - import java.util.List; import org.apache.sentry.core.model.indexer.IndexerConstants; import org.apache.sentry.policy.common.Privilege; import org.apache.sentry.policy.common.PrivilegeFactory; -import org.apache.sentry.provider.file.KeyValue; -import org.apache.sentry.provider.file.PolicyFileConstants; +import org.apache.sentry.provider.common.KeyValue; +import org.apache.sentry.provider.common.ProviderConstants; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -47,7 +44,8 @@ public class IndexerWildcardPrivilege implements Privilege { throw new IllegalArgumentException("Wildcard string cannot be null or empty."); } List<KeyValue>parts = Lists.newArrayList(); - for (String authorizable : AUTHORIZABLE_SPLITTER.trimResults().split(wildcardString)) { + for (String authorizable : ProviderConstants.AUTHORIZABLE_SPLITTER.trimResults().split( + wildcardString)) { if (authorizable.isEmpty()) { throw new IllegalArgumentException("Privilege '" + wildcardString + "' has an empty section"); } @@ -110,7 +108,7 @@ public class IndexerWildcardPrivilege implements Privilege { "Please report, this method should not be called with two different keys"); if(policyPart.getValue().equals(IndexerConstants.ALL) || policyPart.equals(requestPart)) { return true; - } else if (!PolicyFileConstants.PRIVILEGE_NAME.equalsIgnoreCase(policyPart.getKey()) + } else if (!ProviderConstants.PRIVILEGE_NAME.equalsIgnoreCase(policyPart.getKey()) && IndexerConstants.ALL.equalsIgnoreCase(requestPart.getValue())) { /* privilege request is to match with any object of given type */ return true; @@ -120,7 +118,7 @@ public class IndexerWildcardPrivilege implements Privilege { @Override public String toString() { - return AUTHORIZABLE_JOINER.join(parts); + return ProviderConstants.AUTHORIZABLE_JOINER.join(parts); } @Override http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerWildcardPrivilege.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerWildcardPrivilege.java b/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerWildcardPrivilege.java index 48c5b07..5348f95 100644 --- a/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerWildcardPrivilege.java +++ b/sentry-policy/sentry-policy-indexer/src/test/java/org/apache/sentry/policy/indexer/TestIndexerWildcardPrivilege.java @@ -19,13 +19,13 @@ package org.apache.sentry.policy.indexer; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; -import static org.apache.sentry.provider.file.PolicyFileConstants.AUTHORIZABLE_JOINER; -import static org.apache.sentry.provider.file.PolicyFileConstants.KV_JOINER; -import static org.apache.sentry.provider.file.PolicyFileConstants.KV_SEPARATOR; +import static org.apache.sentry.provider.common.ProviderConstants.AUTHORIZABLE_JOINER; +import static org.apache.sentry.provider.common.ProviderConstants.KV_JOINER; +import static org.apache.sentry.provider.common.ProviderConstants.KV_SEPARATOR; import org.apache.sentry.core.model.indexer.IndexerConstants; import org.apache.sentry.policy.common.Privilege; -import org.apache.sentry.provider.file.KeyValue; +import org.apache.sentry.provider.common.KeyValue; import org.junit.Test; public class TestIndexerWildcardPrivilege { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-policy/sentry-policy-search/src/main/java/org/apache/sentry/policy/search/AbstractSearchPrivilegeValidator.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-search/src/main/java/org/apache/sentry/policy/search/AbstractSearchPrivilegeValidator.java b/sentry-policy/sentry-policy-search/src/main/java/org/apache/sentry/policy/search/AbstractSearchPrivilegeValidator.java index a4e611c..781e722 100644 --- a/sentry-policy/sentry-policy-search/src/main/java/org/apache/sentry/policy/search/AbstractSearchPrivilegeValidator.java +++ b/sentry-policy/sentry-policy-search/src/main/java/org/apache/sentry/policy/search/AbstractSearchPrivilegeValidator.java @@ -16,8 +16,8 @@ */ package org.apache.sentry.policy.search; -import static org.apache.sentry.provider.file.PolicyFileConstants.AUTHORIZABLE_SPLITTER; -import static org.apache.sentry.provider.file.PolicyFileConstants.PRIVILEGE_PREFIX; +import static org.apache.sentry.provider.common.ProviderConstants.AUTHORIZABLE_SPLITTER; +import static org.apache.sentry.provider.common.ProviderConstants.PRIVILEGE_PREFIX; import java.util.List; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-policy/sentry-policy-search/src/main/java/org/apache/sentry/policy/search/SearchModelAuthorizables.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-search/src/main/java/org/apache/sentry/policy/search/SearchModelAuthorizables.java b/sentry-policy/sentry-policy-search/src/main/java/org/apache/sentry/policy/search/SearchModelAuthorizables.java index 6551485..dcf17a2 100644 --- a/sentry-policy/sentry-policy-search/src/main/java/org/apache/sentry/policy/search/SearchModelAuthorizables.java +++ b/sentry-policy/sentry-policy-search/src/main/java/org/apache/sentry/policy/search/SearchModelAuthorizables.java @@ -19,7 +19,7 @@ package org.apache.sentry.policy.search; import org.apache.sentry.core.model.search.Collection; import org.apache.sentry.core.model.search.SearchModelAuthorizable; import org.apache.sentry.core.model.search.SearchModelAuthorizable.AuthorizableType; -import org.apache.sentry.provider.file.KeyValue; +import org.apache.sentry.provider.common.KeyValue; public class SearchModelAuthorizables { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-policy/sentry-policy-search/src/main/java/org/apache/sentry/policy/search/SearchWildcardPrivilege.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-search/src/main/java/org/apache/sentry/policy/search/SearchWildcardPrivilege.java b/sentry-policy/sentry-policy-search/src/main/java/org/apache/sentry/policy/search/SearchWildcardPrivilege.java index 9a33fcf..c522412 100644 --- a/sentry-policy/sentry-policy-search/src/main/java/org/apache/sentry/policy/search/SearchWildcardPrivilege.java +++ b/sentry-policy/sentry-policy-search/src/main/java/org/apache/sentry/policy/search/SearchWildcardPrivilege.java @@ -21,16 +21,13 @@ package org.apache.sentry.policy.search; -import static org.apache.sentry.provider.file.PolicyFileConstants.AUTHORIZABLE_JOINER; -import static org.apache.sentry.provider.file.PolicyFileConstants.AUTHORIZABLE_SPLITTER; - import java.util.List; import org.apache.sentry.core.model.search.SearchConstants; import org.apache.sentry.policy.common.Privilege; import org.apache.sentry.policy.common.PrivilegeFactory; -import org.apache.sentry.provider.file.KeyValue; -import org.apache.sentry.provider.file.PolicyFileConstants; +import org.apache.sentry.provider.common.KeyValue; +import org.apache.sentry.provider.common.ProviderConstants; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -47,7 +44,8 @@ public class SearchWildcardPrivilege implements Privilege { throw new IllegalArgumentException("Wildcard string cannot be null or empty."); } List<KeyValue>parts = Lists.newArrayList(); - for (String authorizable : AUTHORIZABLE_SPLITTER.trimResults().split(wildcardString)) { + for (String authorizable : ProviderConstants.AUTHORIZABLE_SPLITTER.trimResults().split( + wildcardString)) { if (authorizable.isEmpty()) { throw new IllegalArgumentException("Privilege '" + wildcardString + "' has an empty section"); } @@ -110,7 +108,7 @@ public class SearchWildcardPrivilege implements Privilege { "Please report, this method should not be called with two different keys"); if(policyPart.getValue().equals(SearchConstants.ALL) || policyPart.equals(requestPart)) { return true; - } else if (!PolicyFileConstants.PRIVILEGE_NAME.equalsIgnoreCase(policyPart.getKey()) + } else if (!ProviderConstants.PRIVILEGE_NAME.equalsIgnoreCase(policyPart.getKey()) && SearchConstants.ALL.equalsIgnoreCase(requestPart.getValue())) { /* privilege request is to match with any object of given type */ return true; @@ -120,7 +118,7 @@ public class SearchWildcardPrivilege implements Privilege { @Override public String toString() { - return AUTHORIZABLE_JOINER.join(parts); + return ProviderConstants.AUTHORIZABLE_JOINER.join(parts); } @Override http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-policy/sentry-policy-search/src/test/java/org/apache/sentry/policy/search/TestSearchWildcardPrivilege.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-search/src/test/java/org/apache/sentry/policy/search/TestSearchWildcardPrivilege.java b/sentry-policy/sentry-policy-search/src/test/java/org/apache/sentry/policy/search/TestSearchWildcardPrivilege.java index cb5531f..125f358 100644 --- a/sentry-policy/sentry-policy-search/src/test/java/org/apache/sentry/policy/search/TestSearchWildcardPrivilege.java +++ b/sentry-policy/sentry-policy-search/src/test/java/org/apache/sentry/policy/search/TestSearchWildcardPrivilege.java @@ -19,13 +19,13 @@ package org.apache.sentry.policy.search; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; -import static org.apache.sentry.provider.file.PolicyFileConstants.AUTHORIZABLE_JOINER; -import static org.apache.sentry.provider.file.PolicyFileConstants.KV_JOINER; -import static org.apache.sentry.provider.file.PolicyFileConstants.KV_SEPARATOR; +import static org.apache.sentry.provider.common.ProviderConstants.AUTHORIZABLE_JOINER; +import static org.apache.sentry.provider.common.ProviderConstants.KV_JOINER; +import static org.apache.sentry.provider.common.ProviderConstants.KV_SEPARATOR; import org.apache.sentry.core.model.search.SearchConstants; import org.apache.sentry.policy.common.Privilege; -import org.apache.sentry.provider.file.KeyValue; +import org.apache.sentry.provider.common.KeyValue; import org.junit.Test; public class TestSearchWildcardPrivilege { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-policy/sentry-policy-sqoop/src/main/java/org/apache/sentry/policy/sqoop/SqoopModelAuthorizables.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-sqoop/src/main/java/org/apache/sentry/policy/sqoop/SqoopModelAuthorizables.java b/sentry-policy/sentry-policy-sqoop/src/main/java/org/apache/sentry/policy/sqoop/SqoopModelAuthorizables.java index fa937fa..223fb55 100644 --- a/sentry-policy/sentry-policy-sqoop/src/main/java/org/apache/sentry/policy/sqoop/SqoopModelAuthorizables.java +++ b/sentry-policy/sentry-policy-sqoop/src/main/java/org/apache/sentry/policy/sqoop/SqoopModelAuthorizables.java @@ -21,8 +21,8 @@ import org.apache.sentry.core.model.sqoop.Job; import org.apache.sentry.core.model.sqoop.Link; import org.apache.sentry.core.model.sqoop.Server; import org.apache.sentry.core.model.sqoop.SqoopAuthorizable; -import org.apache.sentry.provider.file.KeyValue; import org.apache.sentry.core.model.sqoop.SqoopAuthorizable.AuthorizableType; +import org.apache.sentry.provider.common.KeyValue; public class SqoopModelAuthorizables { public static SqoopAuthorizable from(KeyValue keyValue) { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-policy/sentry-policy-sqoop/src/main/java/org/apache/sentry/policy/sqoop/SqoopWildcardPrivilege.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-sqoop/src/main/java/org/apache/sentry/policy/sqoop/SqoopWildcardPrivilege.java b/sentry-policy/sentry-policy-sqoop/src/main/java/org/apache/sentry/policy/sqoop/SqoopWildcardPrivilege.java index da49102..139cf7f 100644 --- a/sentry-policy/sentry-policy-sqoop/src/main/java/org/apache/sentry/policy/sqoop/SqoopWildcardPrivilege.java +++ b/sentry-policy/sentry-policy-sqoop/src/main/java/org/apache/sentry/policy/sqoop/SqoopWildcardPrivilege.java @@ -23,7 +23,7 @@ import java.util.List; import org.apache.sentry.core.model.sqoop.SqoopActionConstant; import org.apache.sentry.policy.common.Privilege; import org.apache.sentry.policy.common.PrivilegeFactory; -import org.apache.sentry.provider.file.KeyValue; +import org.apache.sentry.provider.common.KeyValue; import com.google.common.base.Preconditions; import com.google.common.base.Strings; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-policy/sentry-policy-sqoop/src/test/java/org/apache/sentry/policy/sqoop/TestSqoopWildcardPrivilege.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-sqoop/src/test/java/org/apache/sentry/policy/sqoop/TestSqoopWildcardPrivilege.java b/sentry-policy/sentry-policy-sqoop/src/test/java/org/apache/sentry/policy/sqoop/TestSqoopWildcardPrivilege.java index 92b3707..1f03f05 100644 --- a/sentry-policy/sentry-policy-sqoop/src/test/java/org/apache/sentry/policy/sqoop/TestSqoopWildcardPrivilege.java +++ b/sentry-policy/sentry-policy-sqoop/src/test/java/org/apache/sentry/policy/sqoop/TestSqoopWildcardPrivilege.java @@ -19,13 +19,13 @@ package org.apache.sentry.policy.sqoop; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; -import static org.apache.sentry.provider.file.PolicyFileConstants.AUTHORIZABLE_JOINER; -import static org.apache.sentry.provider.file.PolicyFileConstants.KV_JOINER; -import static org.apache.sentry.provider.file.PolicyFileConstants.KV_SEPARATOR; +import static org.apache.sentry.provider.common.ProviderConstants.AUTHORIZABLE_JOINER; +import static org.apache.sentry.provider.common.ProviderConstants.KV_JOINER; +import static org.apache.sentry.provider.common.ProviderConstants.KV_SEPARATOR; import org.apache.sentry.core.model.sqoop.SqoopActionConstant; import org.apache.sentry.policy.common.Privilege; -import org.apache.sentry.provider.file.KeyValue; +import org.apache.sentry.provider.common.KeyValue; import org.junit.Test; public class TestSqoopWildcardPrivilege { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/KeyValue.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/KeyValue.java b/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/KeyValue.java new file mode 100644 index 0000000..cad37b4 --- /dev/null +++ b/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/KeyValue.java @@ -0,0 +1,95 @@ +/* + * 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 static org.apache.sentry.provider.common.ProviderConstants.KV_JOINER; +import static org.apache.sentry.provider.common.ProviderConstants.KV_SPLITTER; + +import java.util.List; + +import com.google.common.collect.Lists; + +public class KeyValue { + private final String key; + private final String value; + + public KeyValue(String keyValue) { + List<String> kvList = Lists.newArrayList(KV_SPLITTER.trimResults().limit(2).split(keyValue)); + if (kvList.size() != 2) { + throw new IllegalArgumentException("Invalid key value: " + keyValue + " " + kvList); + } + key = kvList.get(0); + value = kvList.get(1); + if (key.isEmpty()) { + throw new IllegalArgumentException("Key cannot be empty"); + } else if (value.isEmpty()) { + throw new IllegalArgumentException("Value cannot be empty"); + } + } + + public KeyValue(String key, String value) { + super(); + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public String getValue() { + return value; + } + + @Override + public String toString() { + return KV_JOINER.join(key, value); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((key == null) ? 0 : key.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + KeyValue other = (KeyValue) obj; + if (key == null) { + if (other.key != null) + return false; + } else if (!key.equalsIgnoreCase(other.key)) + return false; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equalsIgnoreCase(other.value)) + return false; + return true; + } +} http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/PolicyFileConstants.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/PolicyFileConstants.java b/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/PolicyFileConstants.java new file mode 100644 index 0000000..dfe4fe0 --- /dev/null +++ b/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/PolicyFileConstants.java @@ -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. + */ +package org.apache.sentry.provider.common; + +public class PolicyFileConstants { + public static final String DATABASES = "databases"; + public static final String GROUPS = "groups"; + public static final String ROLES = "roles"; + public static final String USERS = "users"; + public static final String PRIVILEGE_SERVER_NAME = "server"; + public static final String PRIVILEGE_DATABASE_NAME = "db"; + public static final String PRIVILEGE_TABLE_NAME = "table"; + public static final String PRIVILEGE_COLUMN_NAME = "column"; + public static final String PRIVILEGE_URI_NAME = "uri"; + public static final String PRIVILEGE_ACTION_NAME = "action"; + public static final String PRIVILEGE_GRANT_OPTION_NAME = "grantoption"; +} http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-provider/sentry-provider-common/src/test/java/org/apache/sentry/provider/common/TestKeyValue.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-common/src/test/java/org/apache/sentry/provider/common/TestKeyValue.java b/sentry-provider/sentry-provider-common/src/test/java/org/apache/sentry/provider/common/TestKeyValue.java new file mode 100644 index 0000000..1ae4c0c --- /dev/null +++ b/sentry-provider/sentry-provider-common/src/test/java/org/apache/sentry/provider/common/TestKeyValue.java @@ -0,0 +1,76 @@ +/* + * 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 static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; +import static org.apache.sentry.provider.common.ProviderConstants.KV_JOINER; + +import org.junit.Test; + +public class TestKeyValue { + + @Test + public void testWithSeparators() throws Exception { + KeyValue kv = new KeyValue("URI=/u/h/w/t/partition=value/"); + assertEquals("URI", kv.getKey()); + assertEquals("/u/h/w/t/partition=value/", kv.getValue()); + } + + @Test(expected = IllegalArgumentException.class) + public void testEmptyKey() throws Exception { + new KeyValue(KV_JOINER.join("", "b")); + } + + @Test(expected = IllegalArgumentException.class) + public void testEmptyValue() throws Exception { + new KeyValue(KV_JOINER.join("a", "")); + } + + @Test + public void testOneParameterConstructor() throws Exception { + KeyValue kv1 = new KeyValue(KV_JOINER.join("k1", "v1")); + KeyValue kv2 = new KeyValue(KV_JOINER.join("k1", "v1")); + KeyValue kv3 = new KeyValue(KV_JOINER.join("k2", "v2")); + doTest(kv1, kv2, kv3); + } + + @Test + public void testTwoParameterConstructor() throws Exception { + KeyValue kv1 = new KeyValue("k1", "v1"); + KeyValue kv2 = new KeyValue("k1", "v1"); + KeyValue kv3 = new KeyValue("k2", "v2"); + doTest(kv1, kv2, kv3); + } + + private void doTest(KeyValue kv1, KeyValue kv2, KeyValue kv3) { + assertEquals(kv1, kv2); + assertFalse(kv1.equals(kv3)); + + assertEquals(kv1.toString(), kv2.toString()); + assertFalse(kv1.toString().equals(kv3.toString())); + + assertEquals(kv1.hashCode(), kv2.hashCode()); + assertFalse(kv1.hashCode() == kv3.hashCode()); + + assertEquals(kv1.getKey(), kv2.getKey()); + assertFalse(kv1.getKey().equals(kv3.getKey())); + + assertEquals(kv1.getValue(), kv2.getValue()); + assertFalse(kv1.getValue().equals(kv3.getValue())); + } +} http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/KeyValue.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/KeyValue.java b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/KeyValue.java deleted file mode 100644 index 8015561..0000000 --- a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/KeyValue.java +++ /dev/null @@ -1,89 +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.KV_JOINER; -import static org.apache.sentry.provider.file.PolicyFileConstants.KV_SPLITTER; - -import java.util.List; - -import com.google.common.collect.Lists; - -public class KeyValue { - private final String key; - private final String value; - - public KeyValue(String keyValue) { - List<String> kvList = Lists.newArrayList(KV_SPLITTER.trimResults().limit(2).split(keyValue)); - if(kvList.size() != 2) { - throw new IllegalArgumentException("Invalid key value: " + keyValue + " " + kvList); - } - key = kvList.get(0); - value = kvList.get(1); - if(key.isEmpty()) { - throw new IllegalArgumentException("Key cannot be empty"); - } else if(value.isEmpty()) { - throw new IllegalArgumentException("Value cannot be empty"); - } - } - public KeyValue(String key, String value) { - super(); - this.key = key; - this.value = value; - } - public String getKey() { - return key; - } - public String getValue() { - return value; - } - - @Override - public String toString() { - return KV_JOINER.join(key, value); - } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((key == null) ? 0 : key.hashCode()); - result = prime * result + ((value == null) ? 0 : value.hashCode()); - return result; - } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - KeyValue other = (KeyValue) obj; - if (key == null) { - if (other.key != null) - return false; - } else if (!key.equalsIgnoreCase(other.key)) - return false; - if (value == null) { - if (other.value != null) - return false; - } else if (!value.equalsIgnoreCase(other.value)) - return false; - return true; - } -} http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/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 9b146d9..e22e6b6 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 @@ -28,6 +28,8 @@ 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.sentry.provider.common.PolicyFileConstants; +import org.apache.sentry.provider.common.ProviderConstants; import org.apache.shiro.config.Ini; import org.apache.shiro.config.Ini.Section; import org.slf4j.Logger; @@ -109,8 +111,8 @@ public class LocalGroupMappingService implements GroupMappingService { " in the " + resourcePath); continue; } - Set<String> groupList = Sets.newHashSet( - PolicyFileConstants.ROLE_SPLITTER.trimResults().split(groupNames)); + Set<String> groupList = Sets.newHashSet(ProviderConstants.ROLE_SPLITTER.trimResults().split( + groupNames)); LOGGER.debug("Got user mapping: " + userName + ", Groups: " + groupNames); groupMap.put(userName, groupList); } http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFile.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFile.java b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFile.java index 32b2d72..835e732 100644 --- a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFile.java +++ b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFile.java @@ -17,10 +17,10 @@ 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.USERS; +import static org.apache.sentry.provider.common.PolicyFileConstants.DATABASES; +import static org.apache.sentry.provider.common.PolicyFileConstants.GROUPS; +import static org.apache.sentry.provider.common.PolicyFileConstants.ROLES; +import static org.apache.sentry.provider.common.PolicyFileConstants.USERS; import java.io.File; import java.util.Collection; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFileConstants.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFileConstants.java b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFileConstants.java deleted file mode 100644 index b2bc531..0000000 --- a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFileConstants.java +++ /dev/null @@ -1,28 +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.sentry.provider.common.ProviderConstants; - -public class PolicyFileConstants extends ProviderConstants { - - public static final String DATABASES = "databases"; - public static final String GROUPS = "groups"; - public static final String ROLES = "roles"; - public static final String USERS = "users"; - -} http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFiles.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFiles.java b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFiles.java index f303294..4e5d4b9 100644 --- a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFiles.java +++ b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFiles.java @@ -16,8 +16,13 @@ */ package org.apache.sentry.provider.file; -import com.google.common.io.ByteStreams; -import com.google.common.io.Resources; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; + import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; @@ -25,12 +30,8 @@ import org.apache.shiro.config.Ini; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; +import com.google.common.io.ByteStreams; +import com.google.common.io.Resources; public class PolicyFiles { @@ -40,7 +41,7 @@ public class PolicyFiles { public static void copyToDir(File dest, String... resources) throws FileNotFoundException, IOException { for(String resource : resources) { - LOGGER.info("Copying " + resource + " to " + dest); + LOGGER.debug("Copying " + resource + " to " + dest); Resources.copy(Resources.getResource(resource), new FileOutputStream(new File(dest, resource))); } } @@ -54,7 +55,7 @@ public class PolicyFiles { in.close(); out.hflush(); out.close(); - LOGGER.info("Copying " + resource + " to " + dest + ", bytes " + bytes); + LOGGER.debug("Copying " + resource + " to " + dest + ", bytes " + bytes); } } @@ -72,7 +73,7 @@ public class PolicyFiles { public static Ini loadFromPath(FileSystem fileSystem, Path path) throws IOException { InputStream inputStream = null; try { - LOGGER.info("Opening " + path); + LOGGER.debug("Opening " + path); String dfsUri = fileSystem.getDefaultUri(fileSystem.getConf()).toString(); inputStream = fileSystem.open(path); Ini ini = new Ini(); http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/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 index fa5ab69..526a0e0 100644 --- 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 @@ -16,19 +16,20 @@ */ package org.apache.sentry.provider.file; -import com.google.common.base.Splitter; -import com.google.common.base.Strings; -import com.google.common.collect.HashBasedTable; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Interner; -import com.google.common.collect.Interners; -import com.google.common.collect.Lists; -import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; -import com.google.common.collect.Table; -import com.google.common.collect.Table.Cell; +import static org.apache.sentry.provider.common.PolicyFileConstants.DATABASES; +import static org.apache.sentry.provider.common.PolicyFileConstants.GROUPS; +import static org.apache.sentry.provider.common.PolicyFileConstants.ROLES; +import static org.apache.sentry.provider.common.PolicyFileConstants.USERS; +import static org.apache.sentry.provider.common.ProviderConstants.ROLE_SPLITTER; + +import java.io.IOException; +import java.net.URI; +import java.util.HashSet; +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; @@ -45,20 +46,19 @@ import org.apache.shiro.config.Ini; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Nullable; - -import java.io.IOException; -import java.net.URI; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -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 com.google.common.base.Splitter; +import com.google.common.base.Strings; +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Interner; +import com.google.common.collect.Interners; +import com.google.common.collect.Lists; +import com.google.common.collect.Multimap; +import com.google.common.collect.Sets; +import com.google.common.collect.Table; +import com.google.common.collect.Table.Cell; public class SimpleFileProviderBackend implements ProviderBackend { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/67b2146e/sentry-provider/sentry-provider-file/src/test/java/org/apache/sentry/provider/file/TestKeyValue.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-file/src/test/java/org/apache/sentry/provider/file/TestKeyValue.java b/sentry-provider/sentry-provider-file/src/test/java/org/apache/sentry/provider/file/TestKeyValue.java deleted file mode 100644 index 4353a03..0000000 --- a/sentry-provider/sentry-provider-file/src/test/java/org/apache/sentry/provider/file/TestKeyValue.java +++ /dev/null @@ -1,76 +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 junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static org.apache.sentry.provider.file.PolicyFileConstants.KV_JOINER; - -import org.junit.Test; - -public class TestKeyValue { - - @Test - public void testWithSeparators() throws Exception { - KeyValue kv = new KeyValue("URI=/u/h/w/t/partition=value/"); - assertEquals("URI", kv.getKey()); - assertEquals("/u/h/w/t/partition=value/", kv.getValue()); - } - - @Test(expected=IllegalArgumentException.class) - public void testEmptyKey() throws Exception { - new KeyValue(KV_JOINER.join("", "b")); - } - - @Test(expected=IllegalArgumentException.class) - public void testEmptyValue() throws Exception { - new KeyValue(KV_JOINER.join("a", "")); - } - - @Test - public void testOneParameterConstructor() throws Exception { - KeyValue kv1 = new KeyValue(KV_JOINER.join("k1", "v1")); - KeyValue kv2 = new KeyValue(KV_JOINER.join("k1", "v1")); - KeyValue kv3 = new KeyValue(KV_JOINER.join("k2", "v2")); - doTest(kv1, kv2, kv3); - } - @Test - public void testTwoParameterConstructor() throws Exception { - KeyValue kv1 = new KeyValue("k1", "v1"); - KeyValue kv2 = new KeyValue("k1", "v1"); - KeyValue kv3 = new KeyValue("k2", "v2"); - doTest(kv1, kv2, kv3); - } - - private void doTest(KeyValue kv1, KeyValue kv2, KeyValue kv3) { - assertEquals(kv1, kv2); - assertFalse(kv1.equals(kv3)); - - assertEquals(kv1.toString(), kv2.toString()); - assertFalse(kv1.toString().equals(kv3.toString())); - - assertEquals(kv1.hashCode(), kv2.hashCode()); - assertFalse(kv1.hashCode() == kv3.hashCode()); - - assertEquals(kv1.getKey(), kv2.getKey()); - assertFalse(kv1.getKey().equals(kv3.getKey())); - - assertEquals(kv1.getValue(), kv2.getValue()); - assertFalse(kv1.getValue().equals(kv3.getValue())); - } -}
