You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by el...@apache.org on 2015/05/08 18:32:10 UTC

[2/6] accumulo git commit: ACCUMULO-3784 fix getauths

ACCUMULO-3784 fix getauths

Signed-off-by: Josh Elser <el...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/fa22fa43
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/fa22fa43
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/fa22fa43

Branch: refs/heads/1.7
Commit: fa22fa431d1de7b7f636f8011ced1b4d45bab7cd
Parents: 2b168f8
Author: Max Jordan <mj...@bbn.com>
Authored: Fri May 8 11:30:42 2015 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Fri May 8 11:30:42 2015 -0400

----------------------------------------------------------------------
 .../util/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/fa22fa43/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetAuthsCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetAuthsCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetAuthsCommand.java
index 74aefaa..8c1e88b 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetAuthsCommand.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetAuthsCommand.java
@@ -17,8 +17,9 @@
 package org.apache.accumulo.core.util.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;
@@ -38,14 +39,20 @@ public class GetAuthsCommand extends Command {
     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";

http://git-wip-us.apache.org/repos/asf/accumulo/blob/fa22fa43/core/src/test/java/org/apache/accumulo/core/util/shell/commands/GetAuthsCommandTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/util/shell/commands/GetAuthsCommandTest.java b/core/src/test/java/org/apache/accumulo/core/util/shell/commands/GetAuthsCommandTest.java
new file mode 100644
index 0000000..b0f0672
--- /dev/null
+++ b/core/src/test/java/org/apache/accumulo/core/util/shell/commands/GetAuthsCommandTest.java
@@ -0,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.core.util.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");
+  }
+}