Repository: incubator-sentry Updated Branches: refs/heads/master 197164e06 -> a337480eb
SENTRY-165: Implement createShowRolesTask() in SentryHiveAuthorizationTaskFactoryImpl (Sravya Tirukkovalur via Brock Noland) Project: http://git-wip-us.apache.org/repos/asf/incubator-sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-sentry/commit/a337480e Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/a337480e Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/a337480e Branch: refs/heads/master Commit: a337480eb2cbf7f61716aaed6c31b4e11b63bb4a Parents: 197164e Author: Sravya Tirukkovalur <[email protected]> Authored: Mon Apr 14 18:31:15 2014 -0700 Committer: Sravya Tirukkovalur <[email protected]> Committed: Tue Apr 15 16:06:26 2014 -0700 ---------------------------------------------------------------------- .../SentryHiveAuthorizationTaskFactoryImpl.java | 31 ++++++++++++-------- .../TestSentryHiveAuthorizationTaskFactory.java | 30 +++++++++++++++---- 2 files changed, 43 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/a337480e/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryHiveAuthorizationTaskFactoryImpl.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryHiveAuthorizationTaskFactoryImpl.java b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryHiveAuthorizationTaskFactoryImpl.java index de0e460..2e7a9d9 100644 --- a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryHiveAuthorizationTaskFactoryImpl.java +++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryHiveAuthorizationTaskFactoryImpl.java @@ -16,11 +16,7 @@ */ package org.apache.sentry.binding.hive; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; - +import com.google.common.base.Preconditions; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hive.SentryHiveConstants; import org.apache.hadoop.hive.conf.HiveConf; @@ -50,7 +46,10 @@ import org.apache.hadoop.hive.ql.security.authorization.PrivilegeRegistry; import org.apache.hadoop.hive.ql.session.SessionState; import org.apache.sentry.core.model.db.AccessConstants; -import com.google.common.base.Preconditions; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; public class SentryHiveAuthorizationTaskFactoryImpl implements HiveAuthorizationTaskFactory { @@ -280,7 +279,18 @@ public class SentryHiveAuthorizationTaskFactoryImpl implements HiveAuthorization @Override public Task<? extends Serializable> createShowCurrentRoleTask(HashSet<ReadEntity> inputs, HashSet<WriteEntity> outputs, Path resultFile) throws SemanticException { - throw new SemanticException("TODO IN FOLLOW ON"); + RoleDDLDesc ddlDesc = new RoleDDLDesc(null, RoleDDLDesc.RoleOperation.SHOW_CURRENT_ROLE); + ddlDesc.setResFile(resultFile.toString()); + return createTask(new DDLWork(inputs, outputs, ddlDesc)); + } + + @Override + public Task<? extends Serializable> createShowRolesTask(ASTNode ast, Path resFile, + HashSet<ReadEntity> inputs, HashSet<WriteEntity> outputs) throws SemanticException { + RoleDDLDesc showRolesDesc = new RoleDDLDesc(null, null, RoleDDLDesc.RoleOperation.SHOW_ROLES, + null); + showRolesDesc.setResFile(resFile.toString()); + return createTask(new DDLWork(inputs, outputs, showRolesDesc)); } private PrivilegeObjectDesc analyzePrivilegeObject(ASTNode ast) @@ -353,10 +363,5 @@ public class SentryHiveAuthorizationTaskFactoryImpl implements HiveAuthorization return task; } - @Override - public Task<? extends Serializable> createShowRolesTask(ASTNode ast, - Path resFile, HashSet<ReadEntity> inputs, HashSet<WriteEntity> outputs) throws SemanticException { - /* TODO */ - throw new SemanticException("TODO IN FOLLOW ON"); - } + } http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/a337480e/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 a61f609..ac0d170 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 @@ -17,12 +17,7 @@ */ package org.apache.sentry.binding.hive; -import java.io.Serializable; -import java.util.HashMap; -import java.util.List; - import junit.framework.Assert; - import org.apache.hadoop.hive.SentryHiveConstants; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.conf.HiveConf.ConfVars; @@ -53,6 +48,10 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; +import java.io.Serializable; +import java.util.HashMap; +import java.util.List; + public class TestSentryHiveAuthorizationTaskFactory { private static final String ALL = "ALL"; @@ -348,6 +347,27 @@ public class TestSentryHiveAuthorizationTaskFactory { SentryHiveConstants.GRANT_REVOKE_NOT_SUPPORTED_FOR_PRINCIPAL + "GROUP"); } + /** + * SHOW ROLES + */ + @Test + public void testShowRoles() throws Exception { + DDLWork work = analyze(parse("SHOW ROLES")); + RoleDDLDesc roleDDLDesc = work.getRoleDDLDesc(); + Assert.assertEquals(RoleOperation.SHOW_ROLES, roleDDLDesc.getOperation()); + } + + /** + * SHOW CURRENT ROLE + */ + @Test + public void testShowCurrentRole() throws Exception { + DDLWork work = analyze(parse("SHOW CURRENT ROLES")); + RoleDDLDesc roleDDLDesc = work.getRoleDDLDesc(); + Assert.assertEquals(PrincipalType.USER, roleDDLDesc.getPrincipalType()); + Assert.assertEquals(RoleOperation.SHOW_CURRENT_ROLE, roleDDLDesc.getOperation()); + } + private void expectSemanticException(String command, String msg) throws Exception { try { analyze(parse(command));
