SentryShellSolr extends SentryShellCommon { public static void main(String[] args) throws Exception { SentryShellSolr sentryShell = new SentryShellSolr(); try { sentryShell.executeShell(args); } catch (Exception e) { LOGGER.error(e.getMessage(), e); Throwable current = e; while (current != null && current.getMessage() == null) { current = current.getCause(); } String error = ""; if (current != null && current.getMessage() != null) { error = "Message: " + current.getMessage(); } System.out.println("The operation failed. " + error); System.exit(1); } }  @Override void run(); static void main(String[] args); static final String SOLR_SERVICE_NAME; }
@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() }; SentryShellSolr.main(args); args = new String[] { "--create_role", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath() }; SentryShellSolr.main(args); args = new String[] { "-lr", "-conf", confPath.getAbsolutePath() }; SentryShellSolr sentryShell = new SentryShellSolr(); 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 SentryShellSolr(); 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() }; SentryShellSolr.main(args); args = new String[] { "--drop_role", "-r", TEST_ROLE_NAME_2, "-conf", confPath.getAbsolutePath() }; SentryShellSolr.main(args); Set<TSentryRole> roles = client.listAllRoles(requestorName, SOLR); 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, SOLR); client.createRole(requestorName, TEST_ROLE_NAME_2, SOLR); String[] args = { "-arg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_1, "-conf", confPath.getAbsolutePath() }; SentryShellSolr.main(args); args = new String[] { "-arg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_2 + "," + TEST_GROUP_3, "-conf", confPath.getAbsolutePath() }; SentryShellSolr.main(args); args = new String[] { "--add_role_group", "-r", TEST_ROLE_NAME_2, "-g", TEST_GROUP_1, "-conf", confPath.getAbsolutePath() }; SentryShellSolr.main(args); args = new String[] { "-lr", "-g", TEST_GROUP_1, "-conf", confPath.getAbsolutePath() }; SentryShellSolr sentryShell = new SentryShellSolr(); 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 SentryShellSolr(); 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(); 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() }; SentryShellSolr.main(args); args = new String[] { "-drg", "-r", TEST_ROLE_NAME_1, "-g", TEST_GROUP_2 + "," + TEST_GROUP_3, "-conf", confPath.getAbsolutePath() }; SentryShellSolr.main(args); args = new String[] { "--delete_role_group", "-r", TEST_ROLE_NAME_2, "-g", TEST_GROUP_1, "-conf", confPath.getAbsolutePath() }; SentryShellSolr.main(args); Set<TSentryRole> roles = client.listRolesByGroupName(requestorName, TEST_GROUP_1, SOLR); assertEquals("Incorrect number of roles", 0, roles.size()); roles = client.listRolesByGroupName(requestorName, TEST_GROUP_2, SOLR); assertEquals("Incorrect number of roles", 0, roles.size()); roles = client.listRolesByGroupName(requestorName, TEST_GROUP_3, SOLR); assertEquals("Incorrect number of roles", 0, roles.size()); client.dropRole(requestorName, TEST_ROLE_NAME_1, SOLR); client.dropRole(requestorName, TEST_ROLE_NAME_2, SOLR); } }); }
@Test public void testCaseSensitiveGroupName() throws Exception { runTestAsSubject(new TestOperation() { @Override public void runTestAsSubject() throws Exception { client.createRole(requestorName, TEST_ROLE_NAME_1, SOLR); String[] args = { "-arg", "-r", TEST_ROLE_NAME_1, "-g", "group1", "-conf", confPath.getAbsolutePath() }; SentryShellSolr.main(args); args = new String[] { "-lr", "-g", "group1", "-conf", confPath.getAbsolutePath() }; SentryShellSolr sentryShell = new SentryShellSolr(); 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); } }); }