@Test public void deleteAllAuth() throws Exception { AccumuloClient client = EasyMock.createMock(AccumuloClient.class); CommandLine cli = EasyMock.createMock(CommandLine.class); Shell shellState = EasyMock.createMock(Shell.class); ConsoleReader reader = EasyMock.createMock(ConsoleReader.class); SecurityOperations secOps = EasyMock.createMock(SecurityOperations.class); EasyMock.expect(shellState.getAccumuloClient()).andReturn(client); EasyMock.expect(client.whoami()).andReturn("root"); EasyMock.expect(cli.getOptionValue("u", "root")).andReturn("foo"); EasyMock.expect(cli.getOptionValue("s")).andReturn("abc,123"); EasyMock.expect(client.securityOperations()).andReturn(secOps); EasyMock.expect(client.securityOperations()).andReturn(secOps); EasyMock.expect(secOps.getUserAuthorizations("foo")) .andReturn(new Authorizations("abc", "123")); secOps.changeUserAuthorizations("foo", new Authorizations()); EasyMock.expectLastCall(); EasyMock.replay(client, cli, shellState, reader, secOps); cmd.execute("deleteauths -u foo -s abc,123", cli, shellState); EasyMock.verify(client, cli, shellState, reader, secOps); }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException { final AccumuloClient accumuloClient = shellState.getAccumuloClient(); final String user = cl.getOptionValue(userOpt.getOpt(), accumuloClient.whoami()); final String scanOpts = cl.getOptionValue(scanOptAuths.getOpt()); final Authorizations auths = accumuloClient.securityOperations().getUserAuthorizations(user); final StringBuilder userAuths = new StringBuilder(); final String[] toBeRemovedAuths = scanOpts.split(","); final Set<String> toBeRemovedSet = new HashSet<>(); Collections.addAll(toBeRemovedSet, toBeRemovedAuths); final String[] existingAuths = auths.toString().split(","); for (String auth : existingAuths) { if (!toBeRemovedSet.contains(auth)) { userAuths.append(auth); userAuths.append(","); } } if (userAuths.length() > 0) { accumuloClient.securityOperations().changeUserAuthorizations(user, ScanCommand.parseAuthorizations(userAuths.substring(0, userAuths.length() - 1))); } else { accumuloClient.securityOperations().changeUserAuthorizations(user, new Authorizations()); } Shell.log.debug("Changed record-level authorizations for user {}", user); return 0; }
DeleteAuthsCommand extends Command { @Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException { final AccumuloClient accumuloClient = shellState.getAccumuloClient(); final String user = cl.getOptionValue(userOpt.getOpt(), accumuloClient.whoami()); final String scanOpts = cl.getOptionValue(scanOptAuths.getOpt()); final Authorizations auths = accumuloClient.securityOperations().getUserAuthorizations(user); final StringBuilder userAuths = new StringBuilder(); final String[] toBeRemovedAuths = scanOpts.split(","); final Set<String> toBeRemovedSet = new HashSet<>(); Collections.addAll(toBeRemovedSet, toBeRemovedAuths); final String[] existingAuths = auths.toString().split(","); for (String auth : existingAuths) { if (!toBeRemovedSet.contains(auth)) { userAuths.append(auth); userAuths.append(","); } } if (userAuths.length() > 0) { accumuloClient.securityOperations().changeUserAuthorizations(user, ScanCommand.parseAuthorizations(userAuths.substring(0, userAuths.length() - 1))); } else { accumuloClient.securityOperations().changeUserAuthorizations(user, new Authorizations()); } Shell.log.debug("Changed record-level authorizations for user {}", user); return 0; } }
DeleteAuthsCommand extends Command { @Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException { final AccumuloClient accumuloClient = shellState.getAccumuloClient(); final String user = cl.getOptionValue(userOpt.getOpt(), accumuloClient.whoami()); final String scanOpts = cl.getOptionValue(scanOptAuths.getOpt()); final Authorizations auths = accumuloClient.securityOperations().getUserAuthorizations(user); final StringBuilder userAuths = new StringBuilder(); final String[] toBeRemovedAuths = scanOpts.split(","); final Set<String> toBeRemovedSet = new HashSet<>(); Collections.addAll(toBeRemovedSet, toBeRemovedAuths); final String[] existingAuths = auths.toString().split(","); for (String auth : existingAuths) { if (!toBeRemovedSet.contains(auth)) { userAuths.append(auth); userAuths.append(","); } } if (userAuths.length() > 0) { accumuloClient.securityOperations().changeUserAuthorizations(user, ScanCommand.parseAuthorizations(userAuths.substring(0, userAuths.length() - 1))); } else { accumuloClient.securityOperations().changeUserAuthorizations(user, new Authorizations()); } Shell.log.debug("Changed record-level authorizations for user {}", user); return 0; }  }
DeleteAuthsCommand extends Command { @Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException { final AccumuloClient accumuloClient = shellState.getAccumuloClient(); final String user = cl.getOptionValue(userOpt.getOpt(), accumuloClient.whoami()); final String scanOpts = cl.getOptionValue(scanOptAuths.getOpt()); final Authorizations auths = accumuloClient.securityOperations().getUserAuthorizations(user); final StringBuilder userAuths = new StringBuilder(); final String[] toBeRemovedAuths = scanOpts.split(","); final Set<String> toBeRemovedSet = new HashSet<>(); Collections.addAll(toBeRemovedSet, toBeRemovedAuths); final String[] existingAuths = auths.toString().split(","); for (String auth : existingAuths) { if (!toBeRemovedSet.contains(auth)) { userAuths.append(auth); userAuths.append(","); } } if (userAuths.length() > 0) { accumuloClient.securityOperations().changeUserAuthorizations(user, ScanCommand.parseAuthorizations(userAuths.substring(0, userAuths.length() - 1))); } else { accumuloClient.securityOperations().changeUserAuthorizations(user, new Authorizations()); } Shell.log.debug("Changed record-level authorizations for user {}", user); return 0; }  @Override int execute(final String fullCommand, final CommandLine cl, final Shell shellState); @Override String description(); @Override void registerCompletion(final Token root,
      final Map<Command.CompletionSet,Set<String>> completionSet); @Override Options getOptions(); @Override int numArgs(); }
DeleteAuthsCommand extends Command { @Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException { final AccumuloClient accumuloClient = shellState.getAccumuloClient(); final String user = cl.getOptionValue(userOpt.getOpt(), accumuloClient.whoami()); final String scanOpts = cl.getOptionValue(scanOptAuths.getOpt()); final Authorizations auths = accumuloClient.securityOperations().getUserAuthorizations(user); final StringBuilder userAuths = new StringBuilder(); final String[] toBeRemovedAuths = scanOpts.split(","); final Set<String> toBeRemovedSet = new HashSet<>(); Collections.addAll(toBeRemovedSet, toBeRemovedAuths); final String[] existingAuths = auths.toString().split(","); for (String auth : existingAuths) { if (!toBeRemovedSet.contains(auth)) { userAuths.append(auth); userAuths.append(","); } } if (userAuths.length() > 0) { accumuloClient.securityOperations().changeUserAuthorizations(user, ScanCommand.parseAuthorizations(userAuths.substring(0, userAuths.length() - 1))); } else { accumuloClient.securityOperations().changeUserAuthorizations(user, new Authorizations()); } Shell.log.debug("Changed record-level authorizations for user {}", user); return 0; }  @Override int execute(final String fullCommand, final CommandLine cl, final Shell shellState); @Override String description(); @Override void registerCompletion(final Token root,
      final Map<Command.CompletionSet,Set<String>> completionSet); @Override Options getOptions(); @Override int numArgs();  }