SentryShellIndexer extends SentryShellGeneric { public static void main(String[] args) throws Exception { SentryShellIndexer sentryShell = new SentryShellIndexer(); 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())); System.exit(1); } }  @Override 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() }; SentryShellIndexer.main(args); args = new String[] { "--create_role", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath() }; SentryShellIndexer.main(args); args = new String[] { "-lr", "-conf", confPath.getAbsolutePath() }; SentryShellIndexer sentryShell = new SentryShellIndexer(); 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 SentryShellIndexer(); 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() }; SentryShellIndexer.main(args); args = new String[] { "--drop_role", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath() }; SentryShellIndexer.main(args); Set<TSentryRole> roles = client.listAllRoles(requestorName, HBASE_INDEXER); assertEquals("Incorrect number of roles", 0, roles.size()); } }); }
@Test public void testAddDeleteRoleForGroup() throws Exception { runTestAsSubject(new TestOperation() { @Override public void runTestAsSubject() throws Exception { String TEST_GROUP_1 = "testGroup1"; String TEST_GROUP_2 = "testGroup2"; String TEST_GROUP_3 = "testGroup3"; client.createRole(requestorName, TEST_ROLE_NAME_1, HBASE_INDEXER); client.createRole(requestorName, TEST_ROLE_NAME_2, HBASE_INDEXER); String[] args = { "-arg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_1, "-conf", confPath.getAbsolutePath() }; SentryShellIndexer.main(args); args = new String[] { "-arg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_2 + "," + TEST_GROUP_3, "-conf", confPath.getAbsolutePath() }; SentryShellIndexer.main(args); args = new String[] { "--add_role_group", "-r", TEST_ROLE_NAME_2, "-g", TEST_GROUP_1, "-conf", confPath.getAbsolutePath() }; SentryShellIndexer.main(args); args = new String[] { "-lr", "-g", TEST_GROUP_1, "-conf", confPath.getAbsolutePath() }; SentryShellIndexer sentryShell = new SentryShellIndexer(); Set<String> roleNames = getShellResultWithOSRedirect(sentryShell, args, true); validateRoleNames(roleNames, TEST_ROLE_NAME_1, TEST_ROLE_NAME_2); args = new String[] { "--list_role", "-g", TEST_GROUP_2, "-conf", confPath.getAbsolutePath() }; sentryShell = new SentryShellIndexer(); 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 SentryShellIndexer(); roleNames = getShellResultWithOSRedirect(sentryShell, args, true); validateRoleNames(roleNames, TEST_ROLE_NAME_1); args = new String[] { "-drg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_1, "-conf", confPath.getAbsolutePath() }; SentryShellIndexer.main(args); args = new String[] { "-drg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_2 + "," + TEST_GROUP_3, "-conf", confPath.getAbsolutePath() }; SentryShellIndexer.main(args); args = new String[] { "--delete_role_group", "-r", TEST_ROLE_NAME_2, "-g", TEST_GROUP_1, "-conf", confPath.getAbsolutePath() }; SentryShellIndexer.main(args); Set<TSentryRole> roles = client.listRolesByGroupName(requestorName, TEST_GROUP_1, HBASE_INDEXER); assertEquals("Incorrect number of roles", 0, roles.size()); roles = client.listRolesByGroupName(requestorName, TEST_GROUP_2, HBASE_INDEXER); assertEquals("Incorrect number of roles", 0, roles.size()); roles = client.listRolesByGroupName(requestorName, TEST_GROUP_3, HBASE_INDEXER); assertEquals("Incorrect number of roles", 0, roles.size()); client.dropRole(requestorName, TEST_ROLE_NAME_1, HBASE_INDEXER); client.dropRole(requestorName, TEST_ROLE_NAME_2, HBASE_INDEXER); } }); }
@Test public void testCaseSensitiveGroupName() throws Exception { runTestAsSubject(new TestOperation() { @Override public void runTestAsSubject() throws Exception { client.createRole(requestorName, TEST_ROLE_NAME_1, HBASE_INDEXER); String[] args = { "-arg", "-r", TEST_ROLE_NAME_1, "-g", "group1", "-conf", confPath.getAbsolutePath() }; SentryShellIndexer.main(args); args = new String[] { "-lr", "-g", "group1", "-conf", confPath.getAbsolutePath() }; SentryShellIndexer sentryShell = new SentryShellIndexer(); Set<String> roleNames = getShellResultWithOSRedirect(sentryShell, args, true); validateRoleNames(roleNames, TEST_ROLE_NAME_1); args = new String[] { "-lr", "-g", "GROUP1", "-conf", confPath.getAbsolutePath() }; roleNames = getShellResultWithOSRedirect(sentryShell, args, true); validateRoleNames(roleNames); } }); }