You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by co...@apache.org on 2017/11/20 14:47:22 UTC
[1/9] sentry git commit: Revert "SENTRY-2012 - Make
SentryShellGeneric extendible. Mano Kovacs, reviewed by Colm O hEigeartaigh."
Repository: sentry
Updated Branches:
refs/heads/akolb-cli 81128e6bc -> fe3ef2370
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSolr.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSolr.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSolr.java
index 40e7555..0f4bb62 100644
--- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSolr.java
+++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSolr.java
@@ -18,17 +18,12 @@
package org.apache.sentry.provider.db.generic.tools;
-import com.google.common.collect.Sets;
import com.google.common.io.Files;
-import org.apache.commons.io.FileUtils;
-import org.apache.sentry.core.common.exception.SentryUserException;
-import org.apache.sentry.provider.db.generic.service.thrift.SentryGenericServiceIntegrationBase;
-import org.apache.sentry.provider.db.generic.service.thrift.TSentryPrivilege;
-import org.apache.sentry.provider.db.generic.service.thrift.TSentryRole;
-import org.apache.sentry.provider.db.tools.SentryShellCommon;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import com.google.common.collect.Sets;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -38,7 +33,16 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
-import static org.junit.Assert.*;
+import org.apache.commons.io.FileUtils;
+import org.apache.sentry.core.common.exception.SentryUserException;
+import org.apache.sentry.provider.db.generic.service.thrift.SentryGenericServiceIntegrationBase;
+import org.apache.sentry.provider.db.generic.service.thrift.TSentryRole;
+import org.apache.sentry.provider.db.generic.service.thrift.TSentryPrivilege;
+import org.apache.sentry.provider.db.tools.SentryShellCommon;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase {
private File confDir;
@@ -76,32 +80,32 @@ public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase {
@Override
public void runTestAsSubject() throws Exception {
// test: create role with -cr
- String[] args = { "-cr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() };
- SentryShellSolr.main(args);
+ String[] args = { "-cr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ SentryShellGeneric.main(args);
// test: create role with --create_role
args = new String[] { "--create_role", "-r", TEST_ROLE_NAME_2, "-conf",
- confPath.getAbsolutePath() };
- SentryShellSolr.main(args);
+ confPath.getAbsolutePath(), "-t", "solr" };
+ SentryShellGeneric.main(args);
// validate the result, list roles with -lr
- args = new String[] { "-lr", "-conf", confPath.getAbsolutePath() };
- SentryShellSolr sentryShell = new SentryShellSolr();
+ args = new String[] { "-lr", "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
Set<String> roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames, TEST_ROLE_NAME_1, TEST_ROLE_NAME_2);
// validate the result, list roles with --list_role
- args = new String[] { "--list_role", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ args = new String[] { "--list_role", "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames, TEST_ROLE_NAME_1, TEST_ROLE_NAME_2);
// test: drop role with -dr
- args = new String[] { "-dr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() };
- SentryShellSolr.main(args);
+ args = new String[] { "-dr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ SentryShellGeneric.main(args);
// test: drop role with --drop_role
args = new String[] { "--drop_role", "-r", TEST_ROLE_NAME_2, "-conf",
- confPath.getAbsolutePath() };
- SentryShellSolr.main(args);
+ confPath.getAbsolutePath(), "-t", "solr" };
+ SentryShellGeneric.main(args);
// validate the result
Set<TSentryRole> roles = client.listAllRoles(requestorName, SOLR);
@@ -125,41 +129,41 @@ public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase {
client.createRole(requestorName, TEST_ROLE_NAME_2, SOLR);
// test: add role to group with -arg
String[] args = { "-arg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_1, "-conf",
- confPath.getAbsolutePath() };
- SentryShellSolr.main(args);
+ confPath.getAbsolutePath(), "-t", "solr" };
+ SentryShellGeneric.main(args);
// test: add role to multiple groups
args = new String[] { "-arg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_2 + "," + TEST_GROUP_3,
- "-conf",
- confPath.getAbsolutePath() };
- SentryShellSolr.main(args);
+ "-conf",
+ confPath.getAbsolutePath(), "-t", "solr" };
+ SentryShellGeneric.main(args);
// test: add role to group with --add_role_group
args = new String[] { "--add_role_group", "-r", TEST_ROLE_NAME_2, "-g", TEST_GROUP_1,
- "-conf",
- confPath.getAbsolutePath() };
- SentryShellSolr.main(args);
+ "-conf",
+ confPath.getAbsolutePath(), "-t", "solr" };
+ SentryShellGeneric.main(args);
// validate the result list roles with -lr and -g
- args = new String[] { "-lr", "-g", TEST_GROUP_1, "-conf", confPath.getAbsolutePath() };
- SentryShellSolr sentryShell = new SentryShellSolr();
+ args = new String[] { "-lr", "-g", TEST_GROUP_1, "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
Set<String> roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames, TEST_ROLE_NAME_1, TEST_ROLE_NAME_2);
// list roles with --list_role and -g
args = new String[] { "--list_role", "-g", TEST_GROUP_2, "-conf",
- confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames, TEST_ROLE_NAME_1);
args = new String[] { "--list_role", "-g", TEST_GROUP_3, "-conf",
- confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames, TEST_ROLE_NAME_1);
// List the groups and roles via listGroups
- args = new String[] { "--list_group", "-conf", confPath.getAbsolutePath()};
- sentryShell = new SentryShellSolr();
+ args = new String[] { "--list_group", "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
Set<String> groups = getShellResultWithOSRedirect(sentryShell, args, true);
assertEquals(3, groups.size());
assertTrue(groups.contains("testGroup3 = testrole1"));
@@ -168,17 +172,17 @@ public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase {
// test: delete role from group with -drg
args = new String[] { "-drg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_1, "-conf",
- confPath.getAbsolutePath() };
- SentryShellSolr.main(args);
+ confPath.getAbsolutePath(), "-t", "solr" };
+ SentryShellGeneric.main(args);
// test: delete role to multiple groups
args = new String[] { "-drg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_2 + "," + TEST_GROUP_3,
- "-conf",
- confPath.getAbsolutePath() };
- SentryShellSolr.main(args);
+ "-conf",
+ confPath.getAbsolutePath(), "-t", "solr" };
+ SentryShellGeneric.main(args);
// test: delete role from group with --delete_role_group
args = new String[] { "--delete_role_group", "-r", TEST_ROLE_NAME_2, "-g", TEST_GROUP_1,
- "-conf", confPath.getAbsolutePath() };
- SentryShellSolr.main(args);
+ "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ SentryShellGeneric.main(args);
// validate the result
Set<TSentryRole> roles = client.listRolesByGroupName(requestorName, TEST_GROUP_1, SOLR);
@@ -204,22 +208,22 @@ public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase {
client.createRole(requestorName, TEST_ROLE_NAME_1, SOLR);
// add role to a group (lower case)
String[] args = { "-arg", "-r", TEST_ROLE_NAME_1, "-g", "group1", "-conf",
- confPath.getAbsolutePath() };
- SentryShellSolr.main(args);
+ confPath.getAbsolutePath(), "-t", "solr" };
+ SentryShellGeneric.main(args);
// validate the roles when group name is same case as above
- args = new String[] { "-lr", "-g", "group1", "-conf", confPath.getAbsolutePath() };
- SentryShellSolr sentryShell = new SentryShellSolr();
+ args = new String[] { "-lr", "-g", "group1", "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
Set<String> roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames, TEST_ROLE_NAME_1);
// roles should be empty when group name is different case than above
- args = new String[] { "-lr", "-g", "GROUP1", "-conf", confPath.getAbsolutePath() };
+ args = new String[] { "-lr", "-g", "GROUP1", "-conf", confPath.getAbsolutePath(), "-t", "solr" };
roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames);
}
- });
- }
+ });
+ }
public static String grant(boolean shortOption) {
return shortOption ? "-gpr" : "--grant_privilege_role";
@@ -242,21 +246,21 @@ public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase {
client.createRole(requestorName, TEST_ROLE_NAME_2, SOLR);
String [] privs = {
- "Collection=*->action=*",
- "Collection=collection2->action=update",
- "Collection=collection3->action=query",
+ "Collection=*->action=*",
+ "Collection=collection2->action=update",
+ "Collection=collection3->action=query",
};
for (int i = 0; i < privs.length; ++i) {
// test: grant privilege to role
String [] args = new String [] { grant(shortOption), "-r", TEST_ROLE_NAME_1, "-p",
- privs[ i ],
- "-conf", confPath.getAbsolutePath() };
- SentryShellSolr.main(args);
+ privs[ i ],
+ "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ SentryShellGeneric.main(args);
}
// test the list privilege
- String [] args = new String[] { list(shortOption), "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() };
- SentryShellSolr sentryShell = new SentryShellSolr();
+ String [] args = new String[] { list(shortOption), "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
Set<String> privilegeStrs = getShellResultWithOSRedirect(sentryShell, args, true);
assertEquals("Incorrect number of privileges", privs.length, privilegeStrs.size());
for (int i = 0; i < privs.length; ++i) {
@@ -266,8 +270,8 @@ public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase {
for (int i = 0; i < privs.length; ++i) {
args = new String[] { revoke(shortOption), "-r", TEST_ROLE_NAME_1, "-p",
privs[ i ], "-conf",
- confPath.getAbsolutePath()};
- SentryShellSolr.main(args);
+ confPath.getAbsolutePath(), "-t", "solr" };
+ SentryShellGeneric.main(args);
Set<TSentryPrivilege> privileges = client.listAllPrivilegesByRoleName(requestorName,
TEST_ROLE_NAME_1, SOLR, service);
assertEquals("Incorrect number of privileges", privs.length - (i + 1), privileges.size());
@@ -299,8 +303,8 @@ public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase {
public void runTestAsSubject() throws Exception {
client.createRole(requestorName, TEST_ROLE_NAME_1, SOLR);
// test: create duplicate role with -cr
- String[] args = { "-cr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() };
- SentryShellSolr sentryShell = new SentryShellSolr();
+ String[] args = { "-cr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
try {
sentryShell.executeShell(args);
fail("Exception should be thrown for creating duplicate role");
@@ -309,8 +313,8 @@ public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase {
}
// test: drop non-exist role with -dr
- args = new String[] { "-dr", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ args = new String[] { "-dr", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
try {
sentryShell.executeShell(args);
fail("Exception should be thrown for dropping non-exist role");
@@ -320,8 +324,8 @@ public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase {
// test: add non-exist role to group with -arg
args = new String[] { "-arg", "-r", TEST_ROLE_NAME_2, "-g", "testGroup1", "-conf",
- confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
try {
sentryShell.executeShell(args);
fail("Exception should be thrown for granting non-exist role to group");
@@ -331,8 +335,8 @@ public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase {
// test: drop group from non-exist role with -drg
args = new String[] { "-drg", "-r", TEST_ROLE_NAME_2, "-g", "testGroup1", "-conf",
- confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
try {
sentryShell.executeShell(args);
fail("Exception should be thrown for drop group from non-exist role");
@@ -342,8 +346,8 @@ public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase {
// test: grant privilege to role with the error privilege format
args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-p", "serverserver1->action=*",
- "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
try {
sentryShell.executeShell(args);
fail("Exception should be thrown for the error privilege format, invalid key value.");
@@ -353,9 +357,9 @@ public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase {
// test: grant privilege to role with the error privilege hierarchy
args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-p",
- "server=server1->table=tbl1->column=col2->action=insert", "-conf",
- confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ "server=server1->table=tbl1->column=col2->action=insert", "-conf",
+ confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
try {
sentryShell.executeShell(args);
fail("Exception should be thrown for the error privilege format, invalid key value.");
@@ -377,63 +381,63 @@ public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase {
String strOptionConf = "conf";
client.createRole(requestorName, TEST_ROLE_NAME_1, SOLR);
// test: the conf is required argument
- String[] args = { "-cr", "-r", TEST_ROLE_NAME_1 };
- SentryShellSolr sentryShell = new SentryShellSolr();
+ String[] args = { "-cr", "-r", TEST_ROLE_NAME_1, "-t", "solr" };
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + strOptionConf);
// test: -r is required when create role
- args = new String[] { "-cr", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ args = new String[] { "-cr", "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);
// test: -r is required when drop role
- args = new String[] { "-dr", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ args = new String[] { "-dr", "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);
// test: -r is required when add role to group
- args = new String[] { "-arg", "-g", "testGroup1", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ args = new String[] { "-arg", "-g", "testGroup1", "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);
// test: -g is required when add role to group
- args = new String[] { "-arg", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ args = new String[] { "-arg", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_GROUP_NAME);
// test: -r is required when delete role from group
- args = new String[] { "-drg", "-g", "testGroup1", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ args = new String[] { "-drg", "-g", "testGroup1", "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);
// test: -g is required when delete role from group
- args = new String[] { "-drg", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ args = new String[] { "-drg", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_GROUP_NAME);
// test: -r is required when grant privilege to role
- args = new String[] { "-gpr", "-p", "server=server1", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ args = new String[] { "-gpr", "-p", "server=server1", "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);
// test: -p is required when grant privilege to role
- args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_PRIVILEGE);
// test: action is required in privilege
- args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-p", "collection=collection1" };
- sentryShell = new SentryShellSolr();
- try {
+ args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-p", "collection=collection1", "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
+ try {
getShellResultWithOSRedirect(sentryShell, args, false);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
@@ -441,20 +445,20 @@ public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase {
}
// test: -r is required when revoke privilege from role
- args = new String[] { "-rpr", "-p", "server=server1", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ args = new String[] { "-rpr", "-p", "server=server1", "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);
// test: -p is required when revoke privilege from role
- args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t", "solr" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_PRIVILEGE);
// test: command option is required for shell
args = new String[] {"-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSolr();
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsgsContains(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + "[",
"-arg Add role to group",
@@ -473,8 +477,8 @@ public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase {
}
// redirect the System.out to ByteArrayOutputStream, then execute the command and parse the result.
- private Set<String> getShellResultWithOSRedirect(SentryShellSolr sentryShell,
- String[] args, boolean expectedExecuteResult) throws Exception {
+ private Set<String> getShellResultWithOSRedirect(SentryShellGeneric sentryShell,
+ String[] args, boolean expectedExecuteResult) throws Exception {
PrintStream oldOut = System.out;
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
@@ -487,7 +491,7 @@ public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase {
private void validateRoleNames(Set<String> roleNames, String ... expectedRoleNames) {
if (expectedRoleNames != null && expectedRoleNames.length > 0) {
assertEquals("Found: " + roleNames.size() + " roles, expected: " + expectedRoleNames.length,
- expectedRoleNames.length, roleNames.size());
+ expectedRoleNames.length, roleNames.size());
Set<String> lowerCaseRoles = new HashSet<String>();
for (String role : roleNames) {
lowerCaseRoles.add(role.toLowerCase());
@@ -495,19 +499,19 @@ public class TestSentryShellSolr extends SentryGenericServiceIntegrationBase {
for (String expectedRole : expectedRoleNames) {
assertTrue("Expected role: " + expectedRole,
- lowerCaseRoles.contains(expectedRole.toLowerCase()));
+ lowerCaseRoles.contains(expectedRole.toLowerCase()));
}
}
}
- private void validateMissingParameterMsg(SentryShellSolr sentryShell, String[] args,
- String expectedErrorMsg) throws Exception {
+ private void validateMissingParameterMsg(SentryShellGeneric sentryShell, String[] args,
+ String expectedErrorMsg) throws Exception {
Set<String> errorMsgs = getShellResultWithOSRedirect(sentryShell, args, false);
assertTrue("Expected error message: " + expectedErrorMsg, errorMsgs.contains(expectedErrorMsg));
}
- private void validateMissingParameterMsgsContains(SentryShellSolr sentryShell, String[] args,
- String ... expectedErrorMsgsContains) throws Exception {
+ private void validateMissingParameterMsgsContains(SentryShellGeneric sentryShell, String[] args,
+ String ... expectedErrorMsgsContains) throws Exception {
Set<String> errorMsgs = getShellResultWithOSRedirect(sentryShell, args, false);
boolean foundAllMessages = false;
Iterator<String> it = errorMsgs.iterator();
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSqoop.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSqoop.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSqoop.java
index 27614eb..cdba442 100644
--- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSqoop.java
+++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellSqoop.java
@@ -78,32 +78,32 @@ public class TestSentryShellSqoop extends SentryGenericServiceIntegrationBase {
@Override
public void runTestAsSubject() throws Exception {
// test: create role with -cr
- String[] args = { "-cr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() };
- SentryShellSqoop.main(args);
+ String[] args = { "-cr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ SentryShellGeneric.main(args);
// test: create role with --create_role
args = new String[] { "--create_role", "-r", TEST_ROLE_NAME_2, "-conf",
- confPath.getAbsolutePath() };
- SentryShellSqoop.main(args);
+ confPath.getAbsolutePath(), "-t", "sqoop" };
+ SentryShellGeneric.main(args);
// validate the result, list roles with -lr
- args = new String[] { "-lr", "-conf", confPath.getAbsolutePath() };
- SentryShellSqoop sentryShell = new SentryShellSqoop();
+ args = new String[] { "-lr", "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
Set<String> roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames, TEST_ROLE_NAME_1, TEST_ROLE_NAME_2);
// validate the result, list roles with --list_role
- args = new String[] { "--list_role", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSqoop();
+ args = new String[] { "--list_role", "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames, TEST_ROLE_NAME_1, TEST_ROLE_NAME_2);
// test: drop role with -dr
- args = new String[] { "-dr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() };
- SentryShellSqoop.main(args);
+ args = new String[] { "-dr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ SentryShellGeneric.main(args);
// test: drop role with --drop_role
args = new String[] { "--drop_role", "-r", TEST_ROLE_NAME_2, "-conf",
- confPath.getAbsolutePath() };
- SentryShellSqoop.main(args);
+ confPath.getAbsolutePath(), "-t", "sqoop" };
+ SentryShellGeneric.main(args);
// validate the result
Set<TSentryRole> roles = client.listAllRoles(requestorName, AuthorizationComponent.SQOOP);
@@ -127,41 +127,41 @@ public class TestSentryShellSqoop extends SentryGenericServiceIntegrationBase {
client.createRole(requestorName, TEST_ROLE_NAME_2, AuthorizationComponent.SQOOP);
// test: add role to group with -arg
String[] args = { "-arg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_1, "-conf",
- confPath.getAbsolutePath() };
- SentryShellSqoop.main(args);
+ confPath.getAbsolutePath(), "-t", "sqoop" };
+ SentryShellGeneric.main(args);
// test: add role to multiple groups
args = new String[] { "-arg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_2 + "," + TEST_GROUP_3,
"-conf",
- confPath.getAbsolutePath() };
- SentryShellSqoop.main(args);
+ confPath.getAbsolutePath(), "-t", "sqoop" };
+ SentryShellGeneric.main(args);
// test: add role to group with --add_role_group
args = new String[] { "--add_role_group", "-r", TEST_ROLE_NAME_2, "-g", TEST_GROUP_1,
"-conf",
- confPath.getAbsolutePath() };
- SentryShellSqoop.main(args);
+ confPath.getAbsolutePath(), "-t", "sqoop" };
+ SentryShellGeneric.main(args);
// validate the result list roles with -lr and -g
- args = new String[] { "-lr", "-g", TEST_GROUP_1, "-conf", confPath.getAbsolutePath() };
- SentryShellSqoop sentryShell = new SentryShellSqoop();
+ args = new String[] { "-lr", "-g", TEST_GROUP_1, "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
Set<String> roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames, TEST_ROLE_NAME_1, TEST_ROLE_NAME_2);
// list roles with --list_role and -g
args = new String[] { "--list_role", "-g", TEST_GROUP_2, "-conf",
- confPath.getAbsolutePath() };
- sentryShell = new SentryShellSqoop();
+ confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames, TEST_ROLE_NAME_1);
args = new String[] { "--list_role", "-g", TEST_GROUP_3, "-conf",
- confPath.getAbsolutePath() };
- sentryShell = new SentryShellSqoop();
+ confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames, TEST_ROLE_NAME_1);
// List the groups and roles via listGroups
- args = new String[] { "--list_group", "-conf", confPath.getAbsolutePath()};
- sentryShell = new SentryShellSqoop();
+ args = new String[] { "--list_group", "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
Set<String> groups = getShellResultWithOSRedirect(sentryShell, args, true);
assertEquals(3, groups.size());
assertTrue(groups.contains("testGroup3 = testrole1"));
@@ -170,17 +170,17 @@ public class TestSentryShellSqoop extends SentryGenericServiceIntegrationBase {
// test: delete role from group with -drg
args = new String[] { "-drg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_1, "-conf",
- confPath.getAbsolutePath() };
- SentryShellSqoop.main(args);
+ confPath.getAbsolutePath(), "-t", "sqoop" };
+ SentryShellGeneric.main(args);
// test: delete role to multiple groups
args = new String[] { "-drg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_2 + "," + TEST_GROUP_3,
"-conf",
- confPath.getAbsolutePath() };
- SentryShellSqoop.main(args);
+ confPath.getAbsolutePath(), "-t", "sqoop" };
+ SentryShellGeneric.main(args);
// test: delete role from group with --delete_role_group
args = new String[] { "--delete_role_group", "-r", TEST_ROLE_NAME_2, "-g", TEST_GROUP_1,
- "-conf", confPath.getAbsolutePath() };
- SentryShellSqoop.main(args);
+ "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ SentryShellGeneric.main(args);
// validate the result
Set<TSentryRole> roles = client.listRolesByGroupName(requestorName, TEST_GROUP_1, AuthorizationComponent.SQOOP);
@@ -206,17 +206,17 @@ public class TestSentryShellSqoop extends SentryGenericServiceIntegrationBase {
client.createRole(requestorName, TEST_ROLE_NAME_1, AuthorizationComponent.SQOOP);
// add role to a group (lower case)
String[] args = {"-arg", "-r", TEST_ROLE_NAME_1, "-g", "group1", "-conf",
- confPath.getAbsolutePath()};
- SentryShellSqoop.main(args);
+ confPath.getAbsolutePath(), "-t", "sqoop"};
+ SentryShellGeneric.main(args);
// validate the roles when group name is same case as above
- args = new String[]{"-lr", "-g", "group1", "-conf", confPath.getAbsolutePath()};
- SentryShellSqoop sentryShell = new SentryShellSqoop();
+ args = new String[]{"-lr", "-g", "group1", "-conf", confPath.getAbsolutePath(), "-t", "sqoop"};
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
Set<String> roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames, TEST_ROLE_NAME_1);
// roles should be empty when group name is different case than above
- args = new String[]{"-lr", "-g", "GROUP1", "-conf", confPath.getAbsolutePath()};
+ args = new String[]{"-lr", "-g", "GROUP1", "-conf", confPath.getAbsolutePath(), "-t", "sqoop"};
roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames);
}
@@ -252,13 +252,13 @@ public class TestSentryShellSqoop extends SentryGenericServiceIntegrationBase {
// test: grant privilege to role
String [] args = new String [] { grant(shortOption), "-r", TEST_ROLE_NAME_1, "-p",
privs[ i ],
- "-conf", confPath.getAbsolutePath() };
- SentryShellSqoop.main(args);
+ "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ SentryShellGeneric.main(args);
}
// test the list privilege
- String [] args = new String[] { list(shortOption), "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() };
- SentryShellSqoop sentryShell = new SentryShellSqoop();
+ String [] args = new String[] { list(shortOption), "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
Set<String> privilegeStrs = getShellResultWithOSRedirect(sentryShell, args, true);
assertEquals("Incorrect number of privileges", privs.length, privilegeStrs.size());
@@ -269,8 +269,8 @@ public class TestSentryShellSqoop extends SentryGenericServiceIntegrationBase {
for (int i = 0; i < privs.length; ++i) {
args = new String[] { revoke(shortOption), "-r", TEST_ROLE_NAME_1, "-p",
privs[ i ], "-conf",
- confPath.getAbsolutePath()};
- SentryShellSqoop.main(args);
+ confPath.getAbsolutePath(), "-t", "sqoop" };
+ SentryShellGeneric.main(args);
Set<TSentryPrivilege> privileges = client.listAllPrivilegesByRoleName(requestorName,
TEST_ROLE_NAME_1, AuthorizationComponent.SQOOP, service);
assertEquals("Incorrect number of privileges. Received privileges: " + Arrays.toString(privileges.toArray()), privs.length - (i + 1), privileges.size());
@@ -301,8 +301,8 @@ public class TestSentryShellSqoop extends SentryGenericServiceIntegrationBase {
public void runTestAsSubject() throws Exception {
client.createRole(requestorName, TEST_ROLE_NAME_1, AuthorizationComponent.SQOOP);
// test: create duplicate role with -cr
- String[] args = { "-cr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() };
- SentryShellSqoop sentryShell = new SentryShellSqoop();
+ String[] args = { "-cr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
try {
sentryShell.executeShell(args);
fail("Exception should be thrown for creating duplicate role");
@@ -313,8 +313,8 @@ public class TestSentryShellSqoop extends SentryGenericServiceIntegrationBase {
}
// test: drop non-exist role with -dr
- args = new String[] { "-dr", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSqoop();
+ args = new String[] { "-dr", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
try {
sentryShell.executeShell(args);
fail("Exception should be thrown for dropping non-exist role");
@@ -326,8 +326,8 @@ public class TestSentryShellSqoop extends SentryGenericServiceIntegrationBase {
// test: add non-exist role to group with -arg
args = new String[] { "-arg", "-r", TEST_ROLE_NAME_2, "-g", "testGroup1", "-conf",
- confPath.getAbsolutePath() };
- sentryShell = new SentryShellSqoop();
+ confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
try {
sentryShell.executeShell(args);
fail("Exception should be thrown for granting non-exist role to group");
@@ -339,8 +339,8 @@ public class TestSentryShellSqoop extends SentryGenericServiceIntegrationBase {
// test: drop group from non-exist role with -drg
args = new String[] { "-drg", "-r", TEST_ROLE_NAME_2, "-g", "testGroup1", "-conf",
- confPath.getAbsolutePath() };
- sentryShell = new SentryShellSqoop();
+ confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
try {
sentryShell.executeShell(args);
fail("Exception should be thrown for drop group from non-exist role");
@@ -352,8 +352,8 @@ public class TestSentryShellSqoop extends SentryGenericServiceIntegrationBase {
// test: grant privilege to role with the error privilege format
args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-p", "serverserver1->action=all",
- "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSqoop();
+ "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
try {
sentryShell.executeShell(args);
fail("Exception should be thrown for the error privilege format, invalid key value.");
@@ -377,62 +377,62 @@ public class TestSentryShellSqoop extends SentryGenericServiceIntegrationBase {
String strOptionConf = "conf";
client.createRole(requestorName, TEST_ROLE_NAME_1, AuthorizationComponent.SQOOP);
// test: the conf is required argument
- String[] args = { "-cr", "-r", TEST_ROLE_NAME_1 };
- SentryShellSqoop sentryShell = new SentryShellSqoop();
+ String[] args = { "-cr", "-r", TEST_ROLE_NAME_1, "-t", "sqoop" };
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + strOptionConf);
// test: -r is required when create role
- args = new String[] { "-cr", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSqoop();
+ args = new String[] { "-cr", "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);
// test: -r is required when drop role
- args = new String[] { "-dr", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSqoop();
+ args = new String[] { "-dr", "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);
// test: -r is required when add role to group
- args = new String[] { "-arg", "-g", "testGroup1", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSqoop();
+ args = new String[] { "-arg", "-g", "testGroup1", "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);
// test: -g is required when add role to group
- args = new String[] { "-arg", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSqoop();
+ args = new String[] { "-arg", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_GROUP_NAME);
// test: -r is required when delete role from group
- args = new String[] { "-drg", "-g", "testGroup1", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSqoop();
+ args = new String[] { "-drg", "-g", "testGroup1", "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);
// test: -g is required when delete role from group
- args = new String[] { "-drg", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSqoop();
+ args = new String[] { "-drg", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_GROUP_NAME);
// test: -r is required when grant privilege to role
- args = new String[] { "-gpr", "-p", "server=server1", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSqoop();
+ args = new String[] { "-gpr", "-p", "server=server1", "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);
// test: -p is required when grant privilege to role
- args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSqoop();
+ args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_PRIVILEGE);
// test: action is required in privilege
- args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-p", "Server=sqoopServer1->Connector" };
- sentryShell = new SentryShellSqoop();
+ args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-p", "Server=sqoopServer1->Connector", "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
try {
getShellResultWithOSRedirect(sentryShell, args, false);
fail("Expected IllegalArgumentException");
@@ -443,20 +443,20 @@ public class TestSentryShellSqoop extends SentryGenericServiceIntegrationBase {
}
// test: -r is required when revoke privilege from role
- args = new String[] { "-rpr", "-p", "Server=sqoopServer1->Connector->action=*", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSqoop();
+ args = new String[] { "-rpr", "-p", "Server=sqoopServer1->Connector->action=*", "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);
// test: -p is required when revoke privilege from role
- args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSqoop();
+ args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_PRIVILEGE);
// test: command option is required for shell
- args = new String[] {"-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellSqoop();
+ args = new String[] {"-conf", confPath.getAbsolutePath(), "-t", "sqoop" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsgsContains(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + "[",
"-arg Add role to group",
@@ -475,7 +475,7 @@ public class TestSentryShellSqoop extends SentryGenericServiceIntegrationBase {
}
// redirect the System.out to ByteArrayOutputStream, then execute the command and parse the result.
- private Set<String> getShellResultWithOSRedirect(SentryShellSqoop sentryShell,
+ private Set<String> getShellResultWithOSRedirect(SentryShellGeneric sentryShell,
String[] args, boolean expectedExecuteResult) throws Exception {
PrintStream oldOut = System.out;
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
@@ -502,13 +502,13 @@ public class TestSentryShellSqoop extends SentryGenericServiceIntegrationBase {
}
}
- private void validateMissingParameterMsg(SentryShellSqoop sentryShell, String[] args,
+ private void validateMissingParameterMsg(SentryShellGeneric sentryShell, String[] args,
String expectedErrorMsg) throws Exception {
Set<String> errorMsgs = getShellResultWithOSRedirect(sentryShell, args, false);
assertTrue("Expected error message: " + expectedErrorMsg, errorMsgs.contains(expectedErrorMsg));
}
- private void validateMissingParameterMsgsContains(SentryShellSqoop sentryShell, String[] args,
+ private void validateMissingParameterMsgsContains(SentryShellGeneric sentryShell, String[] args,
String ... expectedErrorMsgsContains) throws Exception {
Set<String> errorMsgs = getShellResultWithOSRedirect(sentryShell, args, false);
boolean foundAllMessages = false;
[7/9] sentry git commit: SENTRY-2048: Bump Hive version to 2.3.2
(Sergio Pena, reviewed by kalyan kumar kalvagadda, Na Li)
Posted by co...@apache.org.
SENTRY-2048: Bump Hive version to 2.3.2 (Sergio Pena, reviewed by kalyan kumar kalvagadda, Na Li)
Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/5f64fe9f
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/5f64fe9f
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/5f64fe9f
Branch: refs/heads/akolb-cli
Commit: 5f64fe9f34fb857ccca5a5b09b9ff46300c98674
Parents: a355979
Author: Sergio Pena <se...@cloudera.com>
Authored: Sun Nov 19 10:47:09 2017 -0600
Committer: Sergio Pena <se...@cloudera.com>
Committed: Sun Nov 19 10:47:09 2017 -0600
----------------------------------------------------------------------
pom.xml | 2 +-
.../json/SentryJSONMessageDeserializer.java | 79 +++++++++++++++++++-
.../json/SentryJSONMessageFactory.java | 48 ++++++++++++
.../hive/ql/exec/SentryFilterDDLTask.java | 9 ++-
.../hive/ql/exec/SentryGrantRevokeTask.java | 7 +-
.../binding/hive/HiveAuthzBindingHook.java | 2 +-
.../hive/authz/DefaultSentryValidator.java | 17 +++++
.../hive/authz/HiveAuthzBindingHookBase.java | 10 ---
.../hive/authz/SentryHiveAuthorizerImpl.java | 13 ++++
.../metastore/SentryHiveMetaStoreClient.java | 2 +-
.../TestSentryHiveAuthorizationTaskFactory.java | 16 ++--
.../e2e/hdfs/TestHDFSIntegrationAdvanced.java | 9 ++-
.../tests/e2e/hdfs/TestHDFSIntegrationBase.java | 4 +
.../e2e/hive/TestPrivilegesAtColumnScope.java | 31 ++++----
.../e2e/hive/hiveserver/HiveServerFactory.java | 10 +++
...actMetastoreTestWithStaticConfiguration.java | 3 +-
.../e2e/metastore/TestMetastoreEndToEnd.java | 6 +-
sentry-tests/sentry-tests-solr/pom.xml | 8 ++
18 files changed, 230 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sentry/blob/5f64fe9f/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 6487a26..d863627 100644
--- a/pom.xml
+++ b/pom.xml
@@ -72,7 +72,7 @@ limitations under the License.
<guava.version>14.0.1</guava.version>
<hadoop.version>2.7.2</hadoop.version>
<hamcrest.version>1.3</hamcrest.version>
- <hive.version>2.0.0</hive.version>
+ <hive.version>2.3.2</hive.version>
<jackson.version>1.8.8</jackson.version>
<jdo-api.version>3.0.1</jdo-api.version>
<jetty.version>9.3.21.v20170918</jetty.version>
http://git-wip-us.apache.org/repos/asf/sentry/blob/5f64fe9f/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageDeserializer.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageDeserializer.java b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageDeserializer.java
index d11b261..929ac8c 100644
--- a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageDeserializer.java
+++ b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageDeserializer.java
@@ -19,6 +19,11 @@
package org.apache.sentry.binding.metastore.messaging.json;
import org.apache.hive.hcatalog.messaging.*;
+import org.apache.hive.hcatalog.messaging.json.JSONAlterIndexMessage;
+import org.apache.hive.hcatalog.messaging.json.JSONCreateFunctionMessage;
+import org.apache.hive.hcatalog.messaging.json.JSONCreateIndexMessage;
+import org.apache.hive.hcatalog.messaging.json.JSONDropFunctionMessage;
+import org.apache.hive.hcatalog.messaging.json.JSONDropIndexMessage;
import org.apache.hive.hcatalog.messaging.json.JSONInsertMessage;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
@@ -130,13 +135,81 @@ public class SentryJSONMessageDeserializer extends MessageDeserializer {
}
/**
+ * Method to de-serialize CreateFunctionMessage instance.
+ */
+ @Override
+ public CreateFunctionMessage getCreateFunctionMessage(String messageBody) {
+ // Sentry does not need this message, but it needs to be implemented so that Hive can
+ // complete the notification log for such event.
+ try {
+ return mapper.readValue(messageBody, JSONCreateFunctionMessage.class);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Could not construct JSONCreateFunctionMessage: ", e);
+ }
+ }
+
+ /**
+ * Method to de-serialize DropFunctionMessage instance.
+ */
+ @Override
+ public DropFunctionMessage getDropFunctionMessage(String messageBody) {
+ // Sentry does not need this message, but it needs to be implemented so that Hive can
+ // complete the notification log for such event.
+ try {
+ return mapper.readValue(messageBody, JSONDropFunctionMessage.class);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Could not construct JSONDropDatabaseMessage: ", e);
+ }
+ }
+
+ /**
+ * Method to de-serialize CreateIndexMessage instance. + */
+ @Override
+ public CreateIndexMessage getCreateIndexMessage(String messageBody) {
+ // Sentry does not need this message, but it needs to be implemented so that Hive can
+ // complete the notification log for such event.
+ try {
+ return mapper.readValue(messageBody, JSONCreateIndexMessage.class);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Could not construct JSONCreateIndexMessage: ", e);
+ }
+ }
+
+ /**
+ * Method to de-serialize DropIndexMessage instance.
+ */
+ @Override
+ public DropIndexMessage getDropIndexMessage(String messageBody) {
+ // Sentry does not need this message, but it needs to be implemented so that Hive can
+ // complete the notification log for such event.
+ try {
+ return mapper.readValue(messageBody, JSONDropIndexMessage.class);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Could not construct JSONDropIndexMessage: ", e);
+ }
+ }
+
+ /**
+ * Method to de-serialize AlterIndexMessage instance.
+ */
+ @Override
+ public AlterIndexMessage getAlterIndexMessage(String messageBody) {
+ // Sentry does not need this message, but it needs to be implemented so that Hive can
+ // complete the notification log for such event.
+ try {
+ return mapper.readValue(messageBody, JSONAlterIndexMessage.class);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Could not construct JSONAlterIndexMessage: ", e);
+ }
+ }
+
+ /**
* Method to de-serialize JSONInsertMessage instance.
*/
@Override
public InsertMessage getInsertMessage(String messageBody) {
- // Sentry would be not be interested in InsertMessage as these are generated when is data is
- // added inserted. This method is implemented for completeness. This is reason why, new sentry
- // JSON class is not defined for InsertMessage.
+ // Sentry does not need this message, but it needs to be implemented so that Hive can
+ // complete the notification log for such event.
try {
return mapper.readValue(messageBody, JSONInsertMessage.class);
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/sentry/blob/5f64fe9f/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageFactory.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageFactory.java b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageFactory.java
index b531976..0af02d1 100644
--- a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageFactory.java
+++ b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageFactory.java
@@ -22,9 +22,16 @@ import com.google.common.collect.Lists;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.metastore.api.Database;
+import org.apache.hadoop.hive.metastore.api.Function;
+import org.apache.hadoop.hive.metastore.api.Index;
import org.apache.hadoop.hive.metastore.api.Partition;
import org.apache.hadoop.hive.metastore.api.Table;
import org.apache.hive.hcatalog.messaging.*;
+import org.apache.hive.hcatalog.messaging.json.JSONAlterIndexMessage;
+import org.apache.hive.hcatalog.messaging.json.JSONCreateFunctionMessage;
+import org.apache.hive.hcatalog.messaging.json.JSONCreateIndexMessage;
+import org.apache.hive.hcatalog.messaging.json.JSONDropFunctionMessage;
+import org.apache.hive.hcatalog.messaging.json.JSONDropIndexMessage;
import org.apache.hive.hcatalog.messaging.json.JSONInsertMessage;
import java.util.*;
@@ -108,6 +115,47 @@ public class SentryJSONMessageFactory extends MessageFactory {
}
@Override
+ public CreateFunctionMessage buildCreateFunctionMessage(Function function) {
+ // Sentry would be not be interested in CreateFunctionMessage as these are generated when is data is
+ // added inserted. This method is implemented for completeness. This is reason why, new sentry
+ // JSON class is not defined for CreateFunctionMessage
+ return new JSONCreateFunctionMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, function, now());
+ }
+
+ @Override
+ public DropFunctionMessage buildDropFunctionMessage(Function function) {
+ // Sentry would be not be interested in DropFunctionMessage as these are generated when is data is
+ // added inserted. This method is implemented for completeness. This is reason why, new sentry
+ // JSON class is not defined for DropFunctionMessage
+ return new JSONDropFunctionMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, function, now());
+
+ }
+
+ @Override
+ public CreateIndexMessage buildCreateIndexMessage(Index index) {
+ // Sentry would be not be interested in CreateIndexMessage as these are generated when is data is
+ // added inserted. This method is implemented for completeness. This is reason why, new sentry
+ // JSON class is not defined for CreateIndexMessage
+ return new JSONCreateIndexMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, index, now());
+ }
+
+ @Override
+ public DropIndexMessage buildDropIndexMessage(Index index) {
+ // Sentry would be not be interested in DropIndexMessage as these are generated when is data is
+ // added inserted. This method is implemented for completeness. This is reason why, new sentry
+ // JSON class is not defined for DropIndexMessage
+ return new JSONDropIndexMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, index, now());
+ }
+
+ @Override
+ public AlterIndexMessage buildAlterIndexMessage(Index before, Index after) {
+ // Sentry would be not be interested in AlterIndexMessage as these are generated when is data is
+ // added inserted. This method is implemented for completeness. This is reason why, new sentry
+ // JSON class is not defined for AlterIndexMessage
+ return new JSONAlterIndexMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, before, after, now());
+ }
+
+ @Override
public InsertMessage buildInsertMessage(String db, String table, Map<String,String> partKeyVals,
List<String> files) {
// Sentry would be not be interested in InsertMessage as these are generated when is data is
http://git-wip-us.apache.org/repos/asf/sentry/blob/5f64fe9f/sentry-binding/sentry-binding-hive/src/main/java/org/apache/hadoop/hive/ql/exec/SentryFilterDDLTask.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/hadoop/hive/ql/exec/SentryFilterDDLTask.java b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/hadoop/hive/ql/exec/SentryFilterDDLTask.java
index 672acb6..efe113e 100644
--- a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/hadoop/hive/ql/exec/SentryFilterDDLTask.java
+++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/hadoop/hive/ql/exec/SentryFilterDDLTask.java
@@ -143,9 +143,6 @@ public class SentryFilterDDLTask extends DDLTask {
parentTasks = ddlTask.getParentTasks();
backupTask = ddlTask.getBackupTask();
backupChildrenTasks = ddlTask.getBackupChildrenTasks();
- started = ddlTask.started();
- isdone = ddlTask.done();
- queued = ddlTask.getQueued();
id = ddlTask.getId();
taskCounters = ddlTask.getCounters();
feedSubscribers = ddlTask.getFeedSubscribers();
@@ -157,5 +154,11 @@ public class SentryFilterDDLTask extends DDLTask {
setException(ddlTask.getException());
console = ddlTask.console;
setFetchSource(ddlTask.isFetchSource());
+ taskHandle = ddlTask.getTaskHandle();
+ conf = ddlTask.conf;
+ queryState = ddlTask.queryState;
+ driverContext = ddlTask.getDriverContext();
+ clonedConf = ddlTask.clonedConf;
+ queryDisplay = ddlTask.queryDisplay;
}
}
http://git-wip-us.apache.org/repos/asf/sentry/blob/5f64fe9f/sentry-binding/sentry-binding-hive/src/main/java/org/apache/hadoop/hive/ql/exec/SentryGrantRevokeTask.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/hadoop/hive/ql/exec/SentryGrantRevokeTask.java b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/hadoop/hive/ql/exec/SentryGrantRevokeTask.java
index 61052cf..21a6abf 100644
--- a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/hadoop/hive/ql/exec/SentryGrantRevokeTask.java
+++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/hadoop/hive/ql/exec/SentryGrantRevokeTask.java
@@ -36,6 +36,7 @@ import org.apache.hadoop.hive.metastore.api.PrincipalType;
import org.apache.hadoop.hive.ql.CompilationOpContext;
import org.apache.hadoop.hive.ql.DriverContext;
import org.apache.hadoop.hive.ql.QueryPlan;
+import org.apache.hadoop.hive.ql.QueryState;
import org.apache.hadoop.hive.ql.hooks.ReadEntity;
import org.apache.hadoop.hive.ql.hooks.WriteEntity;
import org.apache.hadoop.hive.ql.metadata.AuthorizationException;
@@ -109,11 +110,11 @@ public class SentryGrantRevokeTask extends Task<DDLWork> implements Serializable
private HiveOperation stmtOperation;
@Override
- public void initialize(HiveConf conf, QueryPlan queryPlan, DriverContext ctx,
+ public void initialize(QueryState queryState, QueryPlan queryPlan, DriverContext ctx,
CompilationOpContext opContext) {
// CompilationOpContext is an unused parameter on the initialize() method.
- super.initialize(conf, queryPlan, driverContext, null);
- this.conf = conf;
+ super.initialize(queryState, queryPlan, driverContext, null);
+ this.conf = queryState.getConf();
}
@Override
http://git-wip-us.apache.org/repos/asf/sentry/blob/5f64fe9f/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/HiveAuthzBindingHook.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/HiveAuthzBindingHook.java b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/HiveAuthzBindingHook.java
index 802bf9c..e4620ea 100644
--- a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/HiveAuthzBindingHook.java
+++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/HiveAuthzBindingHook.java
@@ -291,7 +291,7 @@ public class HiveAuthzBindingHook extends HiveAuthzBindingHookBase {
@Override
public void postAnalyze(HiveSemanticAnalyzerHookContext context,
List<Task<? extends Serializable>> rootTasks) throws SemanticException {
- HiveOperation stmtOperation = getCurrentHiveStmtOp();
+ HiveOperation stmtOperation = context.getHiveOperation();
HiveAuthzPrivileges stmtAuthObject;
stmtAuthObject = HiveAuthzPrivilegesMap.getHiveAuthzPrivileges(stmtOperation);
http://git-wip-us.apache.org/repos/asf/sentry/blob/5f64fe9f/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/DefaultSentryValidator.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/DefaultSentryValidator.java b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/DefaultSentryValidator.java
index d1f071e..319a1be 100644
--- a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/DefaultSentryValidator.java
+++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/DefaultSentryValidator.java
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Set;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.metadata.AuthorizationException;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
import org.apache.hadoop.hive.ql.plan.HiveOperation;
import org.apache.hadoop.hive.ql.security.HiveAuthenticationProvider;
import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAccessControlException;
@@ -375,6 +376,22 @@ public class DefaultSentryValidator extends SentryHiveAuthorizationValidator {
return listObjs;
}
+ @Override
+ public List<HivePrivilegeObject> applyRowFilterAndColumnMasking(HiveAuthzContext hiveAuthzContext,
+ List<HivePrivilegeObject> list) throws SemanticException {
+ // Sentry does not support this feature yet. Returning null is enough to let Hive
+ // that no row filtering nor column masking will be applied.
+ return null;
+ }
+
+ @Override
+ public boolean needTransform() {
+ // Hive uses this value to know whether a Hive query must be transformed if row filtering
+ // or column masking is applied. Sentry does not support such feature yet, so returning
+ // false is enough to let Hive know that the query is not required to be transformed.
+ return false;
+ }
+
private List<HivePrivilegeObject> filterShowTables(List<HivePrivilegeObject> listObjs,
String userName, HiveAuthzBinding hiveAuthzBinding) {
List<HivePrivilegeObject> filteredResult = new ArrayList<HivePrivilegeObject>();
http://git-wip-us.apache.org/repos/asf/sentry/blob/5f64fe9f/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/HiveAuthzBindingHookBase.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/HiveAuthzBindingHookBase.java b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/HiveAuthzBindingHookBase.java
index 2e299a9..9c60c22 100644
--- a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/HiveAuthzBindingHookBase.java
+++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/HiveAuthzBindingHookBase.java
@@ -886,18 +886,8 @@ public abstract class HiveAuthzBindingHookBase extends AbstractSemanticAnalyzerH
}
}
- protected HiveOperation getCurrentHiveStmtOp() {
- SessionState sessState = SessionState.get();
- if (sessState == null) {
- // TODO: Warn
- return null;
- }
- return sessState.getHiveOperation();
- }
-
protected Subject getCurrentSubject(HiveSemanticAnalyzerHookContext context) {
// Extract the username from the hook context
return new Subject(context.getUserName());
}
-
}
http://git-wip-us.apache.org/repos/asf/sentry/blob/5f64fe9f/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryHiveAuthorizerImpl.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryHiveAuthorizerImpl.java b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryHiveAuthorizerImpl.java
index 1596bce..86ff0cc 100644
--- a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryHiveAuthorizerImpl.java
+++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryHiveAuthorizerImpl.java
@@ -20,11 +20,13 @@ import java.util.List;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.exec.SentryHivePrivilegeObjectDesc;
import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
import org.apache.hadoop.hive.ql.plan.PrivilegeObjectDesc;
import org.apache.hadoop.hive.ql.security.authorization.DefaultHiveAuthorizationTranslator;
import org.apache.hadoop.hive.ql.security.authorization.plugin.AbstractHiveAuthorizer;
import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAccessControlException;
import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthorizationTranslator;
+import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthorizer.VERSION;
import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzContext;
import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzPluginException;
import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveOperationType;
@@ -165,6 +167,17 @@ public class SentryHiveAuthorizerImpl extends AbstractHiveAuthorizer {
return hiveTranslator;
}
+ @Override
+ public List<HivePrivilegeObject> applyRowFilterAndColumnMasking(HiveAuthzContext hiveAuthzContext,
+ List<HivePrivilegeObject> list) throws SemanticException {
+ return null;
+ }
+
+ @Override
+ public boolean needTransform() {
+ return false;
+ }
+
protected static HivePrivilegeObjectType getPrivObjectType(
SentryHivePrivilegeObjectDesc privSubjectDesc) {
if (privSubjectDesc.getObject() == null) {
http://git-wip-us.apache.org/repos/asf/sentry/blob/5f64fe9f/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/metastore/SentryHiveMetaStoreClient.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/metastore/SentryHiveMetaStoreClient.java b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/metastore/SentryHiveMetaStoreClient.java
index cfc5c04..e30a860 100644
--- a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/metastore/SentryHiveMetaStoreClient.java
+++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/metastore/SentryHiveMetaStoreClient.java
@@ -49,7 +49,7 @@ public class SentryHiveMetaStoreClient extends HiveMetaStoreClient implements
public SentryHiveMetaStoreClient(HiveConf conf, HiveMetaHookLoader hookLoader)
throws MetaException {
- super(conf, hookLoader);
+ super(conf, hookLoader, true);
}
@Override
http://git-wip-us.apache.org/repos/asf/sentry/blob/5f64fe9f/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestSentryHiveAuthorizationTaskFactory.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestSentryHiveAuthorizationTaskFactory.java b/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestSentryHiveAuthorizationTaskFactory.java
index de073ed..c75f57d 100644
--- a/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestSentryHiveAuthorizationTaskFactory.java
+++ b/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestSentryHiveAuthorizationTaskFactory.java
@@ -22,6 +22,7 @@ import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
+import org.apache.hadoop.hive.ql.QueryState;
import org.junit.Assert;
import org.apache.commons.io.FileUtils;
@@ -37,7 +38,6 @@ import org.apache.hadoop.hive.ql.metadata.Partition;
import org.apache.hadoop.hive.ql.metadata.Table;
import org.apache.hadoop.hive.ql.parse.ASTNode;
import org.apache.hadoop.hive.ql.parse.DDLSemanticAnalyzer;
-import org.apache.hadoop.hive.ql.parse.ParseDriver;
import org.apache.hadoop.hive.ql.parse.ParseUtils;
import org.apache.hadoop.hive.ql.parse.SemanticException;
import org.apache.hadoop.hive.ql.plan.DDLWork;
@@ -70,7 +70,6 @@ public class TestSentryHiveAuthorizationTaskFactory {
private static final String SERVER = "server1";
- private ParseDriver parseDriver;
private DDLSemanticAnalyzer analyzer;
private HiveConf conf;
private Context context;
@@ -91,12 +90,19 @@ public class TestSentryHiveAuthorizationTaskFactory {
conf.setVar(ConfVars.HIVE_AUTHORIZATION_TASK_FACTORY,
SentryHiveAuthorizationTaskFactoryImpl.class.getName());
+ // This configuration avoids starting the HS2 WebUI which was causes test failures when
+ // HS2 is configured for concurrency
+ conf.setBoolVar(HiveConf.ConfVars.HIVE_IN_TEST, true);
+
+ // This configuration avoids that the HMS fails if the Metastore schema has not version
+ // information. For some reason, HMS does not set a version initially on our tests.
+ conf.setBoolVar(HiveConf.ConfVars.METASTORE_SCHEMA_VERIFICATION, false);
+
db = Mockito.mock(Hive.class);
table = new Table(DB, TABLE);
partition = new Partition(table);
context = new Context(conf);
- parseDriver = new ParseDriver();
- analyzer = new DDLSemanticAnalyzer(conf, db);
+ analyzer = new DDLSemanticAnalyzer(new QueryState(conf), db);
SessionState.start(conf);
Mockito.when(db.getTable(TABLE, false)).thenReturn(table);
Mockito.when(db.getPartition(table, new HashMap<String, String>(), false))
@@ -487,7 +493,7 @@ public class TestSentryHiveAuthorizationTaskFactory {
}
private ASTNode parse(String command) throws Exception {
- return ParseUtils.findRootNonNullToken(parseDriver.parse(command));
+ return ParseUtils.parse(command);
}
private DDLWork analyze(ASTNode ast) throws Exception {
http://git-wip-us.apache.org/repos/asf/sentry/blob/5f64fe9f/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegrationAdvanced.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegrationAdvanced.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegrationAdvanced.java
index 95bbaeb..33ace57 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegrationAdvanced.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegrationAdvanced.java
@@ -791,7 +791,14 @@ public class TestHDFSIntegrationAdvanced extends TestHDFSIntegrationBase {
// Alter table tab1 to be tbCopy which is at scheme-less location.
// And the corresponding path will be updated to sentry server.
hmsClient.alter_table(dbName, "tab1", tbCopy);
- Assert.assertEquals(hmsClient.getTable(dbName, tblName).getSd().getLocation(), "/tmp/external");
+
+ // Remove the checking for the location of the table. The HMS will never return scheme-less
+ // URI locations anymore. However, if any NPE being triggered in future because of any changes,
+ // the test case will cover it and capture it.
+ // i.e. hdfs://<localhost>/tmp/external (location with scheme)
+ // /tmp/external (location without scheme)
+ // Assert.assertEquals("/tmp/external", hmsClient.getTable(dbName, tblName).getSd().getLocation());
+
verifyOnPath("/tmp/external", FsAction.ALL, StaticUserGroup.HIVE, true);
stmt.close();
http://git-wip-us.apache.org/repos/asf/sentry/blob/5f64fe9f/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegrationBase.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegrationBase.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegrationBase.java
index 7495fc7..25a678b 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegrationBase.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegrationBase.java
@@ -575,6 +575,10 @@ public abstract class TestHDFSIntegrationBase {
String hadoopTempDir = System.getProperty("java.io.tmpdir") + File.separator + "hadoop-tmp";
hiveConf.set("hadoop.tmp.dir", hadoopTempDir);
+ // This configuration will avoid that the HMS fails if the metastore schema has not version
+ // information. For some reason, HMS does not set a version initially on our tests.
+ hiveConf.set(ConfVars.METASTORE_SCHEMA_VERIFICATION.varname, "false");
+
// Sets hive.metastore.authorization.storage.checks to true, so that
// disallow the operations such as drop-partition if the user in question
// doesn't have permissions to delete the corresponding directory
http://git-wip-us.apache.org/repos/asf/sentry/blob/5f64fe9f/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtColumnScope.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtColumnScope.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtColumnScope.java
index c2fee2a..9d820a8 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtColumnScope.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtColumnScope.java
@@ -205,12 +205,13 @@ public class TestPrivilegesAtColumnScope extends AbstractTestWithStaticConfigura
context.verifyAuthzException(e);
}
- // negative test: test user can't query column of view
+ // positive test: test user can query column of view
+ // Hive 2 adds a new column view authorization as part of the Column Pruning feature
+ // See Hive ColumnPrunerSelectProc.process() on how view authorization is handled
try {
statement.execute("SELECT COUNT(A) FROM VIEW_1");
- Assert.fail("Expected SQL exception");
} catch (SQLException e) {
- context.verifyAuthzException(e);
+ Assert.fail("Exception not expected.");
}
// negative test: test user can't query column of view
try {
@@ -255,18 +256,18 @@ public class TestPrivilegesAtColumnScope extends AbstractTestWithStaticConfigura
context.verifyAuthzException(e);
}
- // negative test: test user can't query view
+ // positive test: test user can query column of view
+ // Hive 2 adds a new column view authorization as part of the Column Pruning feature
+ // See Hive ColumnPrunerSelectProc.process() on how view authorization is handled
try {
statement.execute("SELECT COUNT(A) FROM VIEW_1");
- Assert.fail("Expected SQL exception");
} catch (SQLException e) {
- context.verifyAuthzException(e);
+ Assert.fail("Exception not expected.");
}
try {
statement.execute("SELECT COUNT(B) FROM VIEW_1");
- Assert.fail("Expected SQL exception");
} catch (SQLException e) {
- context.verifyAuthzException(e);
+ Assert.fail("Exception not expected.");
}
// negative test: test user can't create a new view
@@ -378,12 +379,13 @@ public class TestPrivilegesAtColumnScope extends AbstractTestWithStaticConfigura
Statement statement = context.createStatement(connection);
statement.execute("USE DB_1");
- // test user can't execute query VIEW_1 JOIN VIEW_2
+ // test user can execute query VIEW_1 JOIN VIEW_2
+ // Hive 2 adds a new column view authorization as part of the Column Pruning feature
+ // See Hive ColumnPrunerSelectProc.process() on how view authorization is handled
try {
statement.execute("SELECT COUNT(*) FROM VIEW_1 V1 JOIN VIEW_2 V2 ON (V1.B = V2.B)");
- Assert.fail("Expected SQL Exception");
} catch (SQLException e) {
- context.verifyAuthzException(e);
+ Assert.fail("Exception not expected");
}
// test user can't execute query VIEW_1 JOIN TAB_2
@@ -438,12 +440,13 @@ public class TestPrivilegesAtColumnScope extends AbstractTestWithStaticConfigura
context.verifyAuthzException(e);
}
- // test user can't execute query VIEW_1 JOIN VIEW_2
+ // test user can execute query VIEW_1 JOIN VIEW_2
+ // Hive 2 adds a new column view authorization as part of the Column Pruning feature
+ // See Hive ColumnPrunerSelectProc.process() on how view authorization is handled
try {
statement.execute("SELECT COUNT(*) FROM VIEW_1 V1 JOIN VIEW_2 V2 ON (V1.B = V2.B)");
- Assert.fail("Expected SQL Exception");
} catch (SQLException e) {
- context.verifyAuthzException(e);
+ Assert.fail("Exception not expected");
}
// test user can't execute query TAB_1 JOIN TAB_2
http://git-wip-us.apache.org/repos/asf/sentry/blob/5f64fe9f/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/hiveserver/HiveServerFactory.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/hiveserver/HiveServerFactory.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/hiveserver/HiveServerFactory.java
index d5eb137..7d41348 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/hiveserver/HiveServerFactory.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/hiveserver/HiveServerFactory.java
@@ -206,6 +206,16 @@ public class HiveServerFactory {
String hadoopTempDir = System.getProperty("java.io.tmpdir") + File.separator + "hadoop-tmp";
properties.put("hadoop.tmp.dir", hadoopTempDir);
+ // This configuration will avoid that the HMS fails if the metastore schema has not version
+ // information. For some reason, HMS does not set a version initially on our tests.
+ properties.put(ConfVars.METASTORE_SCHEMA_VERIFICATION.varname, "false");
+
+ // Disable join cartesian checks to allow Sentry tests to pass
+ properties.put(ConfVars.HIVE_STRICT_CHECKS_CARTESIAN.varname, "false");
+
+ // Disable capability checks (these checks do not work when Hive is in testing mode)
+ properties.put(ConfVars.METASTORE_CAPABILITY_CHECK.varname, "false");
+
if (!properties.containsKey(METASTORE_BYPASS)) {
properties.put(METASTORE_BYPASS, "hive,impala," + System.getProperty("user.name", ""));
} else {
http://git-wip-us.apache.org/repos/asf/sentry/blob/5f64fe9f/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/AbstractMetastoreTestWithStaticConfiguration.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/AbstractMetastoreTestWithStaticConfiguration.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/AbstractMetastoreTestWithStaticConfiguration.java
index d0139ad..f14cbb6 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/AbstractMetastoreTestWithStaticConfiguration.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/AbstractMetastoreTestWithStaticConfiguration.java
@@ -28,6 +28,7 @@ import org.apache.hadoop.hive.cli.CliSessionState;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
import org.apache.hadoop.hive.metastore.api.Database;
+import org.apache.hadoop.hive.metastore.api.EnvironmentContext;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
import org.apache.hadoop.hive.metastore.api.Order;
import org.apache.hadoop.hive.metastore.api.Partition;
@@ -138,7 +139,7 @@ public abstract class AbstractMetastoreTestWithStaticConfiguration extends
public void alterPartitionWithLocation(HiveMetaStoreClient client, Partition partition, String location) throws Exception {
partition.getSd().setLocation(location);
- client.alter_partition(partition.getDbName(), partition.getTableName(), partition);
+ client.alter_partition(partition.getDbName(), partition.getTableName(), partition, new EnvironmentContext());
}
public void renamePartition(HiveMetaStoreClient client, Partition partition, Partition newPartition) throws Exception {
http://git-wip-us.apache.org/repos/asf/sentry/blob/5f64fe9f/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/TestMetastoreEndToEnd.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/TestMetastoreEndToEnd.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/TestMetastoreEndToEnd.java
index 7f53527..f8f304f 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/TestMetastoreEndToEnd.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/TestMetastoreEndToEnd.java
@@ -507,14 +507,14 @@ public class TestMetastoreEndToEnd extends
client = context.getMetaStoreClient(USER1_1);
Partition newPartition = client.getPartition(dbName, tabName1, partVals1);
newPartition.getSd().setLocation(tabDir1);
- client.alter_partition(dbName, tabName1, newPartition);
+ client.alter_partition(dbName, tabName1, newPartition, null);
client.close();
// user with Table and URI privileges should be able to alter partition set location
client = context.getMetaStoreClient(USER2_1);
newPartition = client.getPartition(dbName, tabName1, partVals2);
newPartition.getSd().setLocation(tabDir1);
- client.alter_partition(dbName, tabName1, newPartition);
+ client.alter_partition(dbName, tabName1, newPartition, null);
client.close();
policyFile.addRolesToGroup(USERGROUP3, db_all_role);
@@ -524,7 +524,7 @@ public class TestMetastoreEndToEnd extends
newPartition = client.getPartition(dbName, tabName1, partVals2);
newPartition.getSd().setLocation(tabDir1);
try {
- client.alter_partition(dbName, tabName1, newPartition);
+ client.alter_partition(dbName, tabName1, newPartition, null);
fail("alter partition with location should have failed");
} catch (MetaException e) {
Context.verifyMetastoreAuthException(e);
http://git-wip-us.apache.org/repos/asf/sentry/blob/5f64fe9f/sentry-tests/sentry-tests-solr/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-solr/pom.xml b/sentry-tests/sentry-tests-solr/pom.xml
index 723fa9d..9d400b2 100644
--- a/sentry-tests/sentry-tests-solr/pom.xml
+++ b/sentry-tests/sentry-tests-solr/pom.xml
@@ -110,6 +110,10 @@ limitations under the License.
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-shims</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
@@ -195,6 +199,10 @@ limitations under the License.
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-all</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>org.apache.hive</groupId>
+ <artifactId>hive-llap-server</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
[2/9] sentry git commit: Revert "SENTRY-2012 - Make
SentryShellGeneric extendible. Mano Kovacs, reviewed by Colm O hEigeartaigh."
Posted by co...@apache.org.
Revert "SENTRY-2012 - Make SentryShellGeneric extendible. Mano Kovacs, reviewed by Colm O hEigeartaigh."
This reverts commit 2314e465496114444d83cec7dced60f482670179.
Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/5fc1e977
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/5fc1e977
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/5fc1e977
Branch: refs/heads/akolb-cli
Commit: 5fc1e97790936ff0002fbebc156fccd06b4a9014
Parents: 2314e46
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Fri Nov 17 13:12:33 2017 +0000
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Fri Nov 17 13:12:33 2017 +0000
----------------------------------------------------------------------
bin/sentryShell | 6 +-
.../common/AbstractAuthorizableFactory.java | 72 ------
.../sentry/core/common/AuthorizableFactory.java | 50 -----
.../sentry/core/common/AuthorizableType.java | 21 --
.../core/model/kafka/KafkaAuthorizable.java | 2 +-
.../model/kafka/KafkaModelAuthorizables.java | 27 ++-
.../core/model/solr/SolrModelAuthorizable.java | 6 +-
.../core/model/solr/SolrModelAuthorizables.java | 52 +++--
.../core/model/sqoop/SqoopAuthorizable.java | 2 +-
.../model/sqoop/SqoopModelAuthorizables.java | 50 +++--
.../tools/GenericPrivilegeConverter.java | 96 ++++----
.../db/generic/tools/SentryConfigToolSolr.java | 9 +-
.../db/generic/tools/SentryShellGeneric.java | 51 +++--
.../db/generic/tools/SentryShellKafka.java | 71 ------
.../db/generic/tools/SentryShellSolr.java | 52 -----
.../db/generic/tools/SentryShellSqoop.java | 52 -----
.../generic/tools/TestSentryConfigToolSolr.java | 9 +-
.../db/generic/tools/TestSentryShellKafka.java | 207 +++++++++--------
.../db/generic/tools/TestSentryShellSolr.java | 224 ++++++++++---------
.../db/generic/tools/TestSentryShellSqoop.java | 164 +++++++-------
20 files changed, 473 insertions(+), 750 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/bin/sentryShell
----------------------------------------------------------------------
diff --git a/bin/sentryShell b/bin/sentryShell
index d7a53b8..17b1429 100755
--- a/bin/sentryShell
+++ b/bin/sentryShell
@@ -60,9 +60,9 @@ while [ $# -gt 0 ]; do # Until you run out of parameters . . .
if [[ "$1" = "-t" || "$1" = "--type" ]]; then
case $2 in
"hive") shell=org.apache.sentry.provider.db.tools.SentryShellHive ;;
- "kafka") shell=org.apache.sentry.provider.db.generic.tools.SentryShellKafka ;;
- "solr") shell=org.apache.sentry.provider.db.generic.tools.SentryShellSolr ;;
- "sqoop") shell=org.apache.sentry.provider.db.generic.tools.SentryShellSqoop;;
+ "kafka") shell=org.apache.sentry.provider.db.generic.tools.SentryShellGeneric ;;
+ "solr") shell=org.apache.sentry.provider.db.generic.tools.SentryShellGeneric ;;
+ "sqoop") shell=org.apache.sentry.provider.db.generic.tools.SentryShellGeneric ;;
*) echo "Doesn't support the type $2!"; exit 1 ;;
esac
fi
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/AbstractAuthorizableFactory.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/AbstractAuthorizableFactory.java b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/AbstractAuthorizableFactory.java
deleted file mode 100644
index 14bf2df..0000000
--- a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/AbstractAuthorizableFactory.java
+++ /dev/null
@@ -1,72 +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.core.common;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import org.apache.sentry.core.common.utils.SentryConstants;
-
-import java.util.List;
-
-/**
- * @param <A> The type of Authorizable the class handles
- */
-public abstract class AbstractAuthorizableFactory<A extends Authorizable, T extends AuthorizableType<A>> implements AuthorizableFactory<A, T> {
-
- @Override
- public A create(String s) {
- List<String> kvList = Lists.newArrayList(SentryConstants.KV_SPLITTER.trimResults().limit(2).split(s));
- if (kvList.size() != 2) {
- throw new IllegalArgumentException("Invalid authorizable string value: " + s + " " + kvList);
- }
-
- String type;
- String name;
-
- type = kvList.get(0);
- Preconditions.checkArgument(!type.isEmpty(), "Type cannot be empty");
- name = kvList.get(1);
- Preconditions.checkArgument(!name.isEmpty(), "Name cannot be empty");
- try {
- return create(type, name);
- } catch (IllegalArgumentException e) {
- return null;
- }
- }
-
- @Override
- public A create(String type, String name) {
- T typeObject = getType(type);
- if (typeObject == null) {
- return null;
- } else {
- return create(typeObject, name);
- }
- }
-
- private T getType(String typeName) {
- for (T type : getTypes()) {
- if (typeName.equalsIgnoreCase(type.name())) {
- return type;
- }
- }
- return null;
- }
-
- protected abstract T[] getTypes();
-
-}
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/AuthorizableFactory.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/AuthorizableFactory.java b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/AuthorizableFactory.java
deleted file mode 100644
index 9d3b5e0..0000000
--- a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/AuthorizableFactory.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sentry.core.common;
-
-import javax.annotation.Nullable;
-
-/**
- * Interface for factory class for creating authorizable objects from strings or type-name pairs.
- *
- * @param <A> Type of the Authorizable the implementation handles
- */
-public interface AuthorizableFactory<A extends Authorizable, T extends AuthorizableType<A>> {
- /**
- * Parses authorizable and returns it. If s is unknown authorizable, it returns null.
- * @param s type=name format of authorizable
- * @return
- */
- @Nullable
- A create(String s);
-
- /**
- * Returns authorizable based on type and name
- * @param type
- * @param name
- * @return
- */
- A create(String type, String name);
-
- /**
- * Returns authorizable based on type and name
- * @param type
- * @param name
- * @return
- */
- A create(T type, String name);
-}
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/AuthorizableType.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/AuthorizableType.java b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/AuthorizableType.java
deleted file mode 100644
index 71cc6dd..0000000
--- a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/AuthorizableType.java
+++ /dev/null
@@ -1,21 +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.core.common;
-
-public interface AuthorizableType<T extends Authorizable> {
- String name();
-}
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-core/sentry-core-model-kafka/src/main/java/org/apache/sentry/core/model/kafka/KafkaAuthorizable.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-model-kafka/src/main/java/org/apache/sentry/core/model/kafka/KafkaAuthorizable.java b/sentry-core/sentry-core-model-kafka/src/main/java/org/apache/sentry/core/model/kafka/KafkaAuthorizable.java
index 269572c..52ae614 100644
--- a/sentry-core/sentry-core-model-kafka/src/main/java/org/apache/sentry/core/model/kafka/KafkaAuthorizable.java
+++ b/sentry-core/sentry-core-model-kafka/src/main/java/org/apache/sentry/core/model/kafka/KafkaAuthorizable.java
@@ -44,7 +44,7 @@ public interface KafkaAuthorizable extends Authorizable {
/**
* Types of resources that Kafka supports authorization on.
*/
- enum AuthorizableType implements org.apache.sentry.core.common.AuthorizableType<KafkaAuthorizable>{
+ public enum AuthorizableType {
CLUSTER,
HOST,
TOPIC,
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-core/sentry-core-model-kafka/src/main/java/org/apache/sentry/core/model/kafka/KafkaModelAuthorizables.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-model-kafka/src/main/java/org/apache/sentry/core/model/kafka/KafkaModelAuthorizables.java b/sentry-core/sentry-core-model-kafka/src/main/java/org/apache/sentry/core/model/kafka/KafkaModelAuthorizables.java
index 57a4e20..45a1148 100644
--- a/sentry-core/sentry-core-model-kafka/src/main/java/org/apache/sentry/core/model/kafka/KafkaModelAuthorizables.java
+++ b/sentry-core/sentry-core-model-kafka/src/main/java/org/apache/sentry/core/model/kafka/KafkaModelAuthorizables.java
@@ -16,19 +16,27 @@
*/
package org.apache.sentry.core.model.kafka;
-import org.apache.sentry.core.common.AbstractAuthorizableFactory;
+import org.apache.sentry.core.common.utils.KeyValue;
+import org.apache.sentry.core.model.kafka.KafkaAuthorizable.AuthorizableType;
import org.apache.shiro.config.ConfigurationException;
-public class KafkaModelAuthorizables extends AbstractAuthorizableFactory<KafkaAuthorizable, KafkaAuthorizable.AuthorizableType> {
- private static final KafkaModelAuthorizables instance = new KafkaModelAuthorizables();
-
+public class KafkaModelAuthorizables {
+ public static KafkaAuthorizable from(KeyValue keyValue) throws ConfigurationException {
+ String prefix = keyValue.getKey().toLowerCase();
+ String name = keyValue.getValue();
+ for (AuthorizableType type : AuthorizableType.values()) {
+ if (prefix.equalsIgnoreCase(type.name())) {
+ return from(type, name);
+ }
+ }
+ return null;
+ }
public static KafkaAuthorizable from(String keyValue) throws ConfigurationException {
- return instance.create(keyValue);
+ return from(new KeyValue(keyValue));
}
- @Override
- public KafkaAuthorizable create(KafkaAuthorizable.AuthorizableType type, String name) throws ConfigurationException {
+ public static KafkaAuthorizable from(AuthorizableType type, String name) throws ConfigurationException {
switch (type) {
case HOST:
return new Host(name);
@@ -46,9 +54,4 @@ public class KafkaModelAuthorizables extends AbstractAuthorizableFactory<KafkaAu
return null;
}
}
-
- @Override
- protected KafkaAuthorizable.AuthorizableType[] getTypes() {
- return KafkaAuthorizable.AuthorizableType.values();
- }
}
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-core/sentry-core-model-solr/src/main/java/org/apache/sentry/core/model/solr/SolrModelAuthorizable.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-model-solr/src/main/java/org/apache/sentry/core/model/solr/SolrModelAuthorizable.java b/sentry-core/sentry-core-model-solr/src/main/java/org/apache/sentry/core/model/solr/SolrModelAuthorizable.java
index 9eb10c3..56cb4c2 100644
--- a/sentry-core/sentry-core-model-solr/src/main/java/org/apache/sentry/core/model/solr/SolrModelAuthorizable.java
+++ b/sentry-core/sentry-core-model-solr/src/main/java/org/apache/sentry/core/model/solr/SolrModelAuthorizable.java
@@ -22,15 +22,13 @@ import com.google.common.annotations.VisibleForTesting;
public abstract class SolrModelAuthorizable implements Authorizable {
- public enum AuthorizableType implements org.apache.sentry.core.common.AuthorizableType<SolrModelAuthorizable> {
+ public enum AuthorizableType {
Collection,
Field,
Admin,
Config,
Schema
- }
-
- ;
+ };
private final AuthorizableType type;
private final String name;
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-core/sentry-core-model-solr/src/main/java/org/apache/sentry/core/model/solr/SolrModelAuthorizables.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-model-solr/src/main/java/org/apache/sentry/core/model/solr/SolrModelAuthorizables.java b/sentry-core/sentry-core-model-solr/src/main/java/org/apache/sentry/core/model/solr/SolrModelAuthorizables.java
index 09255e7..7979b33 100644
--- a/sentry-core/sentry-core-model-solr/src/main/java/org/apache/sentry/core/model/solr/SolrModelAuthorizables.java
+++ b/sentry-core/sentry-core-model-solr/src/main/java/org/apache/sentry/core/model/solr/SolrModelAuthorizables.java
@@ -16,39 +16,43 @@
*/
package org.apache.sentry.core.model.solr;
-import org.apache.sentry.core.common.AbstractAuthorizableFactory;
+import org.apache.sentry.core.common.utils.KeyValue;
import org.apache.sentry.core.model.solr.SolrModelAuthorizable.AuthorizableType;
-public class SolrModelAuthorizables extends AbstractAuthorizableFactory<SolrModelAuthorizable, AuthorizableType> {
- private static final SolrModelAuthorizables instance = new SolrModelAuthorizables();
+public class SolrModelAuthorizables {
- public static SolrModelAuthorizable from(String s) {
- return instance.create(s);
+ private SolrModelAuthorizables() {
+ // Make constructor private to avoid instantiation
}
- public SolrModelAuthorizable create(SolrModelAuthorizable.AuthorizableType type, String name) {
+ public static SolrModelAuthorizable from(KeyValue keyValue) {
+ String prefix = keyValue.getKey().toLowerCase();
+ String name = keyValue.getValue().toLowerCase();
SolrModelAuthorizable result = null;
- switch (type) {
- case Collection:
- result = new Collection(name);
- break;
- case Admin:
- result = new AdminOperation(name);
- break;
- case Config:
- result = new Config(name);
- break;
- case Schema:
- result = new Schema(name);
- break;
- default:
- break;
+ for(AuthorizableType type : AuthorizableType.values()) {
+ if(prefix.equalsIgnoreCase(type.name())) {
+ switch (type) {
+ case Collection:
+ result = new Collection(name);
+ break;
+ case Admin:
+ result = new AdminOperation(name);
+ break;
+ case Config:
+ result = new Config(name);
+ break;
+ case Schema:
+ result = new Schema(name);
+ break;
+ default:
+ break;
+ }
+ }
}
return result;
}
- @Override
- protected SolrModelAuthorizable.AuthorizableType[] getTypes() {
- return SolrModelAuthorizable.AuthorizableType.values();
+ public static SolrModelAuthorizable from(String s) {
+ return from(new KeyValue(s));
}
}
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-core/sentry-core-model-sqoop/src/main/java/org/apache/sentry/core/model/sqoop/SqoopAuthorizable.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-model-sqoop/src/main/java/org/apache/sentry/core/model/sqoop/SqoopAuthorizable.java b/sentry-core/sentry-core-model-sqoop/src/main/java/org/apache/sentry/core/model/sqoop/SqoopAuthorizable.java
index f060d27..934875e 100644
--- a/sentry-core/sentry-core-model-sqoop/src/main/java/org/apache/sentry/core/model/sqoop/SqoopAuthorizable.java
+++ b/sentry-core/sentry-core-model-sqoop/src/main/java/org/apache/sentry/core/model/sqoop/SqoopAuthorizable.java
@@ -24,7 +24,7 @@ import org.apache.sentry.core.common.Authorizable;
*/
public interface SqoopAuthorizable extends Authorizable {
String ALL = "*";
- enum AuthorizableType implements org.apache.sentry.core.common.AuthorizableType<SqoopAuthorizable> {
+ public enum AuthorizableType {
SERVER,
CONNECTOR,
LINK,
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-core/sentry-core-model-sqoop/src/main/java/org/apache/sentry/core/model/sqoop/SqoopModelAuthorizables.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-model-sqoop/src/main/java/org/apache/sentry/core/model/sqoop/SqoopModelAuthorizables.java b/sentry-core/sentry-core-model-sqoop/src/main/java/org/apache/sentry/core/model/sqoop/SqoopModelAuthorizables.java
index 0227fb8..3bb9a19 100644
--- a/sentry-core/sentry-core-model-sqoop/src/main/java/org/apache/sentry/core/model/sqoop/SqoopModelAuthorizables.java
+++ b/sentry-core/sentry-core-model-sqoop/src/main/java/org/apache/sentry/core/model/sqoop/SqoopModelAuthorizables.java
@@ -16,34 +16,42 @@
*/
package org.apache.sentry.core.model.sqoop;
-import org.apache.sentry.core.common.AbstractAuthorizableFactory;
+import org.apache.sentry.core.model.sqoop.SqoopAuthorizable.AuthorizableType;
+import org.apache.sentry.core.common.utils.KeyValue;
-public class SqoopModelAuthorizables extends AbstractAuthorizableFactory<SqoopAuthorizable, SqoopAuthorizable.AuthorizableType> {
+public class SqoopModelAuthorizables {
- private static final SqoopModelAuthorizables instance = new SqoopModelAuthorizables();
+ private SqoopModelAuthorizables() {
+ // Make constructor private to avoid instantiation
+ }
- public static SqoopAuthorizable from(String keyValue) {
- return instance.create(keyValue);
+ public static SqoopAuthorizable from(KeyValue keyValue) {
+ String prefix = keyValue.getKey().toLowerCase();
+ String name = keyValue.getValue().toLowerCase();
+ for (AuthorizableType type : AuthorizableType.values()) {
+ if(prefix.equalsIgnoreCase(type.name())) {
+ return from(type, name);
+ }
+ }
+ return null;
}
+ public static SqoopAuthorizable from(String keyValue) {
+ return from(new KeyValue(keyValue));
+ }
- public SqoopAuthorizable create(SqoopAuthorizable.AuthorizableType type, String name) {
+ public static SqoopAuthorizable from(AuthorizableType type, String name) {
switch(type) {
- case SERVER:
- return new Server(name);
- case JOB:
- return new Job(name);
- case CONNECTOR:
- return new Connector(name);
- case LINK:
- return new Link(name);
- default:
- return null;
+ case SERVER:
+ return new Server(name);
+ case JOB:
+ return new Job(name);
+ case CONNECTOR:
+ return new Connector(name);
+ case LINK:
+ return new Link(name);
+ default:
+ return null;
}
}
-
- @Override
- protected SqoopAuthorizable.AuthorizableType[] getTypes() {
- return SqoopAuthorizable.AuthorizableType.values();
- }
}
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/GenericPrivilegeConverter.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/GenericPrivilegeConverter.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/GenericPrivilegeConverter.java
index e6fa763..c65b66d 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/GenericPrivilegeConverter.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/GenericPrivilegeConverter.java
@@ -18,25 +18,37 @@
package org.apache.sentry.provider.db.generic.tools;
-import com.google.common.base.Function;
+import static org.apache.sentry.core.common.utils.SentryConstants.AUTHORIZABLE_SEPARATOR;
+import static org.apache.sentry.core.common.utils.SentryConstants.KV_SEPARATOR;
+import static org.apache.sentry.core.common.utils.SentryConstants.RESOURCE_WILDCARD_VALUE;
+
import com.google.common.collect.Lists;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
import org.apache.sentry.core.common.Authorizable;
-import org.apache.sentry.core.common.AuthorizableFactory;
import org.apache.sentry.core.common.exception.SentryUserException;
import org.apache.sentry.core.common.utils.KeyValue;
import org.apache.sentry.core.common.utils.PolicyFileConstants;
import org.apache.sentry.core.common.utils.SentryConstants;
import org.apache.sentry.core.common.validator.PrivilegeValidator;
import org.apache.sentry.core.common.validator.PrivilegeValidatorContext;
+import org.apache.sentry.core.model.kafka.KafkaAuthorizable;
+import org.apache.sentry.core.model.kafka.KafkaModelAuthorizables;
+import org.apache.sentry.core.model.kafka.KafkaPrivilegeModel;
+import org.apache.sentry.core.model.solr.SolrModelAuthorizables;
+import org.apache.sentry.core.model.solr.SolrPrivilegeModel;
+import org.apache.sentry.core.model.sqoop.SqoopModelAuthorizables;
+import org.apache.sentry.core.model.sqoop.SqoopPrivilegeModel;
+import org.apache.sentry.provider.common.AuthorizationComponent;
import org.apache.sentry.provider.db.generic.service.thrift.TAuthorizable;
import org.apache.sentry.provider.db.generic.service.thrift.TSentryGrantOption;
import org.apache.sentry.provider.db.generic.service.thrift.TSentryPrivilege;
import org.apache.sentry.provider.db.generic.tools.command.TSentryPrivilegeConverter;
import org.apache.shiro.config.ConfigurationException;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* A TSentryPrivilegeConverter implementation for "Generic" privileges, covering Apache Kafka, Apache Solr and Apache Sqoop.
* It converts privilege Strings to TSentryPrivilege Objects, and vice versa, for Generic clients.
@@ -49,24 +61,16 @@ public class GenericPrivilegeConverter implements TSentryPrivilegeConverter {
private String service;
private boolean validate;
- private List<PrivilegeValidator> privilegeValidators;
-
- private AuthorizableFactory authorizableFactory;
-
- /**
- * Optional function to parse or convert privilege string.
- */
- private Function<String, String> privilegeStrParser;
+ public GenericPrivilegeConverter(String component, String service) {
+ this(component, service, true);
+ }
- public GenericPrivilegeConverter(String component, String service, List<PrivilegeValidator> privilegeValidators, AuthorizableFactory authorizableFactory, boolean validate) {
+ public GenericPrivilegeConverter(String component, String service, boolean validate) {
this.component = component;
this.service = service;
- this.privilegeValidators = privilegeValidators;
- this.authorizableFactory = authorizableFactory;
this.validate = validate;
}
-
public TSentryPrivilege fromString(String privilegeStr) throws SentryUserException {
privilegeStr = parsePrivilegeString(privilegeStr);
if (validate) {
@@ -74,13 +78,13 @@ public class GenericPrivilegeConverter implements TSentryPrivilegeConverter {
}
TSentryPrivilege tSentryPrivilege = new TSentryPrivilege();
- List<TAuthorizable> authorizables = new ArrayList<>();
+ List<TAuthorizable> authorizables = new LinkedList<TAuthorizable>();
for (String authorizable : SentryConstants.AUTHORIZABLE_SPLITTER.split(privilegeStr)) {
KeyValue keyValue = new KeyValue(authorizable);
String key = keyValue.getKey();
String value = keyValue.getValue();
- Authorizable authz = authorizableFactory.create(key, value);
+ Authorizable authz = getAuthorizable(keyValue);
if (authz != null) {
authorizables.add(new TAuthorizable(authz.getTypeName(), authz.getName()));
} else if (PolicyFileConstants.PRIVILEGE_ACTION_NAME.equalsIgnoreCase(key)) {
@@ -107,30 +111,39 @@ public class GenericPrivilegeConverter implements TSentryPrivilegeConverter {
String grantOption = (tSentryPrivilege.getGrantOption() == TSentryGrantOption.TRUE ? "true"
: "false");
- for (TAuthorizable tAuthorizable : authorizables) {
- privileges.add(SentryConstants.KV_JOINER.join(
- tAuthorizable.getType(), tAuthorizable.getName()));
+ Iterator<TAuthorizable> it = authorizables.iterator();
+ if (it != null) {
+ while (it.hasNext()) {
+ TAuthorizable tAuthorizable = it.next();
+ privileges.add(SentryConstants.KV_JOINER.join(
+ tAuthorizable.getType(), tAuthorizable.getName()));
+ }
}
if (!authorizables.isEmpty()) {
privileges.add(SentryConstants.KV_JOINER.join(
- PolicyFileConstants.PRIVILEGE_ACTION_NAME, action));
+ PolicyFileConstants.PRIVILEGE_ACTION_NAME, action));
}
// only append the grant option to privilege string if it's true
if ("true".equals(grantOption)) {
privileges.add(SentryConstants.KV_JOINER.join(
- PolicyFileConstants.PRIVILEGE_GRANT_OPTION_NAME, grantOption));
+ PolicyFileConstants.PRIVILEGE_GRANT_OPTION_NAME, grantOption));
}
}
return SentryConstants.AUTHORIZABLE_JOINER.join(privileges);
}
private String parsePrivilegeString(String privilegeStr) {
- if (privilegeStrParser == null) {
- return privilegeStr;
+ if (AuthorizationComponent.KAFKA.equals(component)) {
+ final String hostPrefix = KafkaAuthorizable.AuthorizableType.HOST.name() + KV_SEPARATOR;
+ final String hostPrefixLowerCase = hostPrefix.toLowerCase();
+ if (!privilegeStr.toLowerCase().startsWith(hostPrefixLowerCase)) {
+ return hostPrefix + RESOURCE_WILDCARD_VALUE + AUTHORIZABLE_SEPARATOR + privilegeStr;
+ }
}
- return privilegeStrParser.apply(privilegeStr);
+
+ return privilegeStr;
}
private void validatePrivilegeHierarchy(String privilegeStr) throws SentryUserException {
@@ -145,21 +158,28 @@ public class GenericPrivilegeConverter implements TSentryPrivilegeConverter {
}
}
- private List<PrivilegeValidator> getPrivilegeValidators() {
- return privilegeValidators;
- }
-
+ private List<PrivilegeValidator> getPrivilegeValidators() throws SentryUserException {
+ if (AuthorizationComponent.KAFKA.equals(component)) {
+ return KafkaPrivilegeModel.getInstance().getPrivilegeValidators();
+ } else if ("SOLR".equals(component)) {
+ return SolrPrivilegeModel.getInstance().getPrivilegeValidators();
+ } else if (AuthorizationComponent.SQOOP.equals(component)) {
+ return SqoopPrivilegeModel.getInstance().getPrivilegeValidators(service);
+ }
- public void setPrivilegeValidators(List<PrivilegeValidator> privilegeValidators) {
- this.privilegeValidators = privilegeValidators;
+ throw new SentryUserException("Invalid component specified for GenericPrivilegeCoverter: " + component);
}
- public void setAuthorizableFactory(AuthorizableFactory authorizableFactory) {
- this.authorizableFactory = authorizableFactory;
- }
+ private Authorizable getAuthorizable(KeyValue keyValue) throws SentryUserException {
+ if (AuthorizationComponent.KAFKA.equals(component)) {
+ return KafkaModelAuthorizables.from(keyValue);
+ } else if ("SOLR".equals(component)) {
+ return SolrModelAuthorizables.from(keyValue);
+ } else if (AuthorizationComponent.SQOOP.equals(component)) {
+ return SqoopModelAuthorizables.from(keyValue);
+ }
- public void setPrivilegeStrParser(Function<String, String> privilegeStrParser) {
- this.privilegeStrParser = privilegeStrParser;
+ throw new SentryUserException("Invalid component specified for GenericPrivilegeCoverter: " + component);
}
}
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryConfigToolSolr.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryConfigToolSolr.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryConfigToolSolr.java
index 10b875d..5649f43 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryConfigToolSolr.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryConfigToolSolr.java
@@ -18,7 +18,6 @@
package org.apache.sentry.provider.db.generic.tools;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.collect.Table;
@@ -30,8 +29,6 @@ import org.apache.sentry.core.common.Action;
import org.apache.sentry.core.common.exception.SentryConfigurationException;
import org.apache.sentry.core.common.utils.KeyValue;
import org.apache.sentry.core.common.utils.SentryConstants;
-import org.apache.sentry.core.common.validator.PrivilegeValidator;
-import org.apache.sentry.core.model.solr.SolrModelAuthorizables;
import org.apache.sentry.core.model.solr.SolrPrivilegeModel;
import org.apache.sentry.provider.common.ProviderBackend;
import org.apache.sentry.provider.common.ProviderBackendContext;
@@ -95,8 +92,7 @@ public class SentryConfigToolSolr extends SentryConfigToolCommon {
SimpleFileProviderBackend policyFileBackend =
new SimpleFileProviderBackend(conf, policyFile);
ProviderBackendContext context = new ProviderBackendContext();
- ImmutableList<PrivilegeValidator> privilegeValidators = SolrPrivilegeModel.getInstance().getPrivilegeValidators();
- context.setValidators(privilegeValidators);
+ context.setValidators(SolrPrivilegeModel.getInstance().getPrivilegeValidators());
policyFileBackend.initialize(context);
if (validate) {
validatePolicy(policyFileBackend);
@@ -110,8 +106,7 @@ public class SentryConfigToolSolr extends SentryConfigToolCommon {
Set<String> roles = Sets.newHashSet();
Table<String, String, Set<String>> groupRolePrivilegeTable =
policyFileBackend.getGroupRolePrivilegeTable();
- SolrModelAuthorizables authorizableFactory = new SolrModelAuthorizables();
- GenericPrivilegeConverter converter = new GenericPrivilegeConverter(component, service, privilegeValidators, authorizableFactory, false);
+ GenericPrivilegeConverter converter = new GenericPrivilegeConverter(component, service, false);
for (String groupName : groupRolePrivilegeTable.rowKeySet()) {
for (String roleName : groupRolePrivilegeTable.columnKeySet()) {
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryShellGeneric.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryShellGeneric.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryShellGeneric.java
index 8dc04f3..1623f38 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryShellGeneric.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryShellGeneric.java
@@ -25,11 +25,12 @@ import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.sentry.provider.common.AuthorizationComponent;
import org.apache.sentry.provider.db.generic.service.thrift.SentryGenericServiceClient;
import org.apache.sentry.provider.db.generic.service.thrift.SentryGenericServiceClientFactory;
import org.apache.sentry.provider.db.generic.tools.command.GenericShellCommand;
+import org.apache.sentry.provider.db.generic.tools.command.TSentryPrivilegeConverter;
import org.apache.sentry.provider.db.tools.SentryShellCommon;
-import org.apache.sentry.service.thrift.ServiceConstants;
import org.apache.sentry.provider.db.tools.ShellCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,26 +43,25 @@ import com.google.common.collect.Sets;
* create role, drop role, add group to role, grant privilege to role,
* revoke privilege from role, list roles, list privilege for role.
*/
-abstract public class SentryShellGeneric extends SentryShellCommon {
+public class SentryShellGeneric extends SentryShellCommon {
private static final Logger LOGGER = LoggerFactory.getLogger(SentryShellGeneric.class);
-
- abstract protected GenericPrivilegeConverter getPrivilegeConverter(String component, String service);
-
- abstract protected String getComponent(Configuration conf);
+ private static final String KAFKA_SERVICE_NAME = "sentry.service.client.kafka.service.name";
+ private static final String SOLR_SERVICE_NAME = "sentry.service.client.solr.service.name";
+ private static final String SQOOP_SERVICE_NAME = "sentry.service.client.sqoop.service.name";
@Override
public void run() throws Exception {
+ String component = getComponent();
Configuration conf = getSentryConf();
- String component = getComponent(conf);
- String service = getServiceName(conf);
-
+ String service = getService(conf);
try (SentryGenericServiceClient client =
- SentryGenericServiceClientFactory.create(conf)) {
+ SentryGenericServiceClientFactory.create(conf)) {
UserGroupInformation ugi = UserGroupInformation.getLoginUser();
String requestorName = ugi.getShortUserName();
- ShellCommand command = new GenericShellCommand(client, component, service, getPrivilegeConverter(component, service));
+ TSentryPrivilegeConverter converter = new GenericPrivilegeConverter(component, service);
+ ShellCommand command = new GenericShellCommand(client, component, service, converter);
// check the requestor name
if (StringUtils.isEmpty(requestorName)) {
@@ -102,12 +102,28 @@ abstract public class SentryShellGeneric extends SentryShellCommon {
}
}
- protected String getServiceName(Configuration conf) {
- return getServiceNameGeneric(conf);
+ private String getComponent() throws Exception {
+ if (type == TYPE.kafka) {
+ return AuthorizationComponent.KAFKA;
+ } else if (type == TYPE.solr) {
+ return "SOLR";
+ } else if (type == TYPE.sqoop) {
+ return AuthorizationComponent.SQOOP;
+ }
+
+ throw new Exception("Invalid type specified for SentryShellGeneric: " + type);
}
- protected String getServiceNameGeneric(Configuration conf) {
- return conf.get(ServiceConstants.ClientConfig.SERVICE_NAME);
+ private String getService(Configuration conf) throws Exception {
+ if (type == TYPE.kafka) {
+ return conf.get(KAFKA_SERVICE_NAME, AuthorizationComponent.KAFKA);
+ } else if (type == TYPE.solr) {
+ return conf.get(SOLR_SERVICE_NAME, "service1");
+ } else if (type == TYPE.sqoop) {
+ return conf.get(SQOOP_SERVICE_NAME, "sqoopServer1");
+ }
+
+ throw new Exception("Invalid type specified for SentryShellGeneric: " + type);
}
private Configuration getSentryConf() {
@@ -116,9 +132,10 @@ abstract public class SentryShellGeneric extends SentryShellCommon {
return conf;
}
- protected void doMain(String[] args) throws Exception {
+ public static void main(String[] args) throws Exception {
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
try {
- executeShell(args);
+ sentryShell.executeShell(args);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
Throwable current = e;
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryShellKafka.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryShellKafka.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryShellKafka.java
deleted file mode 100644
index 225c2e3..0000000
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryShellKafka.java
+++ /dev/null
@@ -1,71 +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.db.generic.tools;
-
-import com.google.common.base.Function;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.sentry.core.model.kafka.KafkaAuthorizable;
-import org.apache.sentry.core.model.kafka.KafkaModelAuthorizables;
-import org.apache.sentry.core.model.kafka.KafkaPrivilegeModel;
-import org.apache.sentry.provider.common.AuthorizationComponent;
-
-import javax.annotation.Nullable;
-
-import static org.apache.sentry.core.common.utils.SentryConstants.*;
-
-public class SentryShellKafka extends SentryShellGeneric {
- private static final String KAFKA_SERVICE_NAME = "sentry.service.client.kafka.service.name";
-
- @Override
- protected GenericPrivilegeConverter getPrivilegeConverter(String component, String service) {
- GenericPrivilegeConverter privilegeConverter = new GenericPrivilegeConverter(
- component,
- service,
- KafkaPrivilegeModel.getInstance().getPrivilegeValidators(),
- new KafkaModelAuthorizables(),
- true
- );
- privilegeConverter.setPrivilegeStrParser(new Function<String, String>() {
- @Nullable
- @Override
- public String apply(@Nullable String privilegeStr) {
- final String hostPrefix = KafkaAuthorizable.AuthorizableType.HOST.name() + KV_SEPARATOR;
- final String hostPrefixLowerCase = hostPrefix.toLowerCase();
- if (!privilegeStr.toLowerCase().startsWith(hostPrefixLowerCase)) {
- return hostPrefix + RESOURCE_WILDCARD_VALUE + AUTHORIZABLE_SEPARATOR + privilegeStr;
- }
- return privilegeStr;
- }
- });
- return privilegeConverter;
- }
-
- @Override
- protected String getComponent(Configuration conf) {
- return AuthorizationComponent.KAFKA;
- }
-
- @Override
- protected String getServiceName(Configuration conf) {
- return conf.get(KAFKA_SERVICE_NAME, AuthorizationComponent.KAFKA);
- }
-
- public static void main(String[] args) throws Exception {
- new SentryShellKafka().doMain(args);
- }
-}
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryShellSolr.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryShellSolr.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryShellSolr.java
deleted file mode 100644
index de37e42..0000000
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryShellSolr.java
+++ /dev/null
@@ -1,52 +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.db.generic.tools;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.sentry.core.model.solr.SolrModelAuthorizables;
-import org.apache.sentry.core.model.solr.SolrPrivilegeModel;
-import org.apache.sentry.provider.common.AuthorizationComponent;
-
-public class SentryShellSolr extends SentryShellGeneric {
- private static final String SOLR_SERVICE_NAME = "sentry.service.client.solr.service.name";
-
- @Override
- protected GenericPrivilegeConverter getPrivilegeConverter(String component, String service) {
- return new GenericPrivilegeConverter(
- component,
- service,
- SolrPrivilegeModel.getInstance().getPrivilegeValidators(),
- new SolrModelAuthorizables(),
- true
- );
- }
-
- @Override
- protected String getComponent(Configuration conf) {
- return AuthorizationComponent.Search;
- }
-
- @Override
- protected String getServiceName(Configuration conf) {
- return conf.get(SOLR_SERVICE_NAME, "service1");
- }
-
- public static void main(String[] args) throws Exception {
- new SentryShellSolr().doMain(args);
- }
-}
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryShellSqoop.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryShellSqoop.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryShellSqoop.java
deleted file mode 100644
index 6315bb5..0000000
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/tools/SentryShellSqoop.java
+++ /dev/null
@@ -1,52 +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.db.generic.tools;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.sentry.core.model.sqoop.SqoopModelAuthorizables;
-import org.apache.sentry.core.model.sqoop.SqoopPrivilegeModel;
-import org.apache.sentry.provider.common.AuthorizationComponent;
-
-public class SentryShellSqoop extends SentryShellGeneric {
- private static final String SQOOP_SERVICE_NAME = "sentry.service.client.sqoop.service.name";
-
- @Override
- protected GenericPrivilegeConverter getPrivilegeConverter(String component, String service) {
- return new GenericPrivilegeConverter(
- component,
- service,
- SqoopPrivilegeModel.getInstance().getPrivilegeValidators(service),
- new SqoopModelAuthorizables(),
- true
- );
- }
-
- @Override
- protected String getComponent(Configuration conf) {
- return AuthorizationComponent.SQOOP;
- }
-
- @Override
- protected String getServiceName(Configuration conf) {
- return conf.get(SQOOP_SERVICE_NAME, "sqoopServer1");
- }
-
- public static void main(String[] args) throws Exception {
- new SentryShellSqoop().doMain(args);
- }
-}
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryConfigToolSolr.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryConfigToolSolr.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryConfigToolSolr.java
index 4a94776..9e6ff42 100644
--- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryConfigToolSolr.java
+++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryConfigToolSolr.java
@@ -33,8 +33,6 @@ import java.util.Map;
import java.util.Set;
import org.apache.commons.io.FileUtils;
-import org.apache.sentry.core.model.solr.SolrModelAuthorizables;
-import org.apache.sentry.core.model.solr.SolrPrivilegeModel;
import org.apache.sentry.provider.db.generic.service.thrift.SentryGenericServiceIntegrationBase;
import org.apache.sentry.provider.db.generic.service.thrift.TSentryRole;
import org.apache.sentry.provider.db.generic.service.thrift.TSentryPrivilege;
@@ -135,12 +133,7 @@ public class TestSentryConfigToolSolr extends SentryGenericServiceIntegrationBas
}
// check privileges
- GenericPrivilegeConverter convert = new GenericPrivilegeConverter(
- SOLR,
- service,
- SolrPrivilegeModel.getInstance().getPrivilegeValidators(),
- new SolrModelAuthorizables(),
- true);
+ GenericPrivilegeConverter convert = new GenericPrivilegeConverter(SOLR, service);
for (String role : roles) {
Set<TSentryPrivilege> privileges = client.listAllPrivilegesByRoleName(
requestorName, role, SOLR, service);
http://git-wip-us.apache.org/repos/asf/sentry/blob/5fc1e977/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellKafka.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellKafka.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellKafka.java
index fc1d1ac..a9234fa 100644
--- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellKafka.java
+++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/generic/tools/TestSentryShellKafka.java
@@ -79,32 +79,32 @@ public class TestSentryShellKafka extends SentryGenericServiceIntegrationBase {
@Override
public void runTestAsSubject() throws Exception {
// test: create role with -cr
- String[] args = { "-cr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() };
- SentryShellKafka.main(args);
+ String[] args = { "-cr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ SentryShellGeneric.main(args);
// test: create role with --create_role
args = new String[] { "--create_role", "-r", TEST_ROLE_NAME_2, "-conf",
- confPath.getAbsolutePath() };
- SentryShellKafka.main(args);
+ confPath.getAbsolutePath(), "-t", "kafka" };
+ SentryShellGeneric.main(args);
// validate the result, list roles with -lr
- args = new String[] { "-lr", "-conf", confPath.getAbsolutePath() };
- SentryShellKafka sentryShell = new SentryShellKafka();
+ args = new String[] { "-lr", "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
Set<String> roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames, TEST_ROLE_NAME_1, TEST_ROLE_NAME_2);
// validate the result, list roles with --list_role
- args = new String[] { "--list_role", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ args = new String[] { "--list_role", "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames, TEST_ROLE_NAME_1, TEST_ROLE_NAME_2);
// test: drop role with -dr
- args = new String[] { "-dr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() };
- SentryShellKafka.main(args);
+ args = new String[] { "-dr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ SentryShellGeneric.main(args);
// test: drop role with --drop_role
args = new String[] { "--drop_role", "-r", TEST_ROLE_NAME_2, "-conf",
- confPath.getAbsolutePath() };
- SentryShellKafka.main(args);
+ confPath.getAbsolutePath(), "-t", "kafka" };
+ SentryShellGeneric.main(args);
// validate the result
Set<TSentryRole> roles = client.listAllRoles(requestorName, KAFKA);
@@ -128,41 +128,41 @@ public class TestSentryShellKafka extends SentryGenericServiceIntegrationBase {
client.createRole(requestorName, TEST_ROLE_NAME_2, KAFKA);
// test: add role to group with -arg
String[] args = { "-arg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_1, "-conf",
- confPath.getAbsolutePath() };
- SentryShellKafka.main(args);
+ confPath.getAbsolutePath(), "-t", "kafka" };
+ SentryShellGeneric.main(args);
// test: add role to multiple groups
args = new String[] { "-arg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_2 + "," + TEST_GROUP_3,
- "-conf",
- confPath.getAbsolutePath() };
- SentryShellKafka.main(args);
+ "-conf",
+ confPath.getAbsolutePath(), "-t", "kafka" };
+ SentryShellGeneric.main(args);
// test: add role to group with --add_role_group
args = new String[] { "--add_role_group", "-r", TEST_ROLE_NAME_2, "-g", TEST_GROUP_1,
- "-conf",
- confPath.getAbsolutePath() };
- SentryShellKafka.main(args);
+ "-conf",
+ confPath.getAbsolutePath(), "-t", "kafka" };
+ SentryShellGeneric.main(args);
// validate the result list roles with -lr and -g
- args = new String[] { "-lr", "-g", TEST_GROUP_1, "-conf", confPath.getAbsolutePath() };
- SentryShellKafka sentryShell = new SentryShellKafka();
+ args = new String[] { "-lr", "-g", TEST_GROUP_1, "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
Set<String> roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames, TEST_ROLE_NAME_1, TEST_ROLE_NAME_2);
// list roles with --list_role and -g
args = new String[] { "--list_role", "-g", TEST_GROUP_2, "-conf",
- confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames, TEST_ROLE_NAME_1);
args = new String[] { "--list_role", "-g", TEST_GROUP_3, "-conf",
- confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames, TEST_ROLE_NAME_1);
// List the groups and roles via listGroups
- args = new String[] { "--list_group", "-conf", confPath.getAbsolutePath()};
- sentryShell = new SentryShellKafka();
+ args = new String[] { "--list_group", "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
Set<String> groups = getShellResultWithOSRedirect(sentryShell, args, true);
assertEquals(3, groups.size());
assertTrue(groups.contains("testGroup3 = testrole1"));
@@ -171,17 +171,17 @@ public class TestSentryShellKafka extends SentryGenericServiceIntegrationBase {
// test: delete role from group with -drg
args = new String[] { "-drg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_1, "-conf",
- confPath.getAbsolutePath() };
- SentryShellKafka.main(args);
+ confPath.getAbsolutePath(), "-t", "kafka" };
+ SentryShellGeneric.main(args);
// test: delete role to multiple groups
args = new String[] { "-drg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_2 + "," + TEST_GROUP_3,
- "-conf",
- confPath.getAbsolutePath() };
- SentryShellKafka.main(args);
+ "-conf",
+ confPath.getAbsolutePath(), "-t", "kafka" };
+ SentryShellGeneric.main(args);
// test: delete role from group with --delete_role_group
args = new String[] { "--delete_role_group", "-r", TEST_ROLE_NAME_2, "-g", TEST_GROUP_1,
- "-conf", confPath.getAbsolutePath() };
- SentryShellKafka.main(args);
+ "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ SentryShellGeneric.main(args);
// validate the result
Set<TSentryRole> roles = client.listRolesByGroupName(requestorName, TEST_GROUP_1, KAFKA);
@@ -207,17 +207,17 @@ public class TestSentryShellKafka extends SentryGenericServiceIntegrationBase {
client.createRole(requestorName, TEST_ROLE_NAME_1, KAFKA);
// add role to a group (lower case)
String[] args = {"-arg", "-r", TEST_ROLE_NAME_1, "-g", "group1", "-conf",
- confPath.getAbsolutePath()};
- SentryShellKafka.main(args);
+ confPath.getAbsolutePath(), "-t", "kafka"};
+ SentryShellGeneric.main(args);
// validate the roles when group name is same case as above
- args = new String[]{"-lr", "-g", "group1", "-conf", confPath.getAbsolutePath()};
- SentryShellKafka sentryShell = new SentryShellKafka();
+ args = new String[]{"-lr", "-g", "group1", "-conf", confPath.getAbsolutePath(), "-t", "kafka"};
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
Set<String> roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames, TEST_ROLE_NAME_1);
// roles should be empty when group name is different case than above
- args = new String[]{"-lr", "-g", "GROUP1", "-conf", confPath.getAbsolutePath()};
+ args = new String[]{"-lr", "-g", "GROUP1", "-conf", confPath.getAbsolutePath(), "-t", "kafka"};
roleNames = getShellResultWithOSRedirect(sentryShell, args, true);
validateRoleNames(roleNames);
}
@@ -245,23 +245,23 @@ public class TestSentryShellKafka extends SentryGenericServiceIntegrationBase {
client.createRole(requestorName, TEST_ROLE_NAME_2, KAFKA);
String [] privs = {
- "HOST=*->CLUSTER=kafka-cluster->action=read",
- "HOST=h1->TOPIC=t1->action=write",
- "HOST=*->CONSUMERGROUP=cg1->action=read",
- "CLUSTER=kafka-cluster->action=write",
- "CONSUMERGROUP=cg2->action=write"
+ "HOST=*->CLUSTER=kafka-cluster->action=read",
+ "HOST=h1->TOPIC=t1->action=write",
+ "HOST=*->CONSUMERGROUP=cg1->action=read",
+ "CLUSTER=kafka-cluster->action=write",
+ "CONSUMERGROUP=cg2->action=write"
};
for (int i = 0; i < privs.length; ++i) {
// test: grant privilege to role
String [] args = new String [] { grant(shortOption), "-r", TEST_ROLE_NAME_1, "-p",
- privs[ i ],
- "-conf", confPath.getAbsolutePath()};
- SentryShellKafka.main(args);
+ privs[ i ],
+ "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ SentryShellGeneric.main(args);
}
// test the list privilege
- String [] args = new String[] { list(shortOption), "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath()};
- SentryShellKafka sentryShell = new SentryShellKafka();
+ String [] args = new String[] { list(shortOption), "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
Set<String> privilegeStrs = getShellResultWithOSRedirect(sentryShell, args, true);
assertEquals("Incorrect number of privileges", privs.length, privilegeStrs.size());
@@ -272,8 +272,8 @@ public class TestSentryShellKafka extends SentryGenericServiceIntegrationBase {
for (int i = 0; i < privs.length; ++i) {
args = new String[] { revoke(shortOption), "-r", TEST_ROLE_NAME_1, "-p",
privs[ i ], "-conf",
- confPath.getAbsolutePath() };
- SentryShellKafka.main(args);
+ confPath.getAbsolutePath(), "-t", "kafka" };
+ SentryShellGeneric.main(args);
Set<TSentryPrivilege> privileges = client.listAllPrivilegesByRoleName(requestorName,
TEST_ROLE_NAME_1, KAFKA, service);
assertEquals("Incorrect number of privileges. Received privileges: " + Arrays.toString(privileges.toArray()), privs.length - (i + 1), privileges.size());
@@ -305,8 +305,8 @@ public class TestSentryShellKafka extends SentryGenericServiceIntegrationBase {
public void runTestAsSubject() throws Exception {
client.createRole(requestorName, TEST_ROLE_NAME_1, KAFKA);
// test: create duplicate role with -cr
- String[] args = { "-cr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() };
- SentryShellKafka sentryShell = new SentryShellKafka();
+ String[] args = { "-cr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
try {
sentryShell.executeShell(args);
fail("Exception should be thrown for creating duplicate role");
@@ -317,8 +317,8 @@ public class TestSentryShellKafka extends SentryGenericServiceIntegrationBase {
}
// test: drop non-exist role with -dr
- args = new String[] { "-dr", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ args = new String[] { "-dr", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
try {
sentryShell.executeShell(args);
fail("Exception should be thrown for dropping non-exist role");
@@ -330,8 +330,8 @@ public class TestSentryShellKafka extends SentryGenericServiceIntegrationBase {
// test: add non-exist role to group with -arg
args = new String[] { "-arg", "-r", TEST_ROLE_NAME_2, "-g", "testGroup1", "-conf",
- confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
try {
sentryShell.executeShell(args);
fail("Exception should be thrown for granting non-exist role to group");
@@ -343,8 +343,8 @@ public class TestSentryShellKafka extends SentryGenericServiceIntegrationBase {
// test: drop group from non-exist role with -drg
args = new String[] { "-drg", "-r", TEST_ROLE_NAME_2, "-g", "testGroup1", "-conf",
- confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
try {
sentryShell.executeShell(args);
fail("Exception should be thrown for drop group from non-exist role");
@@ -356,8 +356,8 @@ public class TestSentryShellKafka extends SentryGenericServiceIntegrationBase {
// test: grant privilege to role with the error privilege format
args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-p", "serverserver1->action=all",
- "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
try {
sentryShell.executeShell(args);
fail("Exception should be thrown for the error privilege format, invalid key value.");
@@ -369,17 +369,16 @@ public class TestSentryShellKafka extends SentryGenericServiceIntegrationBase {
// test: grant privilege to role with the error privilege hierarchy
args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-p",
- "consumergroup=cg1->host=h1->action=create", "-conf",
- confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ "consumergroup=cg1->host=h1->action=create", "-conf",
+ confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
try {
sentryShell.executeShell(args);
fail("Exception should be thrown for the error privilege format, invalid key value.");
} catch (IllegalArgumentException e) {
// expected exception
} catch (Exception e) {
- throw e;
-// fail ("Unexpected exception received. " + e);
+ fail ("Unexpected exception received. " + e);
}
// clear the test data
@@ -396,86 +395,86 @@ public class TestSentryShellKafka extends SentryGenericServiceIntegrationBase {
String strOptionConf = "conf";
client.createRole(requestorName, TEST_ROLE_NAME_1, KAFKA);
// test: the conf is required argument
- String[] args = { "-cr", "-r", TEST_ROLE_NAME_1 };
- SentryShellKafka sentryShell = new SentryShellKafka();
+ String[] args = { "-cr", "-r", TEST_ROLE_NAME_1, "-t", "kafka" };
+ SentryShellGeneric sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + strOptionConf);
// test: -r is required when create role
- args = new String[] { "-cr", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ args = new String[] { "-cr", "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);
// test: -r is required when drop role
- args = new String[] { "-dr", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ args = new String[] { "-dr", "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);
// test: -r is required when add role to group
- args = new String[] { "-arg", "-g", "testGroup1", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ args = new String[] { "-arg", "-g", "testGroup1", "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);
// test: -g is required when add role to group
- args = new String[] { "-arg", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ args = new String[] { "-arg", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_GROUP_NAME);
// test: -r is required when delete role from group
- args = new String[] { "-drg", "-g", "testGroup1", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ args = new String[] { "-drg", "-g", "testGroup1", "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);
// test: -g is required when delete role from group
- args = new String[] { "-drg", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ args = new String[] { "-drg", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_GROUP_NAME);
// test: -r is required when grant privilege to role
- args = new String[] { "-gpr", "-p", "server=server1", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ args = new String[] { "-gpr", "-p", "server=server1", "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);
// test: -p is required when grant privilege to role
- args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_PRIVILEGE);
// test: action is required in privilege
- args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-p", "host=*->topic=t1" };
- sentryShell = new SentryShellKafka();
- try {
+ args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-p", "host=*->topic=t1", "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
+ try {
getShellResultWithOSRedirect(sentryShell, args, false);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
assert(("Kafka privilege must end with a valid action.\n" + KafkaPrivilegeValidator.KafkaPrivilegeHelpMsg).equals(e.getCause().getMessage()));
} catch (Exception e) {
- fail ("Unexpected exception received. " + e);
- }
+ fail ("Unexpected exception received. " + e);
+ }
// test: -r is required when revoke privilege from role
- args = new String[] { "-rpr", "-p", "host=h1", "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ args = new String[] { "-rpr", "-p", "host=h1", "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_ROLE_NAME);
// test: -p is required when revoke privilege from role
- args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsg(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + SentryShellCommon.OPTION_DESC_PRIVILEGE);
// test: command option is required for shell
- args = new String[] {"-conf", confPath.getAbsolutePath() };
- sentryShell = new SentryShellKafka();
+ args = new String[] {"-conf", confPath.getAbsolutePath(), "-t", "kafka" };
+ sentryShell = new SentryShellGeneric();
validateMissingParameterMsgsContains(sentryShell, args,
SentryShellCommon.PREFIX_MESSAGE_MISSING_OPTION + "[",
"-arg Add role to group",
@@ -494,8 +493,8 @@ public class TestSentryShellKafka extends SentryGenericServiceIntegrationBase {
}
// redirect the System.out to ByteArrayOutputStream, then execute the command and parse the result.
- private Set<String> getShellResultWithOSRedirect(SentryShellKafka sentryShell,
- String[] args, boolean expectedExecuteResult) throws Exception {
+ private Set<String> getShellResultWithOSRedirect(SentryShellGeneric sentryShell,
+ String[] args, boolean expectedExecuteResult) throws Exception {
PrintStream oldOut = System.out;
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
@@ -508,7 +507,7 @@ public class TestSentryShellKafka extends SentryGenericServiceIntegrationBase {
private void validateRoleNames(Set<String> roleNames, String ... expectedRoleNames) {
if (expectedRoleNames != null && expectedRoleNames.length > 0) {
assertEquals("Found: " + roleNames.size() + " roles, expected: " + expectedRoleNames.length,
- expectedRoleNames.length, roleNames.size());
+ expectedRoleNames.length, roleNames.size());
Set<String> lowerCaseRoles = new HashSet<String>();
for (String role : roleNames) {
lowerCaseRoles.add(role.toLowerCase());
@@ -516,19 +515,19 @@ public class TestSentryShellKafka extends SentryGenericServiceIntegrationBase {
for (String expectedRole : expectedRoleNames) {
assertTrue("Expected role: " + expectedRole,
- lowerCaseRoles.contains(expectedRole.toLowerCase()));
+ lowerCaseRoles.contains(expectedRole.toLowerCase()));
}
}
}
- private void validateMissingParameterMsg(SentryShellKafka sentryShell, String[] args,
- String expectedErrorMsg) throws Exception {
+ private void validateMissingParameterMsg(SentryShellGeneric sentryShell, String[] args,
+ String expectedErrorMsg) throws Exception {
Set<String> errorMsgs = getShellResultWithOSRedirect(sentryShell, args, false);
assertTrue("Expected error message: " + expectedErrorMsg, errorMsgs.contains(expectedErrorMsg));
}
- private void validateMissingParameterMsgsContains(SentryShellKafka sentryShell, String[] args,
- String ... expectedErrorMsgsContains) throws Exception {
+ private void validateMissingParameterMsgsContains(SentryShellGeneric sentryShell, String[] args,
+ String ... expectedErrorMsgsContains) throws Exception {
Set<String> errorMsgs = getShellResultWithOSRedirect(sentryShell, args, false);
boolean foundAllMessages = false;
Iterator<String> it = errorMsgs.iterator();
[9/9] sentry git commit: Merge branch 'master' into akolb-cli
Posted by co...@apache.org.
Merge branch 'master' into akolb-cli
Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/fe3ef237
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/fe3ef237
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/fe3ef237
Branch: refs/heads/akolb-cli
Commit: fe3ef2370c64f221d45f4156d1d25e0ffecb0b56
Parents: 81128e6 372ffc9
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Mon Nov 20 14:47:11 2017 +0000
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Mon Nov 20 14:47:11 2017 +0000
----------------------------------------------------------------------
bin/sentryShell | 6 +-
pom.xml | 17 +-
.../json/SentryJSONMessageDeserializer.java | 79 ++++++-
.../json/SentryJSONMessageFactory.java | 48 ++++
.../hive/ql/exec/SentryFilterDDLTask.java | 9 +-
.../hive/ql/exec/SentryGrantRevokeTask.java | 7 +-
.../binding/hive/HiveAuthzBindingHook.java | 2 +-
.../hive/authz/DefaultSentryValidator.java | 17 ++
.../hive/authz/HiveAuthzBindingHookBase.java | 10 -
.../hive/authz/SentryHiveAuthorizerImpl.java | 13 ++
.../metastore/SentryHiveMetaStoreClient.java | 2 +-
...rySyncHMSNotificationsPostEventListener.java | 230 +++++++++++++++++++
.../TestSentryHiveAuthorizationTaskFactory.java | 16 +-
...rySyncHMSNotificationsPostEventListener.java | 161 +++++++++++++
.../common/AbstractAuthorizableFactory.java | 72 ------
.../sentry/core/common/AuthorizableFactory.java | 50 ----
.../sentry/core/common/AuthorizableType.java | 21 --
.../sentry/core/common/utils/PathUtils.java | 8 +-
.../sentry/core/common/utils/TestPathUtils.java | 27 +++
.../core/model/kafka/KafkaAuthorizable.java | 2 +-
.../model/kafka/KafkaModelAuthorizables.java | 27 ++-
.../core/model/solr/SolrModelAuthorizable.java | 6 +-
.../core/model/solr/SolrModelAuthorizables.java | 52 +++--
.../core/model/sqoop/SqoopAuthorizable.java | 2 +-
.../model/sqoop/SqoopModelAuthorizables.java | 50 ++--
.../tools/GenericPrivilegeConverter.java | 96 +++++---
.../db/generic/tools/SentryConfigToolSolr.java | 9 +-
.../db/generic/tools/SentryShellGeneric.java | 51 ++--
.../db/generic/tools/SentryShellKafka.java | 71 ------
.../db/generic/tools/SentryShellSolr.java | 52 -----
.../db/generic/tools/SentryShellSqoop.java | 52 -----
.../db/service/persistent/SentryStore.java | 2 +-
.../thrift/SentryPolicyServiceClient.java | 9 +
.../SentryPolicyServiceClientDefaultImpl.java | 13 ++
.../generic/tools/TestSentryConfigToolSolr.java | 9 +-
.../db/generic/tools/TestSentryShellKafka.java | 207 +++++++++--------
.../db/generic/tools/TestSentryShellSolr.java | 224 +++++++++---------
.../db/generic/tools/TestSentryShellSqoop.java | 164 ++++++-------
.../db/service/persistent/TestSentryStore.java | 57 +++++
.../e2e/hdfs/TestHDFSIntegrationAdvanced.java | 9 +-
.../tests/e2e/hdfs/TestHDFSIntegrationBase.java | 9 +
.../e2e/hive/TestPrivilegesAtColumnScope.java | 31 +--
.../e2e/hive/hiveserver/HiveServerFactory.java | 15 ++
...actMetastoreTestWithStaticConfiguration.java | 3 +-
.../e2e/metastore/TestMetastoreEndToEnd.java | 6 +-
sentry-tests/sentry-tests-solr/pom.xml | 8 +
46 files changed, 1232 insertions(+), 799 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sentry/blob/fe3ef237/pom.xml
----------------------------------------------------------------------
[5/9] sentry git commit: SENTRY-2054: Unit tests must create
temporary files under the Maven target directory (Sergio Pena,
reviewed by kalyan kumar kalvagadda)
Posted by co...@apache.org.
SENTRY-2054: Unit tests must create temporary files under the Maven target directory (Sergio Pena, reviewed by kalyan kumar kalvagadda)
Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/0b487f37
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/0b487f37
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/0b487f37
Branch: refs/heads/akolb-cli
Commit: 0b487f3787286e334e8157e4dc31c0bba83b7bbb
Parents: 832e8da
Author: Sergio Pena <se...@cloudera.com>
Authored: Sat Nov 18 08:16:22 2017 -0600
Committer: Sergio Pena <se...@cloudera.com>
Committed: Sat Nov 18 08:16:22 2017 -0600
----------------------------------------------------------------------
pom.xml | 15 +++++++++++++++
1 file changed, 15 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sentry/blob/0b487f37/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 7476b4f..6487a26 100644
--- a/pom.xml
+++ b/pom.xml
@@ -52,6 +52,7 @@ limitations under the License.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<buildtools.dir>${basedir}/build-tools</buildtools.dir>
+ <test.tmp.dir>${project.build.directory}/tmp</test.tmp.dir>
<maven.compile.source>1.8</maven.compile.source>
<maven.compile.target>1.8</maven.compile.target>
<failIfNoTests>false</failIfNoTests>
@@ -706,6 +707,19 @@ limitations under the License.
</target>
</configuration>
</execution>
+ <execution>
+ <id>setup-test-dirs</id>
+ <phase>process-test-resources</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <target>
+ <delete dir="${test.tmp.dir}" />
+ <mkdir dir="${test.tmp.dir}" />
+ </target>
+ </configuration>
+ </execution>
</executions>
</plugin>
@@ -797,6 +811,7 @@ limitations under the License.
<argLine>-Xms512m -Xmx2g -XX:MaxPermSize=256m</argLine>
<systemPropertyVariables>
<java.net.preferIPv4Stack>true</java.net.preferIPv4Stack>
+ <java.io.tmpdir>${test.tmp.dir}</java.io.tmpdir>
</systemPropertyVariables>
</configuration>
</plugin>
[6/9] sentry git commit: SENTRY-2057: Set hadoop.tmp.dir to the maven
build directory configured on java.io.tmpdir (Sergio Pena, no reviewed)
Posted by co...@apache.org.
SENTRY-2057: Set hadoop.tmp.dir to the maven build directory configured on java.io.tmpdir (Sergio Pena, no reviewed)
This patch allows the sentry tests to use the target/ directory of the maven build directory to be used as a temporary place for MR jobs.
This helps on the current test issues found on Jenkins where the /tmp is cleaned up after sometime for an unknown reason.
Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/a3559799
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/a3559799
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/a3559799
Branch: refs/heads/akolb-cli
Commit: a355979914bd50cfb68fe9f45dcf471a33e5f9c4
Parents: 0b487f3
Author: Sergio Pena <se...@cloudera.com>
Authored: Sun Nov 19 08:43:13 2017 -0600
Committer: Sergio Pena <se...@cloudera.com>
Committed: Sun Nov 19 08:43:13 2017 -0600
----------------------------------------------------------------------
.../apache/sentry/tests/e2e/hdfs/TestHDFSIntegrationBase.java | 5 +++++
.../sentry/tests/e2e/hive/hiveserver/HiveServerFactory.java | 5 +++++
2 files changed, 10 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sentry/blob/a3559799/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegrationBase.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegrationBase.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegrationBase.java
index 3c8b70e..7495fc7 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegrationBase.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hdfs/TestHDFSIntegrationBase.java
@@ -570,6 +570,11 @@ public abstract class TestHDFSIntegrationBase {
hiveConf.set(ConfVars.METASTORE_DISALLOW_INCOMPATIBLE_COL_TYPE_CHANGES.varname, "false");
hiveConf.set(ConfVars.HIVE_IN_TEST.varname, "true");
+ // Sets the hadoop temporary directory specified by the java.io.tmpdir (already set to the
+ // maven build directory to avoid writing to the /tmp directly
+ String hadoopTempDir = System.getProperty("java.io.tmpdir") + File.separator + "hadoop-tmp";
+ hiveConf.set("hadoop.tmp.dir", hadoopTempDir);
+
// Sets hive.metastore.authorization.storage.checks to true, so that
// disallow the operations such as drop-partition if the user in question
// doesn't have permissions to delete the corresponding directory
http://git-wip-us.apache.org/repos/asf/sentry/blob/a3559799/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/hiveserver/HiveServerFactory.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/hiveserver/HiveServerFactory.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/hiveserver/HiveServerFactory.java
index 64c6394..d5eb137 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/hiveserver/HiveServerFactory.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/hiveserver/HiveServerFactory.java
@@ -201,6 +201,11 @@ public class HiveServerFactory {
// to HIVESERVER2 if we're using the authorization V2 in test mode.
properties.put(ConfVars.HIVE_TEST_AUTHORIZATION_SQLSTD_HS2_MODE.varname, "true");
+ // Sets the hadoop temporary directory specified by the java.io.tmpdir (already set to the
+ // maven build directory to avoid writing to the /tmp directly
+ String hadoopTempDir = System.getProperty("java.io.tmpdir") + File.separator + "hadoop-tmp";
+ properties.put("hadoop.tmp.dir", hadoopTempDir);
+
if (!properties.containsKey(METASTORE_BYPASS)) {
properties.put(METASTORE_BYPASS, "hive,impala," + System.getProperty("user.name", ""));
} else {
[4/9] sentry git commit: SENTRY-2047: isTableEmptyCore method in
SentryStore has references to MAuthzPathsMapping when it should be generic
(Arjun Mishra, reviewed by Vadim Spector)
Posted by co...@apache.org.
SENTRY-2047: isTableEmptyCore method in SentryStore has references to MAuthzPathsMapping when it should be generic (Arjun Mishra, reviewed by Vadim Spector)
Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/832e8da0
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/832e8da0
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/832e8da0
Branch: refs/heads/akolb-cli
Commit: 832e8da0f30f8db9131e30fabad5dca9f8631d21
Parents: 9c541ad
Author: Vadim Spector <vs...@cloudera.com>
Authored: Fri Nov 17 08:58:27 2017 -0800
Committer: Vadim Spector <vs...@cloudera.com>
Committed: Fri Nov 17 08:58:27 2017 -0800
----------------------------------------------------------------------
.../apache/sentry/provider/db/service/persistent/SentryStore.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sentry/blob/832e8da0/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 7217dea..4dc2bf6 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
@@ -3248,7 +3248,7 @@ public class SentryStore {
// objects up to the "to" record, and will not pass any unnecessary objects that are before
// the "from" record.
query.setRange(0, 1);
- return ((List<MAuthzPathsMapping>) query.execute()).isEmpty();
+ return ((List<?>) query.execute()).isEmpty();
}
/**
[3/9] sentry git commit: SENTRY-2032: Leading Slashes need to removed
when creating HMS path entries (Arjun Mishra, reviewed by Alexander Kolbasov,
Vadim Spector)
Posted by co...@apache.org.
SENTRY-2032: Leading Slashes need to removed when creating HMS path entries (Arjun Mishra, reviewed by Alexander Kolbasov, Vadim Spector)
Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/9c541adf
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/9c541adf
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/9c541adf
Branch: refs/heads/akolb-cli
Commit: 9c541adf15194c44800555f0fb161463df68feac
Parents: 5fc1e97
Author: Vadim Spector <vs...@cloudera.com>
Authored: Fri Nov 17 08:51:41 2017 -0800
Committer: Vadim Spector <vs...@cloudera.com>
Committed: Fri Nov 17 08:51:41 2017 -0800
----------------------------------------------------------------------
.../sentry/core/common/utils/PathUtils.java | 8 ++-
.../sentry/core/common/utils/TestPathUtils.java | 27 ++++++++++
.../db/service/persistent/TestSentryStore.java | 57 ++++++++++++++++++++
3 files changed, 90 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sentry/blob/9c541adf/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/PathUtils.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/PathUtils.java b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/PathUtils.java
index cef8bd7..2d67a5b 100644
--- a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/PathUtils.java
+++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/PathUtils.java
@@ -215,9 +215,13 @@ public class PathUtils {
* Split path into elements.
* May evolve to do something smarter, e.g. path canonicalization,
* but for now simple split on "/" is sufficient.
+ *
+ * Remove leading, following, and consecutive slashes from path so
+ * input like "//a/b//c///" when split gives
+ * {a,b,c} instead of {"","",a,b,"",c,"","",""}
*/
public static String[] splitPath(String path) {
- return (path != null) ? path.split("/+") : null;
+ path = path.replaceAll("(^/+)|(/+$)", "");
+ return path.split("/+");
}
-
}
http://git-wip-us.apache.org/repos/asf/sentry/blob/9c541adf/sentry-core/sentry-core-common/src/test/java/org/apache/sentry/core/common/utils/TestPathUtils.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/test/java/org/apache/sentry/core/common/utils/TestPathUtils.java b/sentry-core/sentry-core-common/src/test/java/org/apache/sentry/core/common/utils/TestPathUtils.java
index 8419b9d..329e668 100644
--- a/sentry-core/sentry-core-common/src/test/java/org/apache/sentry/core/common/utils/TestPathUtils.java
+++ b/sentry-core/sentry-core-common/src/test/java/org/apache/sentry/core/common/utils/TestPathUtils.java
@@ -21,8 +21,11 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import com.google.common.collect.Lists;
import java.net.URI;
+import java.util.Arrays;
+import java.util.List;
import org.junit.Test;
public class TestPathUtils {
@@ -146,4 +149,28 @@ public class TestPathUtils {
assertEquals("file://localhost:9999/tmp/hive-user",
PathUtils.parseLocalURI("file://localhost:9999/tmp/hive-user"));
}
+
+ @Test
+ public void testStripSurplusSlashesAndSplitPath() throws Exception {
+
+ List<String> expected = Arrays.asList("a", "b", "c");
+
+ String path = "a/b/c";
+ assertEquals("Invalid split doesn't match expected output", expected, Lists.newArrayList(PathUtils.splitPath(path)));
+
+ path = "/a/b/c";
+ assertEquals("Invalid split doesn't match expected output", expected, Lists.newArrayList(PathUtils.splitPath(path)));
+
+ path = "a/b/c/";
+ assertEquals("Invalid split doesn't match expected output", expected, Lists.newArrayList(PathUtils.splitPath(path)));
+
+ path = "/a/b/c/";
+ assertEquals("Invalid split doesn't match expected output", expected, Lists.newArrayList(PathUtils.splitPath(path)));
+
+ path = "/////a/b/c///";
+ assertEquals("Invalid split doesn't match expected output", expected, Lists.newArrayList(PathUtils.splitPath(path)));
+
+ path = "/////a//b//c///";
+ assertEquals("Invalid split doesn't match expected output", expected, Lists.newArrayList(PathUtils.splitPath(path)));
+ }
}
http://git-wip-us.apache.org/repos/asf/sentry/blob/9c541adf/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStore.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStore.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStore.java
index cf83e77..90f35f1 100644
--- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStore.java
+++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStore.java
@@ -3461,4 +3461,61 @@ public class TestSentryStore extends org.junit.Assert {
}
}
+ /**
+ * Test paths with multiple leading slashes
+ * @throws Exception
+ */
+ @Test
+ public void testRetrievePathImageWithMultipleLeadingSlashes() throws Exception {
+ //Test with no leading slashes
+ String prefix = "user/hive/warehouse";
+ String []prefixes = {"/" + prefix};
+ Map<String, Collection<String>> authzPaths = new HashMap<>();
+ // Makes sure that authorizable object could be associated
+ // with different paths and can be properly persisted into database.
+ String tablePath = prefix + "/loc1/db2.db/table1.1";
+ authzPaths.put("db1.table1", Sets.newHashSet(tablePath));
+ long notificationID = 1;
+ sentryStore.persistFullPathsImage(authzPaths, notificationID);
+ PathsUpdate pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes);
+ assertEquals(notificationID, pathsUpdate.getImgNum());
+ TPathsUpdate tPathsUpdate = pathsUpdate.toThrift();
+ TPathsDump pathDump = tPathsUpdate.getPathsDump();
+ Map<Integer, TPathEntry> nodeMap = pathDump.getNodeMap();
+ assertEquals(7, nodeMap.size());
+
+ //Test with single leading slashes
+ prefix = "/user/hive/warehouse";
+ prefixes = new String[]{prefix};
+ authzPaths = new HashMap<>();
+ // Makes sure that authorizable object could be associated
+ // with different paths and can be properly persisted into database.
+ tablePath = prefix + "/loc1/db2.db/table1.1";
+ authzPaths.put("db1.table1", Sets.newHashSet(tablePath));
+ notificationID = 2;
+ sentryStore.persistFullPathsImage(authzPaths, notificationID);
+ pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes);
+ assertEquals(notificationID, pathsUpdate.getImgNum());
+ tPathsUpdate = pathsUpdate.toThrift();
+ pathDump = tPathsUpdate.getPathsDump();
+ nodeMap = pathDump.getNodeMap();
+ assertEquals(7, nodeMap.size());
+
+ //Test with multiple leading slash
+ prefix = "///user/hive/warehouse";
+ prefixes = new String[]{prefix};
+ authzPaths = new HashMap<>();
+ // Makes sure that authorizable object could be associated
+ // with different paths and can be properly persisted into database.
+ tablePath = prefix + "/loc1/db2.db/table1.1";
+ authzPaths.put("db1.table1", Sets.newHashSet(tablePath));
+ notificationID = 3;
+ sentryStore.persistFullPathsImage(authzPaths, notificationID);
+ pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes);
+ assertEquals(notificationID, pathsUpdate.getImgNum());
+ tPathsUpdate = pathsUpdate.toThrift();
+ pathDump = tPathsUpdate.getPathsDump();
+ nodeMap = pathDump.getNodeMap();
+ assertEquals(7, nodeMap.size());
+ }
}
[8/9] sentry git commit: SENTRY-1640: Implement HMS Notification
barrier on the HMS plugin side (Sergio Pena,
reviewed by kalyan kumar kalvagadda)
Posted by co...@apache.org.
SENTRY-1640: Implement HMS Notification barrier on the HMS plugin side (Sergio Pena, reviewed by kalyan kumar kalvagadda)
Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/372ffc9b
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/372ffc9b
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/372ffc9b
Branch: refs/heads/akolb-cli
Commit: 372ffc9b4c662b0d076940b7526d2fe58c8a6a09
Parents: 5f64fe9
Author: Sergio Pena <se...@cloudera.com>
Authored: Sun Nov 19 15:12:39 2017 -0600
Committer: Sergio Pena <se...@cloudera.com>
Committed: Sun Nov 19 15:12:39 2017 -0600
----------------------------------------------------------------------
...rySyncHMSNotificationsPostEventListener.java | 230 +++++++++++++++++++
...rySyncHMSNotificationsPostEventListener.java | 161 +++++++++++++
.../thrift/SentryPolicyServiceClient.java | 9 +
.../SentryPolicyServiceClientDefaultImpl.java | 13 ++
4 files changed, 413 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sentry/blob/372ffc9b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/metastore/SentrySyncHMSNotificationsPostEventListener.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/metastore/SentrySyncHMSNotificationsPostEventListener.java b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/metastore/SentrySyncHMSNotificationsPostEventListener.java
new file mode 100644
index 0000000..24d7763
--- /dev/null
+++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/metastore/SentrySyncHMSNotificationsPostEventListener.java
@@ -0,0 +1,230 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sentry.binding.metastore;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.MetaStoreEventListener;
+import org.apache.hadoop.hive.metastore.MetaStoreEventListenerConstants;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.events.AddPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.AlterPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.AlterTableEvent;
+import org.apache.hadoop.hive.metastore.events.CreateDatabaseEvent;
+import org.apache.hadoop.hive.metastore.events.CreateTableEvent;
+import org.apache.hadoop.hive.metastore.events.DropDatabaseEvent;
+import org.apache.hadoop.hive.metastore.events.DropPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.DropTableEvent;
+import org.apache.hadoop.hive.metastore.events.ListenerEvent;
+import org.apache.sentry.binding.hive.conf.HiveAuthzConf;
+import org.apache.sentry.provider.db.service.thrift.SentryPolicyServiceClient;
+import org.apache.sentry.service.thrift.SentryServiceClientFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * This HMS post-event listener is used only to synchronize with HMS notifications on the Sentry server
+ * whenever a DDL event happens on the Hive metastore.
+ */
+public class SentrySyncHMSNotificationsPostEventListener extends MetaStoreEventListener {
+ private static final Logger LOGGER = LoggerFactory.getLogger(SentrySyncHMSNotificationsPostEventListener.class);
+
+ private final HiveAuthzConf authzConf;
+
+ /*
+ * Latest processed ID by the Sentry server. May only increase.
+ *
+ * This listener will track the latest event ID processed by the Sentry server so that it avoids calling
+ * the sync request in case a late thread attempts to synchronize again an already processed ID.
+ *
+ * The variable is shared across threads, so the AtomicLong variable guarantees that is increased
+ * monotonically.
+ */
+ private final AtomicLong latestProcessedId = new AtomicLong(0);
+
+ /*
+ * A client used for testing purposes only. I
+ *
+ * It may be set by unit-tests as a mock object and used to verify that the client methods
+ * were called correctly (see TestSentrySyncHMSNotificationsPostEventListener)
+ */
+ private SentryPolicyServiceClient serviceClient;
+
+ public SentrySyncHMSNotificationsPostEventListener(Configuration config) {
+ super(config);
+
+ if (!(config instanceof HiveConf)) {
+ String error = "Could not initialize Plugin - Configuration is not an instanceof HiveConf";
+ LOGGER.error(error);
+ throw new RuntimeException(error);
+ }
+
+ authzConf = HiveAuthzConf.getAuthzConf((HiveConf)config);
+ }
+
+ @Override
+ public void onCreateTable(CreateTableEvent tableEvent) throws MetaException {
+ syncNotificationEvents(tableEvent, "onCreateTable");
+ }
+
+ @Override
+ public void onDropTable(DropTableEvent tableEvent) throws MetaException {
+ syncNotificationEvents(tableEvent, "onDropTable");
+ }
+
+ @Override
+ public void onAlterTable(AlterTableEvent tableEvent) throws MetaException {
+ // no-op
+ }
+
+ @Override
+ public void onAddPartition(AddPartitionEvent partitionEvent) throws MetaException {
+ // no-op
+ }
+
+ @Override
+ public void onDropPartition(DropPartitionEvent partitionEvent) throws MetaException {
+ // no-op
+ }
+
+ @Override
+ public void onAlterPartition(AlterPartitionEvent partitionEvent) throws MetaException {
+ // no-op
+ }
+
+ @Override
+ public void onCreateDatabase(CreateDatabaseEvent dbEvent) throws MetaException {
+ syncNotificationEvents(dbEvent, "onCreateDatabase");
+ }
+
+ @Override
+ public void onDropDatabase(DropDatabaseEvent dbEvent) throws MetaException {
+ syncNotificationEvents(dbEvent, "onDropDatabase");
+ }
+
+ /**
+ * It requests the Sentry server the synchronization of recent notification events.
+ *
+ * After the sync call, the latest processed ID will be stored for future reference to avoid
+ * syncing an ID that was already processed.
+ *
+ * @param event An event that contains a DB_NOTIFICATION_EVENT_ID_KEY_NAME value to request.
+ */
+ private void syncNotificationEvents(ListenerEvent event, String eventName) {
+ // Do not sync notifications if the event has failed.
+ if (failedEvent(event, eventName)) {
+ return;
+ }
+
+ Map<String, String> eventParameters = event.getParameters();
+ if (!eventParameters.containsKey(MetaStoreEventListenerConstants.DB_NOTIFICATION_EVENT_ID_KEY_NAME)) {
+ return;
+ }
+
+ /* If the HMS is running in an active transaction, then we do not want to sync with Sentry
+ * because the desired eventId is not available for Sentry yet, and Sentry may block the HMS
+ * forever or until a read time-out happens. */
+ if (isMetastoreTransactionActive(eventParameters)) {
+ return;
+ }
+
+ long eventId =
+ Long.parseLong(eventParameters.get(MetaStoreEventListenerConstants.DB_NOTIFICATION_EVENT_ID_KEY_NAME));
+
+ // This check is only for performance reasons to avoid calling the sync thrift call if the Sentry server
+ // already processed the requested eventId.
+ if (eventId <= latestProcessedId.get()) {
+ return;
+ }
+
+ try(SentryPolicyServiceClient sentryClient = this.getSentryServiceClient()) {
+ LOGGER.debug("Starting Sentry/HMS notifications sync for {} (id: {})", eventName, eventId);
+ long sentryLatestProcessedId = sentryClient.syncNotifications(eventId);
+ LOGGER.debug("Finished Sentry/HMS notifications sync for {} (id: {})", eventName, eventId);
+ LOGGER.debug("Latest processed event ID returned by the Sentry server: {}", sentryLatestProcessedId);
+
+ updateProcessedId(sentryLatestProcessedId);
+ } catch (Exception e) {
+ // This error is only logged. There is no need to throw an error to Hive because HMS sync is called
+ // after the notification is already generated by Hive (as post-event).
+ LOGGER.error("Failed to sync requested HMS notifications up to the event ID: " + eventId, e);
+ }
+ }
+
+ /**
+ * @return True if the HMS is calling this notification in an active transaction; False otherwise
+ */
+ private boolean isMetastoreTransactionActive(Map<String, String> parameters) {
+ String transactionActive =
+ parameters.get(MetaStoreEventListenerConstants.HIVE_METASTORE_TRANSACTION_ACTIVE);
+
+ return transactionActive != null && Boolean.valueOf(transactionActive);
+ }
+
+ /**
+ * Updates the latest processed ID, if and only if eventId is bigger. This keeps the contract that
+ * {@link #latestProcessedId} may only increase.
+ *
+ * @param eventId The value to be set on the {@link #latestProcessedId}
+ */
+ private void updateProcessedId(long eventId) {
+ long oldVal = latestProcessedId.get();
+ if (eventId > oldVal) {
+ // It is fine for the compareAndSet to fail
+ latestProcessedId.compareAndSet(oldVal, eventId);
+ }
+ }
+
+ /**
+ * Sets the sentry client object (for testing purposes only)
+ *
+ * It may be set by unit-tests as a mock object and used to verify that the client methods
+ * were called correctly (see TestSentrySyncHMSNotificationsPostEventListener).
+ */
+ @VisibleForTesting
+ void setSentryServiceClient(SentryPolicyServiceClient serviceClient) {
+ this.serviceClient = serviceClient;
+ }
+
+ private SentryPolicyServiceClient getSentryServiceClient() throws MetaException {
+ // Return the sentry client in case was set by the unit tests.
+ if (serviceClient != null) {
+ return serviceClient;
+ }
+
+ try {
+ return SentryServiceClientFactory.create(authzConf);
+ } catch (Exception e) {
+ throw new MetaException("Failed to connect to Sentry service " + e.getMessage());
+ }
+ }
+
+ private boolean failedEvent(ListenerEvent event, String eventName) {
+ if (!event.getStatus()) {
+ LOGGER.debug("Skip HMS synchronization request with the Sentry server for {} " +
+ "{} since the operation failed. \n", eventName, event);
+ return true;
+ }
+
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sentry/blob/372ffc9b/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/metastore/TestSentrySyncHMSNotificationsPostEventListener.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/metastore/TestSentrySyncHMSNotificationsPostEventListener.java b/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/metastore/TestSentrySyncHMSNotificationsPostEventListener.java
new file mode 100644
index 0000000..cca326b
--- /dev/null
+++ b/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/metastore/TestSentrySyncHMSNotificationsPostEventListener.java
@@ -0,0 +1,161 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sentry.binding.metastore;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.MetaStoreEventListenerConstants;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.events.CreateDatabaseEvent;
+import org.apache.hadoop.hive.metastore.events.CreateTableEvent;
+import org.apache.hadoop.hive.metastore.events.DropDatabaseEvent;
+import org.apache.hadoop.hive.metastore.events.DropTableEvent;
+import org.apache.hadoop.hive.metastore.events.ListenerEvent;
+import org.apache.sentry.binding.hive.conf.HiveAuthzConf;
+import org.apache.sentry.core.common.exception.SentryUserException;
+import org.apache.sentry.provider.db.service.thrift.SentryPolicyServiceClient;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * Testing class that tests and verifies the sync sentry notifications are called correctly.
+ */
+public class TestSentrySyncHMSNotificationsPostEventListener {
+ private static final boolean FAILED_STATUS = false;
+ private static final boolean SUCCESSFUL_STATUS = true;
+ private static final boolean EVENT_ID_SET = true;
+ private static final boolean EVENT_ID_UNSET = false;
+
+ private SentrySyncHMSNotificationsPostEventListener eventListener;
+ private SentryPolicyServiceClient mockSentryClient;
+
+ @Rule
+ public TemporaryFolder tempFolder = new TemporaryFolder();
+
+ @Before
+ public void setUp() throws IOException, MetaException, SentryUserException {
+ String sentryConfFile = tempFolder.newFile().getAbsolutePath();
+
+ HiveConf hiveConf = new HiveConf(TestSentrySyncHMSNotificationsPostEventListener.class);
+ hiveConf.set(HiveAuthzConf.HIVE_SENTRY_CONF_URL, "file://" + sentryConfFile);
+
+ // Instead of generating an empty sentry-site.xml, we just write the same info from HiveConf.
+ // The SentrySyncHMSNotificationsPostEventListener won't use any information from it after all.
+ hiveConf.writeXml(new FileOutputStream(sentryConfFile));
+
+ eventListener = new SentrySyncHMSNotificationsPostEventListener(hiveConf);
+
+ mockSentryClient = Mockito.mock(SentryPolicyServiceClient.class);
+
+ // For some reason I cannot use a Mockito.spy() on the eventListener and just mock the
+ // getSentryServiceClient() to return the mock. When the TestURI runs before this
+ // test, then a mock exception is thrown saying a I have an unfinished stubbing method.
+ // This was the best approach I could take for now.
+ eventListener.setSentryServiceClient(mockSentryClient);
+ }
+
+ @Test
+ public void testFailedEventsDoNotSyncNotifications() throws MetaException, SentryUserException {
+ callAllEventsThatSynchronize(FAILED_STATUS, EVENT_ID_UNSET);
+ Mockito.verifyZeroInteractions(mockSentryClient);
+ }
+
+ @Test
+ public void testEventsWithoutAnEventIdDoNotSyncNotifications() throws MetaException {
+ callAllEventsThatSynchronize(SUCCESSFUL_STATUS, EVENT_ID_UNSET);
+ Mockito.verifyZeroInteractions(mockSentryClient);
+ }
+
+ @Test
+ public void testSuccessfulEventsWithAnEventIdSyncNotifications() throws Exception {
+ long latestEventId = callAllEventsThatSynchronize(SUCCESSFUL_STATUS, EVENT_ID_SET);
+
+ for (int i=1; i<=latestEventId; i++) {
+ Mockito.verify(
+ mockSentryClient, Mockito.times(1)
+ ).syncNotifications(i);
+ }
+
+ Mockito.verify(
+ mockSentryClient, Mockito.times((int)latestEventId)
+ ).close();
+
+ Mockito.verifyNoMoreInteractions(mockSentryClient);
+ }
+
+ @Test
+ public void testSyncNotificationsWithNewLatestProcessedIdMayAvoidSyncingCalls() throws Exception {
+ Mockito.doAnswer(new Answer<Long>() {
+ @Override
+ public Long answer(InvocationOnMock invocation) throws Throwable {
+ Long id = (Long)invocation.getArguments()[0];
+ return id + 1;
+ }
+ }).when(mockSentryClient).syncNotifications(Mockito.anyLong());
+
+ long latestEventId = callAllEventsThatSynchronize(SUCCESSFUL_STATUS, EVENT_ID_SET);
+
+ for (int i=1; i<=latestEventId; i+=2) {
+ Mockito.verify(
+ mockSentryClient, Mockito.times(1)
+ ).syncNotifications(i);
+ }
+
+ Mockito.verify(
+ mockSentryClient, Mockito.times((int)latestEventId / 2)
+ ).close();
+
+ Mockito.verifyNoMoreInteractions(mockSentryClient);
+ }
+
+ private long callAllEventsThatSynchronize(boolean status, boolean eventIdSet) throws MetaException {
+ long eventId = 0;
+
+ CreateDatabaseEvent createDatabaseEvent = new CreateDatabaseEvent(null, status , null);
+ setEventId(eventIdSet, createDatabaseEvent, ++eventId);
+ eventListener.onCreateDatabase(createDatabaseEvent);
+
+ DropDatabaseEvent dropDatabaseEvent = new DropDatabaseEvent(null, status , null);
+ setEventId(eventIdSet, dropDatabaseEvent, ++eventId);
+ eventListener.onDropDatabase(dropDatabaseEvent);
+
+ CreateTableEvent createTableEvent = new CreateTableEvent(null, status , null);
+ setEventId(eventIdSet, createTableEvent, ++eventId);
+ eventListener.onCreateTable(createTableEvent);
+
+ DropTableEvent dropTableEvent = new DropTableEvent(null, status , false, null);
+ setEventId(eventIdSet, dropTableEvent, ++eventId);
+ eventListener.onDropTable(dropTableEvent);
+
+ return eventId;
+ }
+
+ private void setEventId(boolean eventIdSet, ListenerEvent eventListener, long eventId) {
+ if (eventIdSet) {
+ eventListener.putParameter(
+ MetaStoreEventListenerConstants.DB_NOTIFICATION_EVENT_ID_KEY_NAME, String.valueOf(eventId));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sentry/blob/372ffc9b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClient.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClient.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClient.java
index 61833fc..f69a8cd 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClient.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClient.java
@@ -215,4 +215,13 @@ public interface SentryPolicyServiceClient extends AutoCloseable {
// export the sentry mapping data with map structure
Map<String, Map<String, Set<String>>> exportPolicy(String requestorUserName, String objectPath)
throws SentryUserException;
+
+ /**
+ * Requests the sentry server to synchronize all HMS notification events up to the specified id.
+ * The sentry server will return once it have processed the id specified..
+ *
+ * @param id Requested HMS notification ID.
+ * @return The most recent processed notification ID.
+ */
+ long syncNotifications(long id) throws SentryUserException;
}
http://git-wip-us.apache.org/repos/asf/sentry/blob/372ffc9b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClientDefaultImpl.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClientDefaultImpl.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClientDefaultImpl.java
index 7ada138..bede5b1 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClientDefaultImpl.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClientDefaultImpl.java
@@ -1065,4 +1065,17 @@ public class SentryPolicyServiceClientDefaultImpl implements SentryPolicyService
transport = null;
}
}
+
+ public long syncNotifications(long id) throws SentryUserException {
+ TSentrySyncIDRequest request =
+ new TSentrySyncIDRequest(ThriftConstants.TSENTRY_SERVICE_VERSION_CURRENT, id);
+
+ try {
+ TSentrySyncIDResponse response = client.sentry_sync_notifications(request);
+ Status.throwIfNotOk(response.getStatus());
+ return response.getId();
+ } catch (TException e) {
+ throw new SentryUserException(THRIFT_EXCEPTION_MESSAGE, e);
+ }
+ }
}
\ No newline at end of file