Merge branch '1.6' into 1.7
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/31dd5ca0 Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/31dd5ca0 Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/31dd5ca0 Branch: refs/heads/1.7 Commit: 31dd5ca05663463d4a4a455accab9ced9ebaa63c Parents: 61eea42 fa22fa4 Author: Josh Elser <els...@apache.org> Authored: Fri May 8 11:55:14 2015 -0400 Committer: Josh Elser <els...@apache.org> Committed: Fri May 8 12:31:44 2015 -0400 ---------------------------------------------------------------------- .../shell/commands/GetAuthsCommand.java | 19 ++++++--- .../shell/commands/GetAuthsCommandTest.java | 44 ++++++++++++++++++++ 2 files changed, 57 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/31dd5ca0/shell/src/main/java/org/apache/accumulo/shell/commands/GetAuthsCommand.java ---------------------------------------------------------------------- diff --cc shell/src/main/java/org/apache/accumulo/shell/commands/GetAuthsCommand.java index c4c1b67,0000000..5c6a4eb mode 100644,000000..100644 --- a/shell/src/main/java/org/apache/accumulo/shell/commands/GetAuthsCommand.java +++ b/shell/src/main/java/org/apache/accumulo/shell/commands/GetAuthsCommand.java @@@ -1,68 -1,0 +1,75 @@@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.accumulo.shell.commands; + +import java.io.IOException; - import java.util.SortedSet; - import java.util.TreeSet; ++import java.util.ArrayList; ++import java.util.Collections; ++import java.util.List; + +import org.apache.accumulo.core.client.AccumuloException; +import org.apache.accumulo.core.client.AccumuloSecurityException; +import org.apache.accumulo.core.security.Authorizations; +import org.apache.accumulo.shell.Shell; +import org.apache.accumulo.shell.Shell.Command; +import org.apache.accumulo.shell.ShellOptions; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.commons.lang.StringUtils; + +public class GetAuthsCommand extends Command { + private Option userOpt; + + @Override + public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, IOException { + final String user = cl.getOptionValue(userOpt.getOpt(), shellState.getConnector().whoami()); + // Sort authorizations + Authorizations auths = shellState.getConnector().securityOperations().getUserAuthorizations(user); - SortedSet<String> set = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); - for (byte[] auth : auths) { - set.add(new String(auth)); - } ++ List<String> set = sortAuthorizations(auths); + shellState.getReader().println(StringUtils.join(set, ',')); + return 0; + } + ++ protected List<String> sortAuthorizations(Authorizations auths) { ++ List<String> list = new ArrayList<String>(); ++ for (byte[] auth : auths) { ++ list.add(new String(auth)); ++ } ++ Collections.sort(list, String.CASE_INSENSITIVE_ORDER); ++ return list; ++ } ++ + @Override + public String description() { + return "displays the maximum scan authorizations for a user"; + } + + @Override + public Options getOptions() { + final Options o = new Options(); + userOpt = new Option(ShellOptions.userOption, "user", true, "user to operate on"); + userOpt.setArgName("user"); + o.addOption(userOpt); + return o; + } + + @Override + public int numArgs() { + return 0; + } +} http://git-wip-us.apache.org/repos/asf/accumulo/blob/31dd5ca0/shell/src/test/java/org/apache/accumulo/shell/commands/GetAuthsCommandTest.java ---------------------------------------------------------------------- diff --cc shell/src/test/java/org/apache/accumulo/shell/commands/GetAuthsCommandTest.java index 0000000,0000000..ab57252 new file mode 100644 --- /dev/null +++ b/shell/src/test/java/org/apache/accumulo/shell/commands/GetAuthsCommandTest.java @@@ -1,0 -1,0 +1,44 @@@ ++/* ++ * Licensed to the Apache Software Foundation (ASF) under one or more ++ * contributor license agreements. See the NOTICE file distributed with ++ * this work for additional information regarding copyright ownership. ++ * The ASF licenses this file to You under the Apache License, Version 2.0 ++ * (the "License"); you may not use this file except in compliance with ++ * the License. You may obtain a copy of the License at ++ * ++ * http://www.apache.org/licenses/LICENSE-2.0 ++ * ++ * Unless required by applicable law or agreed to in writing, software ++ * distributed under the License is distributed on an "AS IS" BASIS, ++ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++ * See the License for the specific language governing permissions and ++ * limitations under the License. ++ */ ++ ++package org.apache.accumulo.shell.commands; ++ ++import static org.junit.Assert.assertEquals; ++import static org.junit.Assert.assertNotNull; ++ ++import java.util.List; ++ ++import org.apache.accumulo.core.security.Authorizations; ++import org.junit.Test; ++ ++public class GetAuthsCommandTest { ++ ++ @Test ++ public void removeAccumuloNamespaceTables() { ++ Authorizations auths = new Authorizations("AAA", "aaa", "bbb", "BBB"); ++ GetAuthsCommand cmd = new GetAuthsCommand(); ++ List<String> sorted = cmd.sortAuthorizations(auths); ++ ++ assertNotNull(sorted); ++ assertEquals(sorted.size(), 4); ++ ++ assertEquals(sorted.get(0), "AAA"); ++ assertEquals(sorted.get(1), "aaa"); ++ assertEquals(sorted.get(2), "BBB"); ++ assertEquals(sorted.get(3), "bbb"); ++ } ++}