SentryShellHive extends SentryShellCommon { public static void main(String[] args) throws Exception { SentryShellHive sentryShell = new SentryShellHive(); try { sentryShell.executeShell(args); } catch (Exception e) { LOGGER.error(e.getMessage(), e); Throwable current = e; while (current != null && current.getMessage() == null) { current = current.getCause(); } System.out.println("The operation failed." + (current.getMessage() == null ? "" : " Message: " + current.getMessage())); } }  void run(); static void main(String[] args);  }
@Test public void testCreateDropRole() throws Exception { runTestAsSubject(new TestOperation() { @Override public void runTestAsSubject() throws Exception { String[] args = { "-cr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); args = new String[] { "--create_role", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); args = new String[] { "-lr", "-conf", confPath.getAbsolutePath() }; SentryShellHive sentryShell = new SentryShellHive(); Set<String> roleNames = getShellResultWithOSRedirect(sentryShell, args, true); validateRoleNames(roleNames, TEST_ROLE_NAME_1, TEST_ROLE_NAME_2); args = new String[] { "--list_role", "-conf", confPath.getAbsolutePath() }; sentryShell = new SentryShellHive(); roleNames = getShellResultWithOSRedirect(sentryShell, args, true); validateRoleNames(roleNames, TEST_ROLE_NAME_1, TEST_ROLE_NAME_2); args = new String[] { "-dr", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); args = new String[] { "--drop_role", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); Set<TSentryRole> roles = client.listRoles(requestorName); assertEquals("Incorrect number of roles", 0, roles.size()); } }); }
@Test public void testAddDeleteRoleForGroup() throws Exception { runTestAsSubject(new TestOperation() { @Override public void runTestAsSubject() throws Exception { client.createRole(requestorName, TEST_ROLE_NAME_1); client.createRole(requestorName, TEST_ROLE_NAME_2); String[] args = { "-arg", "-r", TEST_ROLE_NAME_1, "-g", "testGroup1", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); args = new String[] { "-arg", "-r", TEST_ROLE_NAME_1, "-g", "testGroup2,testGroup3", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); args = new String[] { "--add_role_group", "-r", TEST_ROLE_NAME_2, "-g", "testGroup1", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); args = new String[] { "-lr", "-g", "testGroup1", "-conf", confPath.getAbsolutePath() }; SentryShellHive sentryShell = new SentryShellHive(); Set<String> roleNames = getShellResultWithOSRedirect(sentryShell, args, true); validateRoleNames(roleNames, TEST_ROLE_NAME_1, TEST_ROLE_NAME_2); args = new String[] { "--list_role", "-g", "testGroup2", "-conf", confPath.getAbsolutePath() }; sentryShell = new SentryShellHive(); roleNames = getShellResultWithOSRedirect(sentryShell, args, true); validateRoleNames(roleNames, TEST_ROLE_NAME_1); args = new String[] { "--list_role", "-g", "testGroup3", "-conf", confPath.getAbsolutePath() }; sentryShell = new SentryShellHive(); roleNames = getShellResultWithOSRedirect(sentryShell, args, true); validateRoleNames(roleNames, TEST_ROLE_NAME_1); args = new String[] { "-drg", "-r", TEST_ROLE_NAME_1, "-g", "testGroup1", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); args = new String[] { "-drg", "-r", TEST_ROLE_NAME_1, "-g", "testGroup2,testGroup3", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); args = new String[] { "--delete_role_group", "-r", TEST_ROLE_NAME_2, "-g", "testGroup1", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); Set<TSentryRole> roles = client.listRolesByGroupName(requestorName, "testGroup1"); assertEquals("Incorrect number of roles", 0, roles.size()); roles = client.listRolesByGroupName(requestorName, "testGroup2"); assertEquals("Incorrect number of roles", 0, roles.size()); roles = client.listRolesByGroupName(requestorName, "testGroup3"); assertEquals("Incorrect number of roles", 0, roles.size()); client.dropRole(requestorName, TEST_ROLE_NAME_1); client.dropRole(requestorName, TEST_ROLE_NAME_2); } }); }
@Test public void testGrantRevokePrivilegeWithShortOption() throws Exception { runTestAsSubject(new TestOperation() { @Override public void runTestAsSubject() throws Exception { client.createRole(requestorName, TEST_ROLE_NAME_1); client.createRole(requestorName, TEST_ROLE_NAME_2); String[] args = { "-gpr", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->action=*", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->db=db1->action=select", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->db=db1->table=tbl1->action=insert", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->db=db1->table=tbl1->column=col1->action=insert", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->db=db1->table=tbl1->column=col2->action=insert->grantoption=true", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->uri=hdfs: SentryShellHive.main(args); args = new String[] { "-lp", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() }; SentryShellHive sentryShell = new SentryShellHive(); Set<String> privilegeStrs = getShellResultWithOSRedirect(sentryShell, args, true); assertEquals("Incorrect number of privileges", 6, privilegeStrs.size()); assertTrue(privilegeStrs.contains("server=server1->action=*")); assertTrue(privilegeStrs.contains("server=server1->db=db1->action=select")); assertTrue(privilegeStrs.contains("server=server1->db=db1->table=tbl1->action=insert")); assertTrue(privilegeStrs .contains("server=server1->db=db1->table=tbl1->column=col1->action=insert")); assertTrue(privilegeStrs .contains("server=server1->db=db1->table=tbl1->column=col2->action=insert->grantoption=true")); assertTrue(privilegeStrs.contains("server=server1->uri=hdfs: args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->db=db1->table=tbl1->column=col1->action=insert", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); Set<TSentryPrivilege> privileges = client.listAllPrivilegesByRoleName(requestorName, TEST_ROLE_NAME_1); assertEquals("Incorrect number of privileges", 5, privileges.size()); args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->db=db1->table=tbl1->column=col2->action=insert->grantoption=true", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); privileges = client.listAllPrivilegesByRoleName(requestorName, TEST_ROLE_NAME_1); assertEquals("Incorrect number of privileges", 4, privileges.size()); args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->uri=hdfs: SentryShellHive.main(args); privileges = client.listAllPrivilegesByRoleName(requestorName, TEST_ROLE_NAME_1); assertEquals("Incorrect number of privileges", 3, privileges.size()); args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->db=db1->table=tbl1->action=insert", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); privileges = client.listAllPrivilegesByRoleName(requestorName, TEST_ROLE_NAME_1); assertEquals("Incorrect number of privileges", 2, privileges.size()); args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->db=db1->action=select", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); privileges = client.listAllPrivilegesByRoleName(requestorName, TEST_ROLE_NAME_1); assertEquals("Incorrect number of privileges", 1, privileges.size()); args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->action=*", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); privileges = client.listAllPrivilegesByRoleName(requestorName, TEST_ROLE_NAME_1); assertEquals("Incorrect number of privileges", 0, privileges.size()); client.dropRole(requestorName, TEST_ROLE_NAME_1); client.dropRole(requestorName, TEST_ROLE_NAME_2); } }); }
@Test public void testGrantRevokePrivilegeWithLongOption() throws Exception { runTestAsSubject(new TestOperation() { @Override public void runTestAsSubject() throws Exception { client.createRole(requestorName, TEST_ROLE_NAME_1); client.createRole(requestorName, TEST_ROLE_NAME_2); String[] args = { "--grant_privilege_role", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->action=*", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); args = new String[] { "--grant_privilege_role", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->db=db1->action=select", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); args = new String[] { "--grant_privilege_role", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->db=db1->table=tbl1->action=insert", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); args = new String[] { "--grant_privilege_role", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->db=db1->table=tbl1->column=col1->action=insert", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); args = new String[] { "--grant_privilege_role", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->db=db1->table=tbl1->column=col2->action=insert->grantoption=true", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); args = new String[] { "--grant_privilege_role", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->uri=hdfs: SentryShellHive.main(args); args = new String[] { "--list_privilege", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() }; SentryShellHive sentryShell = new SentryShellHive(); Set<String> privilegeStrs = getShellResultWithOSRedirect(sentryShell, args, true); assertEquals("Incorrect number of privileges", 6, privilegeStrs.size()); assertTrue(privilegeStrs.contains("server=server1->action=*")); assertTrue(privilegeStrs.contains("server=server1->db=db1->action=select")); assertTrue(privilegeStrs.contains("server=server1->db=db1->table=tbl1->action=insert")); assertTrue(privilegeStrs .contains("server=server1->db=db1->table=tbl1->column=col1->action=insert")); assertTrue(privilegeStrs .contains("server=server1->db=db1->table=tbl1->column=col2->action=insert->grantoption=true")); assertTrue(privilegeStrs.contains("server=server1->uri=hdfs: args = new String[] { "--revoke_privilege_role", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->db=db1->table=tbl1->column=col1->action=insert", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); Set<TSentryPrivilege> privileges = client.listAllPrivilegesByRoleName(requestorName, TEST_ROLE_NAME_1); assertEquals("Incorrect number of privileges", 5, privileges.size()); args = new String[] { "--revoke_privilege_role", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->db=db1->table=tbl1->column=col2->action=insert->grantoption=true", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); privileges = client.listAllPrivilegesByRoleName(requestorName, TEST_ROLE_NAME_1); assertEquals("Incorrect number of privileges", 4, privileges.size()); args = new String[] { "--revoke_privilege_role", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->uri=hdfs: SentryShellHive.main(args); privileges = client.listAllPrivilegesByRoleName(requestorName, TEST_ROLE_NAME_1); assertEquals("Incorrect number of privileges", 3, privileges.size()); args = new String[] { "--revoke_privilege_role", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->db=db1->table=tbl1->action=insert", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); privileges = client.listAllPrivilegesByRoleName(requestorName, TEST_ROLE_NAME_1); assertEquals("Incorrect number of privileges", 2, privileges.size()); args = new String[] { "--revoke_privilege_role", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->db=db1->action=select", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); privileges = client.listAllPrivilegesByRoleName(requestorName, TEST_ROLE_NAME_1); assertEquals("Incorrect number of privileges", 1, privileges.size()); args = new String[] { "--revoke_privilege_role", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->action=*", "-conf", confPath.getAbsolutePath() }; SentryShellHive.main(args); privileges = client.listAllPrivilegesByRoleName(requestorName, TEST_ROLE_NAME_1); assertEquals("Incorrect number of privileges", 0, privileges.size()); client.dropRole(requestorName, TEST_ROLE_NAME_1); client.dropRole(requestorName, TEST_ROLE_NAME_2); } }); }