Repository: incubator-sentry Updated Branches: refs/heads/SENTRY-999 041576221 -> 48c021a00
SENTRY-1092: Move Class KeyValue and PolicyConstants to sentry-core-common (Colin Ma, Reviewed by Daoebg 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/48c021a0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/48c021a0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/48c021a0 Branch: refs/heads/SENTRY-999 Commit: 48c021a0021e3c8e99030826d4e6792ed8f5a4a9 Parents: 0415762 Author: Colin Ma <[email protected]> Authored: Tue Feb 23 14:05:07 2016 +0800 Committer: Colin Ma <[email protected]> Committed: Tue Feb 23 14:05:07 2016 +0800 ---------------------------------------------------------------------- .../hive/SentryIniPolicyFileFormatter.java | 6 +- .../hive/TestSentryIniPolicyFileFormatter.java | 6 +- .../sentry/core/common/utils/KeyValue.java | 99 ++++++++++++++++++++ .../core/common/utils/SentryConstants.java | 40 ++++++++ .../sentry/core/common/utils/TestKeyValue.java | 74 +++++++++++++++ .../sentry/policy/common/CommonPrivilege.java | 13 ++- .../apache/sentry/policy/common/KeyValue.java | 99 -------------------- .../sentry/policy/common/PolicyConstants.java | 40 -------- .../policy/common/TestCommonPrivilege.java | 1 + .../sentry/policy/common/TestKeyValue.java | 74 --------------- .../policy/db/AbstractDBPrivilegeValidator.java | 4 +- .../sentry/policy/db/DBModelAuthorizables.java | 2 +- .../sentry/policy/db/DBWildcardPrivilege.java | 12 +-- .../policy/db/TestDBWildcardPrivilege.java | 8 +- .../AbstractIndexerPrivilegeValidator.java | 4 +- .../indexer/IndexerModelAuthorizables.java | 2 +- .../indexer/IndexerWildcardPrivilege.java | 10 +- .../indexer/TestIndexerWildcardPrivilege.java | 8 +- .../AbstractSearchPrivilegeValidator.java | 4 +- .../policy/search/SearchModelAuthorizables.java | 2 +- .../policy/search/SearchWildcardPrivilege.java | 10 +- .../search/TestSearchWildcardPrivilege.java | 8 +- .../policy/sqoop/ServerNameRequiredMatch.java | 4 +- .../policy/sqoop/SqoopModelAuthorizables.java | 2 +- .../policy/sqoop/SqoopWildcardPrivilege.java | 4 +- .../sqoop/TestSqoopWildcardPrivilege.java | 8 +- .../common/ResourceAuthorizationProvider.java | 8 +- .../service/persistent/PrivilegeObject.java | 4 +- .../thrift/SentryGenericPolicyProcessor.java | 14 +-- .../tools/SolrTSentryPrivilegeConvertor.java | 14 +-- .../db/service/model/MSentryGMPrivilege.java | 4 +- .../db/service/persistent/SentryStore.java | 8 +- .../db/tools/command/hive/CommandUtil.java | 6 +- .../tools/command/hive/ListPrivilegesCmd.java | 18 ++-- .../service/thrift/SentryServiceUtil.java | 22 ++--- .../thrift/TestSentryServiceImportExport.java | 6 +- .../provider/file/LocalGroupMappingService.java | 4 +- .../file/SimpleFileProviderBackend.java | 2 +- .../AbstractTestWithStaticConfiguration.java | 6 +- .../tests/e2e/hive/TestPolicyImportExport.java | 6 +- .../metastore/SentryPolicyProviderForDb.java | 6 +- 41 files changed, 338 insertions(+), 334 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryIniPolicyFileFormatter.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryIniPolicyFileFormatter.java b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryIniPolicyFileFormatter.java index 45747df..822bf9e 100644 --- a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryIniPolicyFileFormatter.java +++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryIniPolicyFileFormatter.java @@ -24,7 +24,7 @@ import java.util.Map; import java.util.Set; import org.apache.hadoop.conf.Configuration; -import org.apache.sentry.policy.common.PolicyConstants; +import org.apache.sentry.core.common.utils.SentryConstants; import org.apache.sentry.provider.common.PolicyFileConstants; import org.apache.sentry.provider.common.ProviderBackendContext; import org.apache.sentry.provider.file.SimpleFileProviderBackend; @@ -152,8 +152,8 @@ public class SentryIniPolicyFileFormatter implements SentryPolicyFileFormatter { List<String> lines = Lists.newArrayList(); lines.add("[" + name + "]"); for (Map.Entry<String, Set<String>> entry : mappingData.entrySet()) { - lines.add(PolicyConstants.KV_JOINER.join(entry.getKey(), - PolicyConstants.ROLE_JOINER.join(entry.getValue()))); + lines.add(SentryConstants.KV_JOINER.join(entry.getKey(), + SentryConstants.ROLE_JOINER.join(entry.getValue()))); } return Joiner.on(NL).join(lines); } http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestSentryIniPolicyFileFormatter.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestSentryIniPolicyFileFormatter.java b/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestSentryIniPolicyFileFormatter.java index f61dd0c..f17d47a 100644 --- a/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestSentryIniPolicyFileFormatter.java +++ b/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestSentryIniPolicyFileFormatter.java @@ -25,7 +25,7 @@ import java.util.Map; import java.util.Set; import org.apache.sentry.binding.hive.conf.HiveAuthzConf; -import org.apache.sentry.policy.common.PolicyConstants; +import org.apache.sentry.core.common.utils.SentryConstants; import org.apache.sentry.provider.common.PolicyFileConstants; import org.junit.Test; @@ -208,8 +208,8 @@ public class TestSentryIniPolicyFileFormatter { for (String actualPrivilege : actualPrivileges) { boolean isFound = exceptedPrivileges.contains(actualPrivilege); if (!isFound) { - String withOptionPrivilege = PolicyConstants.AUTHORIZABLE_JOINER.join(actualPrivilege, - PolicyConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_GRANT_OPTION_NAME, + String withOptionPrivilege = SentryConstants.AUTHORIZABLE_JOINER.join(actualPrivilege, + SentryConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_GRANT_OPTION_NAME, "false")); isFound = exceptedPrivileges.contains(withOptionPrivilege); } http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/KeyValue.java ---------------------------------------------------------------------- diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/KeyValue.java b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/KeyValue.java new file mode 100644 index 0000000..079629e --- /dev/null +++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/KeyValue.java @@ -0,0 +1,99 @@ +/* + * 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.core.common.utils; + +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(SentryConstants.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 SentryConstants.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/48c021a0/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/SentryConstants.java ---------------------------------------------------------------------- diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/SentryConstants.java b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/SentryConstants.java new file mode 100644 index 0000000..28ba8d3 --- /dev/null +++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/SentryConstants.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sentry.core.common.utils; + +import com.google.common.base.Joiner; +import com.google.common.base.Splitter; + +public class SentryConstants { + + public static final String ROLE_SEPARATOR = ","; + public static final String AUTHORIZABLE_SEPARATOR = "->"; + public static final String KV_SEPARATOR = "="; + + public static final Splitter ROLE_SPLITTER = Splitter.on(ROLE_SEPARATOR); + public static final Splitter AUTHORIZABLE_SPLITTER = Splitter.on(AUTHORIZABLE_SEPARATOR); + public static final Splitter KV_SPLITTER = Splitter.on(KV_SEPARATOR); + public static final Joiner ROLE_JOINER = Joiner.on(ROLE_SEPARATOR); + public static final Joiner AUTHORIZABLE_JOINER = Joiner.on(AUTHORIZABLE_SEPARATOR); + public static final Joiner KV_JOINER = Joiner.on(KV_SEPARATOR); + + public static final String PRIVILEGE_NAME = "action"; + public static final String PRIVILEGE_PREFIX = (PRIVILEGE_NAME + KV_SEPARATOR).toLowerCase(); + public static final String PRIVILEGE_WILDCARD_VALUE = "*"; + + public static final String RESOURCE_WILDCARD_VALUE = "*"; +} http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-core/sentry-core-common/src/test/java/org/apache/sentry/core/common/utils/TestKeyValue.java ---------------------------------------------------------------------- diff --git a/sentry-core/sentry-core-common/src/test/java/org/apache/sentry/core/common/utils/TestKeyValue.java b/sentry-core/sentry-core-common/src/test/java/org/apache/sentry/core/common/utils/TestKeyValue.java new file mode 100644 index 0000000..ca44a24 --- /dev/null +++ b/sentry-core/sentry-core-common/src/test/java/org/apache/sentry/core/common/utils/TestKeyValue.java @@ -0,0 +1,74 @@ +/* + * 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.core.common.utils; + +import static org.apache.sentry.core.common.utils.SentryConstants.KV_JOINER; +import junit.framework.Assert; +import org.junit.Test; + +public class TestKeyValue { + + @Test + public void testWithSeparators() throws Exception { + KeyValue kv = new KeyValue("URI=/u/h/w/t/partition=value/"); + Assert.assertEquals("URI", kv.getKey()); + Assert.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) { + Assert.assertEquals(kv1, kv2); + Assert.assertFalse(kv1.equals(kv3)); + + Assert.assertEquals(kv1.toString(), kv2.toString()); + Assert.assertFalse(kv1.toString().equals(kv3.toString())); + + Assert.assertEquals(kv1.hashCode(), kv2.hashCode()); + Assert.assertFalse(kv1.hashCode() == kv3.hashCode()); + + Assert.assertEquals(kv1.getKey(), kv2.getKey()); + Assert.assertFalse(kv1.getKey().equals(kv3.getKey())); + + Assert.assertEquals(kv1.getValue(), kv2.getValue()); + Assert.assertFalse(kv1.getValue().equals(kv3.getValue())); + } +} http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-policy/sentry-policy-common/src/main/java/org/apache/sentry/policy/common/CommonPrivilege.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-common/src/main/java/org/apache/sentry/policy/common/CommonPrivilege.java b/sentry-policy/sentry-policy-common/src/main/java/org/apache/sentry/policy/common/CommonPrivilege.java index 91fb5df..8583448 100644 --- a/sentry-policy/sentry-policy-common/src/main/java/org/apache/sentry/policy/common/CommonPrivilege.java +++ b/sentry-policy/sentry-policy-common/src/main/java/org/apache/sentry/policy/common/CommonPrivilege.java @@ -23,7 +23,10 @@ import org.apache.sentry.core.common.BitFieldAction; import org.apache.sentry.core.common.BitFieldActionFactory; import org.apache.sentry.core.common.ImplyMethodType; import org.apache.sentry.core.common.Model; +import org.apache.sentry.core.common.utils.KeyValue; import org.apache.sentry.core.common.utils.PathUtils; +import org.apache.sentry.core.common.utils.SentryConstants; + import java.util.List; // The class is used to compare the privilege @@ -37,7 +40,7 @@ public class CommonPrivilege implements Privilege { throw new IllegalArgumentException("Privilege string cannot be null or empty."); } List<KeyValue> parts = Lists.newArrayList(); - for (String authorizable : PolicyConstants.AUTHORIZABLE_SPLITTER.trimResults().split( + for (String authorizable : SentryConstants.AUTHORIZABLE_SPLITTER.trimResults().split( privilegeStr)) { if (authorizable.isEmpty()) { throw new IllegalArgumentException("Privilege '" + privilegeStr + "' has an empty section"); @@ -77,7 +80,7 @@ public class CommonPrivilege implements Privilege { } // do the imply for action - if (PolicyConstants.PRIVILEGE_NAME.equalsIgnoreCase(policyKey)) { + if (SentryConstants.PRIVILEGE_NAME.equalsIgnoreCase(policyKey)) { if (!impliesAction(part.getValue(), otherPart.getValue(), model.getBitFieldActionFactory())) { return false; } @@ -95,7 +98,7 @@ public class CommonPrivilege implements Privilege { // all of the other parts are wildcards for (; index < parts.size(); index++) { KeyValue part = parts.get(index); - if (!PolicyConstants.PRIVILEGE_WILDCARD_VALUE.equals(part.getValue())) { + if (!SentryConstants.PRIVILEGE_WILDCARD_VALUE.equals(part.getValue())) { return false; } } @@ -130,7 +133,7 @@ public class CommonPrivilege implements Privilege { } private boolean impliesStringWithWildcard(String policyValue, String requestValue) { - if (PolicyConstants.RESOURCE_WILDCARD_VALUE.equals(policyValue)) { + if (SentryConstants.RESOURCE_WILDCARD_VALUE.equals(policyValue)) { return true; } return policyValue.equals(requestValue); @@ -139,7 +142,7 @@ public class CommonPrivilege implements Privilege { @Override public String toString() { - return PolicyConstants.AUTHORIZABLE_JOINER.join(parts); + return SentryConstants.AUTHORIZABLE_JOINER.join(parts); } public boolean implies(Privilege p) { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-policy/sentry-policy-common/src/main/java/org/apache/sentry/policy/common/KeyValue.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-common/src/main/java/org/apache/sentry/policy/common/KeyValue.java b/sentry-policy/sentry-policy-common/src/main/java/org/apache/sentry/policy/common/KeyValue.java deleted file mode 100644 index 77e5fdf..0000000 --- a/sentry-policy/sentry-policy-common/src/main/java/org/apache/sentry/policy/common/KeyValue.java +++ /dev/null @@ -1,99 +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.policy.common; - -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(PolicyConstants.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 PolicyConstants.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/48c021a0/sentry-policy/sentry-policy-common/src/main/java/org/apache/sentry/policy/common/PolicyConstants.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-common/src/main/java/org/apache/sentry/policy/common/PolicyConstants.java b/sentry-policy/sentry-policy-common/src/main/java/org/apache/sentry/policy/common/PolicyConstants.java deleted file mode 100644 index 5182197..0000000 --- a/sentry-policy/sentry-policy-common/src/main/java/org/apache/sentry/policy/common/PolicyConstants.java +++ /dev/null @@ -1,40 +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.policy.common; - -import com.google.common.base.Joiner; -import com.google.common.base.Splitter; - -public class PolicyConstants { - - public static final String ROLE_SEPARATOR = ","; - public static final String AUTHORIZABLE_SEPARATOR = "->"; - public static final String KV_SEPARATOR = "="; - - public static final Splitter ROLE_SPLITTER = Splitter.on(ROLE_SEPARATOR); - public static final Splitter AUTHORIZABLE_SPLITTER = Splitter.on(AUTHORIZABLE_SEPARATOR); - public static final Splitter KV_SPLITTER = Splitter.on(KV_SEPARATOR); - public static final Joiner ROLE_JOINER = Joiner.on(ROLE_SEPARATOR); - public static final Joiner AUTHORIZABLE_JOINER = Joiner.on(AUTHORIZABLE_SEPARATOR); - public static final Joiner KV_JOINER = Joiner.on(KV_SEPARATOR); - - public static final String PRIVILEGE_NAME = "action"; - public static final String PRIVILEGE_PREFIX = (PRIVILEGE_NAME + KV_SEPARATOR).toLowerCase(); - public static final String PRIVILEGE_WILDCARD_VALUE = "*"; - - public static final String RESOURCE_WILDCARD_VALUE = "*"; -} http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-policy/sentry-policy-common/src/test/java/org/apache/sentry/policy/common/TestCommonPrivilege.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-common/src/test/java/org/apache/sentry/policy/common/TestCommonPrivilege.java b/sentry-policy/sentry-policy-common/src/test/java/org/apache/sentry/policy/common/TestCommonPrivilege.java index d74c88f..abaf61f 100644 --- a/sentry-policy/sentry-policy-common/src/test/java/org/apache/sentry/policy/common/TestCommonPrivilege.java +++ b/sentry-policy/sentry-policy-common/src/test/java/org/apache/sentry/policy/common/TestCommonPrivilege.java @@ -17,6 +17,7 @@ package org.apache.sentry.policy.common; import org.apache.sentry.core.common.Model; +import org.apache.sentry.core.common.utils.KeyValue; import org.junit.Before; import org.junit.Test; import java.util.List; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-policy/sentry-policy-common/src/test/java/org/apache/sentry/policy/common/TestKeyValue.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-common/src/test/java/org/apache/sentry/policy/common/TestKeyValue.java b/sentry-policy/sentry-policy-common/src/test/java/org/apache/sentry/policy/common/TestKeyValue.java deleted file mode 100644 index 7686ea1..0000000 --- a/sentry-policy/sentry-policy-common/src/test/java/org/apache/sentry/policy/common/TestKeyValue.java +++ /dev/null @@ -1,74 +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.policy.common; - -import static org.apache.sentry.policy.common.PolicyConstants.KV_JOINER; -import junit.framework.Assert; -import org.junit.Test; - -public class TestKeyValue { - - @Test - public void testWithSeparators() throws Exception { - KeyValue kv = new KeyValue("URI=/u/h/w/t/partition=value/"); - Assert.assertEquals("URI", kv.getKey()); - Assert.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) { - Assert.assertEquals(kv1, kv2); - Assert.assertFalse(kv1.equals(kv3)); - - Assert.assertEquals(kv1.toString(), kv2.toString()); - Assert.assertFalse(kv1.toString().equals(kv3.toString())); - - Assert.assertEquals(kv1.hashCode(), kv2.hashCode()); - Assert.assertFalse(kv1.hashCode() == kv3.hashCode()); - - Assert.assertEquals(kv1.getKey(), kv2.getKey()); - Assert.assertFalse(kv1.getKey().equals(kv3.getKey())); - - Assert.assertEquals(kv1.getValue(), kv2.getValue()); - Assert.assertFalse(kv1.getValue().equals(kv3.getValue())); - } -} http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/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 8bd311a..a85f54e 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.policy.common.PolicyConstants.AUTHORIZABLE_SPLITTER; -import static org.apache.sentry.policy.common.PolicyConstants.PRIVILEGE_PREFIX; +import static org.apache.sentry.core.common.utils.SentryConstants.AUTHORIZABLE_SPLITTER; +import static org.apache.sentry.core.common.utils.SentryConstants.PRIVILEGE_PREFIX; import java.util.List; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/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 96b172d..ca1ca9d 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.policy.common.KeyValue; +import org.apache.sentry.core.common.utils.KeyValue; public class DBModelAuthorizables { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/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 116e0aa..69e9ad2 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 @@ -24,12 +24,12 @@ package org.apache.sentry.policy.db; import java.util.List; import org.apache.sentry.core.common.utils.PathUtils; +import org.apache.sentry.core.common.utils.SentryConstants; import org.apache.sentry.core.model.db.AccessConstants; import org.apache.sentry.core.model.db.DBModelAuthorizable.AuthorizableType; -import org.apache.sentry.policy.common.PolicyConstants; import org.apache.sentry.policy.common.Privilege; import org.apache.sentry.policy.common.PrivilegeFactory; -import org.apache.sentry.policy.common.KeyValue; +import org.apache.sentry.core.common.utils.KeyValue; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; @@ -48,7 +48,7 @@ public class DBWildcardPrivilege implements Privilege { throw new IllegalArgumentException("Wildcard string cannot be null or empty."); } List<KeyValue>parts = Lists.newArrayList(); - for (String authorizable : PolicyConstants.AUTHORIZABLE_SPLITTER.trimResults().split( + for (String authorizable : SentryConstants.AUTHORIZABLE_SPLITTER.trimResults().split( wildcardString)) { if (authorizable.isEmpty()) { throw new IllegalArgumentException("Privilege '" + wildcardString + "' has an empty section"); @@ -117,11 +117,11 @@ public class DBWildcardPrivilege implements Privilege { if(policyPart.getValue().equals(AccessConstants.ALL) || policyPart.getValue().equalsIgnoreCase("ALL")) { return true; - } else if (!PolicyConstants.PRIVILEGE_NAME.equalsIgnoreCase(policyPart.getKey()) + } else if (!SentryConstants.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 (!PolicyConstants.PRIVILEGE_NAME.equalsIgnoreCase(policyPart.getKey()) + } else if (!SentryConstants.PRIVILEGE_NAME.equalsIgnoreCase(policyPart.getKey()) && AccessConstants.SOME.equalsIgnoreCase(requestPart.getValue())) { /* privilege request is to match with any object of given type */ return true; @@ -138,7 +138,7 @@ public class DBWildcardPrivilege implements Privilege { @Override public String toString() { - return PolicyConstants.AUTHORIZABLE_JOINER.join(parts); + return SentryConstants.AUTHORIZABLE_JOINER.join(parts); } @Override http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/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 9fcf853..343a45d 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.policy.common.PolicyConstants.AUTHORIZABLE_JOINER; -import static org.apache.sentry.policy.common.PolicyConstants.KV_JOINER; -import static org.apache.sentry.policy.common.PolicyConstants.KV_SEPARATOR; +import static org.apache.sentry.core.common.utils.SentryConstants.AUTHORIZABLE_JOINER; +import static org.apache.sentry.core.common.utils.SentryConstants.KV_JOINER; +import static org.apache.sentry.core.common.utils.SentryConstants.KV_SEPARATOR; import org.apache.sentry.core.model.db.AccessConstants; import org.apache.sentry.policy.common.Privilege; -import org.apache.sentry.policy.common.KeyValue; +import org.apache.sentry.core.common.utils.KeyValue; import org.junit.Test; public class TestDBWildcardPrivilege { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/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 a01824c..a2cd12c 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.policy.common.PolicyConstants.AUTHORIZABLE_SPLITTER; -import static org.apache.sentry.policy.common.PolicyConstants.PRIVILEGE_PREFIX; +import static org.apache.sentry.core.common.utils.SentryConstants.AUTHORIZABLE_SPLITTER; +import static org.apache.sentry.core.common.utils.SentryConstants.PRIVILEGE_PREFIX; import java.util.List; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/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 13893b3..dafa5c1 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.policy.common.KeyValue; +import org.apache.sentry.core.common.utils.KeyValue; public class IndexerModelAuthorizables { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/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 0ec0ce1..cda5d3d 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 @@ -23,11 +23,11 @@ package org.apache.sentry.policy.indexer; import java.util.List; +import org.apache.sentry.core.common.utils.SentryConstants; import org.apache.sentry.core.model.indexer.IndexerConstants; -import org.apache.sentry.policy.common.PolicyConstants; import org.apache.sentry.policy.common.Privilege; import org.apache.sentry.policy.common.PrivilegeFactory; -import org.apache.sentry.policy.common.KeyValue; +import org.apache.sentry.core.common.utils.KeyValue; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -44,7 +44,7 @@ public class IndexerWildcardPrivilege implements Privilege { throw new IllegalArgumentException("Wildcard string cannot be null or empty."); } List<KeyValue>parts = Lists.newArrayList(); - for (String authorizable : PolicyConstants.AUTHORIZABLE_SPLITTER.trimResults().split( + for (String authorizable : SentryConstants.AUTHORIZABLE_SPLITTER.trimResults().split( wildcardString)) { if (authorizable.isEmpty()) { throw new IllegalArgumentException("Privilege '" + wildcardString + "' has an empty section"); @@ -108,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 (!PolicyConstants.PRIVILEGE_NAME.equalsIgnoreCase(policyPart.getKey()) + } else if (!SentryConstants.PRIVILEGE_NAME.equalsIgnoreCase(policyPart.getKey()) && IndexerConstants.ALL.equalsIgnoreCase(requestPart.getValue())) { /* privilege request is to match with any object of given type */ return true; @@ -118,7 +118,7 @@ public class IndexerWildcardPrivilege implements Privilege { @Override public String toString() { - return PolicyConstants.AUTHORIZABLE_JOINER.join(parts); + return SentryConstants.AUTHORIZABLE_JOINER.join(parts); } @Override http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/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 b599a84..3ecde2d 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.policy.common.PolicyConstants.AUTHORIZABLE_JOINER; -import static org.apache.sentry.policy.common.PolicyConstants.KV_JOINER; -import static org.apache.sentry.policy.common.PolicyConstants.KV_SEPARATOR; +import static org.apache.sentry.core.common.utils.SentryConstants.AUTHORIZABLE_JOINER; +import static org.apache.sentry.core.common.utils.SentryConstants.KV_JOINER; +import static org.apache.sentry.core.common.utils.SentryConstants.KV_SEPARATOR; import org.apache.sentry.core.model.indexer.IndexerConstants; import org.apache.sentry.policy.common.Privilege; -import org.apache.sentry.policy.common.KeyValue; +import org.apache.sentry.core.common.utils.KeyValue; import org.junit.Test; public class TestIndexerWildcardPrivilege { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/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 054c354..f7efbb6 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.policy.common.PolicyConstants.AUTHORIZABLE_SPLITTER; -import static org.apache.sentry.policy.common.PolicyConstants.PRIVILEGE_PREFIX; +import static org.apache.sentry.core.common.utils.SentryConstants.AUTHORIZABLE_SPLITTER; +import static org.apache.sentry.core.common.utils.SentryConstants.PRIVILEGE_PREFIX; import java.util.List; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/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 252f50a..e09bc36 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.policy.common.KeyValue; +import org.apache.sentry.core.common.utils.KeyValue; public class SearchModelAuthorizables { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/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 e25faf2..8aeab04 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 @@ -23,11 +23,11 @@ package org.apache.sentry.policy.search; import java.util.List; +import org.apache.sentry.core.common.utils.SentryConstants; import org.apache.sentry.core.model.search.SearchConstants; -import org.apache.sentry.policy.common.PolicyConstants; import org.apache.sentry.policy.common.Privilege; import org.apache.sentry.policy.common.PrivilegeFactory; -import org.apache.sentry.policy.common.KeyValue; +import org.apache.sentry.core.common.utils.KeyValue; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -44,7 +44,7 @@ public class SearchWildcardPrivilege implements Privilege { throw new IllegalArgumentException("Wildcard string cannot be null or empty."); } List<KeyValue>parts = Lists.newArrayList(); - for (String authorizable : PolicyConstants.AUTHORIZABLE_SPLITTER.trimResults().split( + for (String authorizable : SentryConstants.AUTHORIZABLE_SPLITTER.trimResults().split( wildcardString)) { if (authorizable.isEmpty()) { throw new IllegalArgumentException("Privilege '" + wildcardString + "' has an empty section"); @@ -108,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 (!PolicyConstants.PRIVILEGE_NAME.equalsIgnoreCase(policyPart.getKey()) + } else if (!SentryConstants.PRIVILEGE_NAME.equalsIgnoreCase(policyPart.getKey()) && SearchConstants.ALL.equalsIgnoreCase(requestPart.getValue())) { /* privilege request is to match with any object of given type */ return true; @@ -118,7 +118,7 @@ public class SearchWildcardPrivilege implements Privilege { @Override public String toString() { - return PolicyConstants.AUTHORIZABLE_JOINER.join(parts); + return SentryConstants.AUTHORIZABLE_JOINER.join(parts); } @Override http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/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 a4c8a2b..688e3f8 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.policy.common.PolicyConstants.AUTHORIZABLE_JOINER; -import static org.apache.sentry.policy.common.PolicyConstants.KV_JOINER; -import static org.apache.sentry.policy.common.PolicyConstants.KV_SEPARATOR; +import static org.apache.sentry.core.common.utils.SentryConstants.AUTHORIZABLE_JOINER; +import static org.apache.sentry.core.common.utils.SentryConstants.KV_JOINER; +import static org.apache.sentry.core.common.utils.SentryConstants.KV_SEPARATOR; import org.apache.sentry.core.model.search.SearchConstants; import org.apache.sentry.policy.common.Privilege; -import org.apache.sentry.policy.common.KeyValue; +import org.apache.sentry.core.common.utils.KeyValue; import org.junit.Test; public class TestSearchWildcardPrivilege { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-policy/sentry-policy-sqoop/src/main/java/org/apache/sentry/policy/sqoop/ServerNameRequiredMatch.java ---------------------------------------------------------------------- diff --git a/sentry-policy/sentry-policy-sqoop/src/main/java/org/apache/sentry/policy/sqoop/ServerNameRequiredMatch.java b/sentry-policy/sentry-policy-sqoop/src/main/java/org/apache/sentry/policy/sqoop/ServerNameRequiredMatch.java index ef1c88b..ea6bc35 100644 --- a/sentry-policy/sentry-policy-sqoop/src/main/java/org/apache/sentry/policy/sqoop/ServerNameRequiredMatch.java +++ b/sentry-policy/sentry-policy-sqoop/src/main/java/org/apache/sentry/policy/sqoop/ServerNameRequiredMatch.java @@ -16,8 +16,8 @@ */ package org.apache.sentry.policy.sqoop; -import static org.apache.sentry.policy.common.PolicyConstants.AUTHORIZABLE_SPLITTER; -import static org.apache.sentry.policy.common.PolicyConstants.PRIVILEGE_PREFIX; +import static org.apache.sentry.core.common.utils.SentryConstants.AUTHORIZABLE_SPLITTER; +import static org.apache.sentry.core.common.utils.SentryConstants.PRIVILEGE_PREFIX; import java.util.List; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/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 b03b4dc..72f7b75 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 @@ -22,7 +22,7 @@ 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.core.model.sqoop.SqoopAuthorizable.AuthorizableType; -import org.apache.sentry.policy.common.KeyValue; +import org.apache.sentry.core.common.utils.KeyValue; public class SqoopModelAuthorizables { public static SqoopAuthorizable from(KeyValue keyValue) { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/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 ae89cf4..ae70943 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 @@ -16,14 +16,14 @@ */ package org.apache.sentry.policy.sqoop; -import static org.apache.sentry.policy.common.PolicyConstants.AUTHORIZABLE_SPLITTER; +import static org.apache.sentry.core.common.utils.SentryConstants.AUTHORIZABLE_SPLITTER; 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.policy.common.KeyValue; +import org.apache.sentry.core.common.utils.KeyValue; import com.google.common.base.Preconditions; import com.google.common.base.Strings; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/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 f19a1f8..8d27726 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.policy.common.PolicyConstants.AUTHORIZABLE_JOINER; -import static org.apache.sentry.policy.common.PolicyConstants.KV_JOINER; -import static org.apache.sentry.policy.common.PolicyConstants.KV_SEPARATOR; +import static org.apache.sentry.core.common.utils.SentryConstants.AUTHORIZABLE_JOINER; +import static org.apache.sentry.core.common.utils.SentryConstants.KV_JOINER; +import static org.apache.sentry.core.common.utils.SentryConstants.KV_SEPARATOR; import org.apache.sentry.core.model.sqoop.SqoopActionConstant; import org.apache.sentry.policy.common.Privilege; -import org.apache.sentry.policy.common.KeyValue; +import org.apache.sentry.core.common.utils.KeyValue; import org.junit.Test; public class TestSqoopWildcardPrivilege { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/ResourceAuthorizationProvider.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/ResourceAuthorizationProvider.java b/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/ResourceAuthorizationProvider.java index 0cf0b5d..758f2cf 100644 --- a/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/ResourceAuthorizationProvider.java +++ b/sentry-provider/sentry-provider-common/src/main/java/org/apache/sentry/provider/common/ResourceAuthorizationProvider.java @@ -16,10 +16,10 @@ */ package org.apache.sentry.provider.common; -import static org.apache.sentry.policy.common.PolicyConstants.AUTHORIZABLE_JOINER; -import static org.apache.sentry.policy.common.PolicyConstants.AUTHORIZABLE_SPLITTER; -import static org.apache.sentry.policy.common.PolicyConstants.KV_JOINER; -import static org.apache.sentry.policy.common.PolicyConstants.PRIVILEGE_NAME; +import static org.apache.sentry.core.common.utils.SentryConstants.AUTHORIZABLE_JOINER; +import static org.apache.sentry.core.common.utils.SentryConstants.AUTHORIZABLE_SPLITTER; +import static org.apache.sentry.core.common.utils.SentryConstants.KV_JOINER; +import static org.apache.sentry.core.common.utils.SentryConstants.PRIVILEGE_NAME; import java.util.ArrayList; import java.util.HashSet; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/service/persistent/PrivilegeObject.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/service/persistent/PrivilegeObject.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/service/persistent/PrivilegeObject.java index 3c00d23..0ac39f4 100644 --- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/service/persistent/PrivilegeObject.java +++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/service/persistent/PrivilegeObject.java @@ -17,8 +17,8 @@ */ package org.apache.sentry.provider.db.generic.service.persistent; -import static org.apache.sentry.policy.common.PolicyConstants.KV_JOINER; -import static org.apache.sentry.policy.common.PolicyConstants.AUTHORIZABLE_JOINER; +import static org.apache.sentry.core.common.utils.SentryConstants.KV_JOINER; +import static org.apache.sentry.core.common.utils.SentryConstants.AUTHORIZABLE_JOINER; import java.util.List; import org.apache.sentry.core.common.Authorizable; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/service/thrift/SentryGenericPolicyProcessor.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/service/thrift/SentryGenericPolicyProcessor.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/service/thrift/SentryGenericPolicyProcessor.java index d07331e..02fff69 100644 --- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/service/thrift/SentryGenericPolicyProcessor.java +++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/service/thrift/SentryGenericPolicyProcessor.java @@ -17,8 +17,8 @@ */ package org.apache.sentry.provider.db.generic.service.thrift; -import static org.apache.sentry.policy.common.PolicyConstants.AUTHORIZABLE_JOINER; -import static org.apache.sentry.policy.common.PolicyConstants.KV_JOINER; +import static org.apache.sentry.core.common.utils.SentryConstants.AUTHORIZABLE_JOINER; +import static org.apache.sentry.core.common.utils.SentryConstants.KV_JOINER; import java.lang.reflect.Constructor; import java.util.HashSet; @@ -29,9 +29,9 @@ import java.util.Set; import org.apache.hadoop.conf.Configuration; import org.apache.sentry.SentryUserException; import org.apache.sentry.core.common.Authorizable; +import org.apache.sentry.core.common.utils.SentryConstants; import org.apache.sentry.core.model.db.AccessConstants; -import org.apache.sentry.policy.common.KeyValue; -import org.apache.sentry.policy.common.PolicyConstants; +import org.apache.sentry.core.common.utils.KeyValue; import org.apache.sentry.provider.common.AuthorizationComponent; import org.apache.sentry.provider.db.SentryAccessDeniedException; import org.apache.sentry.provider.db.SentryAlreadyExistsException; @@ -257,11 +257,11 @@ public class SentryGenericPolicyProcessor implements SentryGenericPolicyService. for (Authorizable authorizable : authorizables) { - privileges.add(PolicyConstants.KV_JOINER.join(authorizable.getTypeName(), + privileges.add(SentryConstants.KV_JOINER.join(authorizable.getTypeName(), authorizable.getName())); } - return PolicyConstants.AUTHORIZABLE_JOINER.join(privileges); + return SentryConstants.AUTHORIZABLE_JOINER.join(privileges); } else { return ""; } @@ -293,7 +293,7 @@ public class SentryGenericPolicyProcessor implements SentryGenericPolicyService. return authorizables; } - for (String authorizable : PolicyConstants.AUTHORIZABLE_SPLITTER.split(privilegeStr)) { + for (String authorizable : SentryConstants.AUTHORIZABLE_SPLITTER.split(privilegeStr)) { KeyValue tempKV = new KeyValue(authorizable); final String key = tempKV.getKey(); final String value = tempKV.getValue(); http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SolrTSentryPrivilegeConvertor.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SolrTSentryPrivilegeConvertor.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SolrTSentryPrivilegeConvertor.java index e2dfdf1..4ca7afa 100644 --- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SolrTSentryPrivilegeConvertor.java +++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SolrTSentryPrivilegeConvertor.java @@ -20,14 +20,14 @@ package org.apache.sentry.provider.db.generic.tools; import com.google.common.collect.Lists; +import org.apache.sentry.core.common.utils.SentryConstants; import org.apache.sentry.core.model.search.Collection; import org.apache.sentry.core.model.search.SearchModelAuthorizable; -import org.apache.sentry.policy.common.PolicyConstants; import org.apache.sentry.policy.common.PrivilegeValidator; import org.apache.sentry.policy.common.PrivilegeValidatorContext; import org.apache.sentry.policy.search.SearchModelAuthorizables; import org.apache.sentry.policy.search.SimpleSearchPolicyEngine; -import org.apache.sentry.policy.common.KeyValue; +import org.apache.sentry.core.common.utils.KeyValue; import org.apache.sentry.provider.common.PolicyFileConstants; import org.apache.sentry.provider.db.generic.service.thrift.TAuthorizable; import org.apache.sentry.provider.db.generic.service.thrift.TSentryGrantOption; @@ -52,7 +52,7 @@ public class SolrTSentryPrivilegeConvertor implements TSentryPrivilegeConvertor validatePrivilegeHierarchy(privilegeStr); TSentryPrivilege tSentryPrivilege = new TSentryPrivilege(); List<TAuthorizable> authorizables = new LinkedList<TAuthorizable>(); - for (String authorizable : PolicyConstants.AUTHORIZABLE_SPLITTER.split(privilegeStr)) { + for (String authorizable : SentryConstants.AUTHORIZABLE_SPLITTER.split(privilegeStr)) { KeyValue keyValue = new KeyValue(authorizable); String key = keyValue.getKey(); String value = keyValue.getValue(); @@ -95,23 +95,23 @@ public class SolrTSentryPrivilegeConvertor implements TSentryPrivilegeConvertor if (it != null) { while (it.hasNext()) { TAuthorizable tAuthorizable = it.next(); - privileges.add(PolicyConstants.KV_JOINER.join( + privileges.add(SentryConstants.KV_JOINER.join( tAuthorizable.getType(), tAuthorizable.getName())); } } if (!authorizables.isEmpty()) { - privileges.add(PolicyConstants.KV_JOINER.join( + privileges.add(SentryConstants.KV_JOINER.join( PolicyFileConstants.PRIVILEGE_ACTION_NAME, action)); } // only append the grant option to privilege string if it's true if ("true".equals(grantOption)) { - privileges.add(PolicyConstants.KV_JOINER.join( + privileges.add(SentryConstants.KV_JOINER.join( PolicyFileConstants.PRIVILEGE_GRANT_OPTION_NAME, grantOption)); } } - return PolicyConstants.AUTHORIZABLE_JOINER.join(privileges); + return SentryConstants.AUTHORIZABLE_JOINER.join(privileges); } private static void validatePrivilegeHierarchy(String privilegeStr) throws Exception { http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/model/MSentryGMPrivilege.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/model/MSentryGMPrivilege.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/model/MSentryGMPrivilege.java index 13b48ea..59161f0 100644 --- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/model/MSentryGMPrivilege.java +++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/model/MSentryGMPrivilege.java @@ -17,8 +17,8 @@ vim * Licensed to the Apache Software Foundation (ASF) under one */ package org.apache.sentry.provider.db.service.model; -import static org.apache.sentry.policy.common.PolicyConstants.AUTHORIZABLE_JOINER; -import static org.apache.sentry.policy.common.PolicyConstants.KV_JOINER; +import static org.apache.sentry.core.common.utils.SentryConstants.AUTHORIZABLE_JOINER; +import static org.apache.sentry.core.common.utils.SentryConstants.KV_JOINER; import java.lang.reflect.Field; import java.util.HashSet; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java index 9cebe1e..223f13c 100644 --- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java +++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java @@ -18,8 +18,8 @@ package org.apache.sentry.provider.db.service.persistent; -import static org.apache.sentry.policy.common.PolicyConstants.AUTHORIZABLE_JOINER; -import static org.apache.sentry.policy.common.PolicyConstants.KV_JOINER; +import static org.apache.sentry.core.common.utils.SentryConstants.AUTHORIZABLE_JOINER; +import static org.apache.sentry.core.common.utils.SentryConstants.KV_JOINER; import java.io.IOException; import java.util.ArrayList; @@ -47,9 +47,9 @@ import javax.jdo.Transaction; import org.apache.commons.lang.StringUtils; import org.apache.hadoop.conf.Configuration; import org.apache.sentry.SentryUserException; +import org.apache.sentry.core.common.utils.SentryConstants; import org.apache.sentry.core.model.db.AccessConstants; import org.apache.sentry.core.model.db.DBModelAuthorizable.AuthorizableType; -import org.apache.sentry.policy.common.PolicyConstants; import org.apache.sentry.provider.db.SentryAccessDeniedException; import org.apache.sentry.provider.db.SentryAlreadyExistsException; import org.apache.sentry.provider.db.SentryGrantDeniedException; @@ -1309,7 +1309,7 @@ public class SentryStore { if (!isNULL(privilege.getAction()) && !privilege.getAction().equalsIgnoreCase(AccessConstants.ALL)) { authorizable - .add(KV_JOINER.join(PolicyConstants.PRIVILEGE_NAME.toLowerCase(), + .add(KV_JOINER.join(SentryConstants.PRIVILEGE_NAME.toLowerCase(), privilege.getAction())); } return AUTHORIZABLE_JOINER.join(authorizable); http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/command/hive/CommandUtil.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/command/hive/CommandUtil.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/command/hive/CommandUtil.java index fa7fc6e..c229374 100644 --- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/command/hive/CommandUtil.java +++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/command/hive/CommandUtil.java @@ -18,8 +18,8 @@ package org.apache.sentry.provider.db.tools.command.hive; import org.apache.commons.lang.StringUtils; -import org.apache.sentry.policy.common.KeyValue; -import org.apache.sentry.policy.common.PolicyConstants; +import org.apache.sentry.core.common.utils.SentryConstants; +import org.apache.sentry.core.common.utils.KeyValue; import org.apache.sentry.provider.common.PolicyFileConstants; import org.apache.sentry.provider.db.service.thrift.TSentryGrantOption; import org.apache.sentry.provider.db.service.thrift.TSentryPrivilege; @@ -32,7 +32,7 @@ public class CommandUtil { // parse the privilege in String and get the TSentryPrivilege as result public static TSentryPrivilege convertToTSentryPrivilege(String privilegeStr) throws Exception { TSentryPrivilege tSentryPrivilege = new TSentryPrivilege(); - for (String authorizable : PolicyConstants.AUTHORIZABLE_SPLITTER.split(privilegeStr)) { + for (String authorizable : SentryConstants.AUTHORIZABLE_SPLITTER.split(privilegeStr)) { KeyValue tempKV = new KeyValue(authorizable); String key = tempKV.getKey(); String value = tempKV.getValue(); http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/command/hive/ListPrivilegesCmd.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/command/hive/ListPrivilegesCmd.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/command/hive/ListPrivilegesCmd.java index d990ef3..f671322 100644 --- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/command/hive/ListPrivilegesCmd.java +++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/tools/command/hive/ListPrivilegesCmd.java @@ -19,7 +19,7 @@ package org.apache.sentry.provider.db.tools.command.hive; import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; -import org.apache.sentry.policy.common.PolicyConstants; +import org.apache.sentry.core.common.utils.SentryConstants; import org.apache.sentry.provider.common.PolicyFileConstants; import org.apache.sentry.provider.db.service.thrift.SentryPolicyServiceClient; import org.apache.sentry.provider.db.service.thrift.TSentryGrantOption; @@ -64,34 +64,34 @@ public class ListPrivilegesCmd implements Command { String grantOption = (tSentryPrivilege.getGrantOption() == TSentryGrantOption.TRUE ? "true" : "false"); if (!StringUtils.isEmpty(serverName)) { - privileges.add(PolicyConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_SERVER_NAME, + privileges.add(SentryConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_SERVER_NAME, serverName)); if (!StringUtils.isEmpty(uri)) { - privileges.add(PolicyConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_URI_NAME, + privileges.add(SentryConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_URI_NAME, uri)); } else if (!StringUtils.isEmpty(dbName)) { - privileges.add(PolicyConstants.KV_JOINER.join( + privileges.add(SentryConstants.KV_JOINER.join( PolicyFileConstants.PRIVILEGE_DATABASE_NAME, dbName)); if (!StringUtils.isEmpty(tableName)) { - privileges.add(PolicyConstants.KV_JOINER.join( + privileges.add(SentryConstants.KV_JOINER.join( PolicyFileConstants.PRIVILEGE_TABLE_NAME, tableName)); if (!StringUtils.isEmpty(columnName)) { - privileges.add(PolicyConstants.KV_JOINER.join( + privileges.add(SentryConstants.KV_JOINER.join( PolicyFileConstants.PRIVILEGE_COLUMN_NAME, columnName)); } } } if (!StringUtils.isEmpty(action)) { - privileges.add(PolicyConstants.KV_JOINER.join( + privileges.add(SentryConstants.KV_JOINER.join( PolicyFileConstants.PRIVILEGE_ACTION_NAME, action)); } } // only append the grant option to privilege string if it's true if ("true".equals(grantOption)) { - privileges.add(PolicyConstants.KV_JOINER.join( + privileges.add(SentryConstants.KV_JOINER.join( PolicyFileConstants.PRIVILEGE_GRANT_OPTION_NAME, grantOption)); } } - return PolicyConstants.AUTHORIZABLE_JOINER.join(privileges); + return SentryConstants.AUTHORIZABLE_JOINER.join(privileges); } } http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceUtil.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceUtil.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceUtil.java index 5b293ec..f22cf54 100644 --- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceUtil.java +++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceUtil.java @@ -21,8 +21,8 @@ package org.apache.sentry.service.thrift; import java.util.List; import org.apache.commons.lang.StringUtils; -import org.apache.sentry.policy.common.KeyValue; -import org.apache.sentry.policy.common.PolicyConstants; +import org.apache.sentry.core.common.utils.SentryConstants; +import org.apache.sentry.core.common.utils.KeyValue; import org.apache.sentry.provider.common.PolicyFileConstants; import org.apache.sentry.provider.db.service.thrift.TSentryGrantOption; import org.apache.sentry.provider.db.service.thrift.TSentryPrivilege; @@ -35,7 +35,7 @@ public class SentryServiceUtil { // parse the privilege in String and get the TSentryPrivilege as result public static TSentryPrivilege convertToTSentryPrivilege(String privilegeStr) { TSentryPrivilege tSentryPrivilege = new TSentryPrivilege(); - for (String authorizable : PolicyConstants.AUTHORIZABLE_SPLITTER.split(privilegeStr)) { + for (String authorizable : SentryConstants.AUTHORIZABLE_SPLITTER.split(privilegeStr)) { KeyValue tempKV = new KeyValue(authorizable); String key = tempKV.getKey(); String value = tempKV.getValue(); @@ -94,34 +94,34 @@ public class SentryServiceUtil { String grantOption = (tSentryPrivilege.getGrantOption() == TSentryGrantOption.TRUE ? "true" : "false"); if (!StringUtils.isEmpty(serverName)) { - privileges.add(PolicyConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_SERVER_NAME, + privileges.add(SentryConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_SERVER_NAME, serverName)); if (!StringUtils.isEmpty(uri)) { - privileges.add(PolicyConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_URI_NAME, + privileges.add(SentryConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_URI_NAME, uri)); } else if (!StringUtils.isEmpty(dbName)) { - privileges.add(PolicyConstants.KV_JOINER.join( + privileges.add(SentryConstants.KV_JOINER.join( PolicyFileConstants.PRIVILEGE_DATABASE_NAME, dbName)); if (!StringUtils.isEmpty(tableName)) { - privileges.add(PolicyConstants.KV_JOINER.join( + privileges.add(SentryConstants.KV_JOINER.join( PolicyFileConstants.PRIVILEGE_TABLE_NAME, tableName)); if (!StringUtils.isEmpty(columnName)) { - privileges.add(PolicyConstants.KV_JOINER.join( + privileges.add(SentryConstants.KV_JOINER.join( PolicyFileConstants.PRIVILEGE_COLUMN_NAME, columnName)); } } } if (!StringUtils.isEmpty(action)) { - privileges.add(PolicyConstants.KV_JOINER.join( + privileges.add(SentryConstants.KV_JOINER.join( PolicyFileConstants.PRIVILEGE_ACTION_NAME, action)); } } // only append the grant option to privilege string if it's true if ("true".equals(grantOption)) { - privileges.add(PolicyConstants.KV_JOINER.join( + privileges.add(SentryConstants.KV_JOINER.join( PolicyFileConstants.PRIVILEGE_GRANT_OPTION_NAME, grantOption)); } } - return PolicyConstants.AUTHORIZABLE_JOINER.join(privileges); + return SentryConstants.AUTHORIZABLE_JOINER.join(privileges); } } http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceImportExport.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceImportExport.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceImportExport.java index 1b11e62..0b030c1 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceImportExport.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceImportExport.java @@ -25,7 +25,7 @@ import static org.junit.Assert.fail; import java.util.Map; import java.util.Set; -import org.apache.sentry.policy.common.PolicyConstants; +import org.apache.sentry.core.common.utils.SentryConstants; import org.apache.sentry.provider.common.PolicyFileConstants; import org.apache.sentry.service.thrift.SentryServiceIntegrationBase; import org.junit.Before; @@ -526,8 +526,8 @@ public class TestSentryServiceImportExport extends SentryServiceIntegrationBase for (String actualPrivilege : actualPrivileges) { boolean isFound = exceptedPrivileges.contains(actualPrivilege); if (!isFound) { - String withOptionPrivilege = PolicyConstants.AUTHORIZABLE_JOINER.join(actualPrivilege, - PolicyConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_GRANT_OPTION_NAME, + String withOptionPrivilege = SentryConstants.AUTHORIZABLE_JOINER.join(actualPrivilege, + SentryConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_GRANT_OPTION_NAME, "false")); isFound = exceptedPrivileges.contains(withOptionPrivilege); } http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/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 fed1195..72e219d 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 @@ -26,7 +26,7 @@ import java.util.Set; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.sentry.policy.common.PolicyConstants; +import org.apache.sentry.core.common.utils.SentryConstants; import org.apache.sentry.provider.common.GroupMappingService; import org.apache.sentry.provider.common.PolicyFileConstants; import org.apache.sentry.provider.common.SentryGroupNotFoundException; @@ -111,7 +111,7 @@ public class LocalGroupMappingService implements GroupMappingService { " in the " + resourcePath); continue; } - Set<String> groupList = Sets.newHashSet(PolicyConstants.ROLE_SPLITTER.trimResults().split( + Set<String> groupList = Sets.newHashSet(SentryConstants.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/48c021a0/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 884de16..cc53cb3 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,7 +16,7 @@ */ package org.apache.sentry.provider.file; -import static org.apache.sentry.policy.common.PolicyConstants.ROLE_SPLITTER; +import static org.apache.sentry.core.common.utils.SentryConstants.ROLE_SPLITTER; import java.io.IOException; import java.net.URI; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java index 79f74af..77d89ef 100644 --- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java +++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java @@ -16,9 +16,9 @@ */ package org.apache.sentry.tests.e2e.hive; -import static org.apache.sentry.policy.common.PolicyConstants.AUTHORIZABLE_SPLITTER; -import static org.apache.sentry.policy.common.PolicyConstants.PRIVILEGE_PREFIX; -import static org.apache.sentry.policy.common.PolicyConstants.ROLE_SPLITTER; +import static org.apache.sentry.core.common.utils.SentryConstants.AUTHORIZABLE_SPLITTER; +import static org.apache.sentry.core.common.utils.SentryConstants.PRIVILEGE_PREFIX; +import static org.apache.sentry.core.common.utils.SentryConstants.ROLE_SPLITTER; import static org.junit.Assert.assertTrue; import java.io.File; http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPolicyImportExport.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPolicyImportExport.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPolicyImportExport.java index 4d2f572..cb4fed3 100644 --- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPolicyImportExport.java +++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPolicyImportExport.java @@ -28,7 +28,7 @@ import java.util.Set; import org.apache.sentry.binding.hive.SentryPolicyFileFormatFactory; import org.apache.sentry.binding.hive.SentryPolicyFileFormatter; import org.apache.sentry.binding.hive.authz.SentryConfigTool; -import org.apache.sentry.policy.common.PolicyConstants; +import org.apache.sentry.core.common.utils.SentryConstants; import org.apache.sentry.provider.common.PolicyFileConstants; import org.junit.Before; import org.junit.BeforeClass; @@ -183,8 +183,8 @@ public class TestPolicyImportExport extends AbstractTestWithStaticConfiguration for (String actualPrivilege : actualPrivileges) { boolean isFound = exceptedPrivileges.contains(actualPrivilege); if (!isFound) { - String withOptionPrivilege = PolicyConstants.AUTHORIZABLE_JOINER.join(actualPrivilege, - PolicyConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_GRANT_OPTION_NAME, + String withOptionPrivilege = SentryConstants.AUTHORIZABLE_JOINER.join(actualPrivilege, + SentryConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_GRANT_OPTION_NAME, "false")); isFound = exceptedPrivileges.contains(withOptionPrivilege); } http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/48c021a0/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/SentryPolicyProviderForDb.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/SentryPolicyProviderForDb.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/SentryPolicyProviderForDb.java index 4e1e750..474cdd7 100644 --- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/SentryPolicyProviderForDb.java +++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/SentryPolicyProviderForDb.java @@ -16,9 +16,9 @@ */ package org.apache.sentry.tests.e2e.metastore; -import static org.apache.sentry.policy.common.PolicyConstants.AUTHORIZABLE_SPLITTER; -import static org.apache.sentry.policy.common.PolicyConstants.PRIVILEGE_PREFIX; -import static org.apache.sentry.policy.common.PolicyConstants.ROLE_SPLITTER; +import static org.apache.sentry.core.common.utils.SentryConstants.AUTHORIZABLE_SPLITTER; +import static org.apache.sentry.core.common.utils.SentryConstants.PRIVILEGE_PREFIX; +import static org.apache.sentry.core.common.utils.SentryConstants.ROLE_SPLITTER; import static org.apache.sentry.tests.e2e.hive.StaticUserGroup.ADMIN1; import static org.apache.sentry.tests.e2e.hive.StaticUserGroup.ADMINGROUP;
