You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2013/12/05 00:58:06 UTC

[14/50] [abbrv] git commit: ACCUMULO-1479 added table namespaces permission check to RandomWalk

ACCUMULO-1479 added table namespaces permission check to RandomWalk


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

Branch: refs/heads/1.6.0-SNAPSHOT
Commit: 5f4b864b072dc82ba17294d49f3b0a364c79b8fd
Parents: 14fb257
Author: Sean Hickey <ta...@gmail.com>
Authored: Tue Aug 6 10:45:20 2013 -0400
Committer: Christopher Tubbs <ct...@apache.org>
Committed: Wed Dec 4 18:46:10 2013 -0500

----------------------------------------------------------------------
 .../concurrent/ChangePermissions.java           | 37 ++++++++++++++++++--
 .../randomwalk/concurrent/CheckPermission.java  | 13 +++++--
 2 files changed, 46 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/5f4b864b/test/src/main/java/org/apache/accumulo/test/randomwalk/concurrent/ChangePermissions.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/randomwalk/concurrent/ChangePermissions.java b/test/src/main/java/org/apache/accumulo/test/randomwalk/concurrent/ChangePermissions.java
index be2de2a..a63391c 100644
--- a/test/src/main/java/org/apache/accumulo/test/randomwalk/concurrent/ChangePermissions.java
+++ b/test/src/main/java/org/apache/accumulo/test/randomwalk/concurrent/ChangePermissions.java
@@ -26,6 +26,7 @@ import org.apache.accumulo.core.client.AccumuloException;
 import org.apache.accumulo.core.client.AccumuloSecurityException;
 import org.apache.accumulo.core.client.Connector;
 import org.apache.accumulo.core.security.SystemPermission;
+import org.apache.accumulo.core.security.TableNamespacePermission;
 import org.apache.accumulo.core.security.TablePermission;
 import org.apache.accumulo.test.randomwalk.State;
 import org.apache.accumulo.test.randomwalk.Test;
@@ -46,11 +47,18 @@ public class ChangePermissions extends Test {
     List<String> tableNames = (List<String>) state.get("tables");
     String tableName = tableNames.get(rand.nextInt(tableNames.size()));
     
+    @SuppressWarnings("unchecked")
+    List<String> tableNamespaces = (List<String>) state.get("namespaces");
+    String tableNamespace = tableNamespaces.get(rand.nextInt(tableNamespaces.size()));
+    
     try {
-      if (rand.nextBoolean())
+      int dice = rand.nextInt(2);
+      if (dice == 0)
         changeSystemPermission(conn, rand, userName);
-      else
+      else if (dice == 1)
         changeTablePermission(conn, rand, userName, tableName);
+      else if (dice == 2)
+        changeTableNamespacePermission(conn, rand, userName, tableNamespace);
     } catch (AccumuloSecurityException ex) {
       log.debug("Unable to change user permissions: " + ex.getCause());
     }
@@ -108,4 +116,29 @@ public class ChangePermissions extends Test {
     }
   }
   
+  private void changeTableNamespacePermission(Connector conn, Random rand, String userName, String tableNamespace) throws AccumuloException, AccumuloSecurityException {
+    
+    EnumSet<TableNamespacePermission> perms = EnumSet.noneOf(TableNamespacePermission.class);
+    for (TableNamespacePermission p : TableNamespacePermission.values()) {
+      if (conn.securityOperations().hasTableNamespacePermission(userName, tableNamespace, p))
+        perms.add(p);
+    }
+    
+    EnumSet<TableNamespacePermission> more = EnumSet.allOf(TableNamespacePermission.class);
+    more.removeAll(perms);
+    
+    if (rand.nextBoolean() && more.size() > 0) {
+      List<TableNamespacePermission> moreList = new ArrayList<TableNamespacePermission>(more);
+      TableNamespacePermission choice = moreList.get(rand.nextInt(moreList.size()));
+      log.debug("adding permission " + choice);
+      conn.securityOperations().grantTableNamespacePermission(userName, tableNamespace, choice);
+    } else {
+      if (perms.size() > 0) {
+        List<TableNamespacePermission> permList = new ArrayList<TableNamespacePermission>(perms);
+        TableNamespacePermission choice = permList.get(rand.nextInt(permList.size()));
+        log.debug("removing permission " + choice);
+        conn.securityOperations().revokeTableNamespacePermission(userName, tableNamespace, choice);
+      }
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/5f4b864b/test/src/main/java/org/apache/accumulo/test/randomwalk/concurrent/CheckPermission.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/randomwalk/concurrent/CheckPermission.java b/test/src/main/java/org/apache/accumulo/test/randomwalk/concurrent/CheckPermission.java
index 5fa9bc4..544ce96 100644
--- a/test/src/main/java/org/apache/accumulo/test/randomwalk/concurrent/CheckPermission.java
+++ b/test/src/main/java/org/apache/accumulo/test/randomwalk/concurrent/CheckPermission.java
@@ -24,6 +24,7 @@ import org.apache.accumulo.core.client.AccumuloSecurityException;
 import org.apache.accumulo.core.client.Connector;
 import org.apache.accumulo.core.security.SystemPermission;
 import org.apache.accumulo.core.security.TablePermission;
+import org.apache.accumulo.core.security.TableNamespacePermission;
 import org.apache.accumulo.test.randomwalk.State;
 import org.apache.accumulo.test.randomwalk.Test;
 
@@ -43,13 +44,21 @@ public class CheckPermission extends Test {
     List<String> tableNames = (List<String>) state.get("tables");
     String tableName = tableNames.get(rand.nextInt(tableNames.size()));
     
+    @SuppressWarnings("unchecked")
+    List<String> tableNamespaces = (List<String>) state.get("namespaces");
+    String tableNamespace = tableNamespaces.get(rand.nextInt(tableNamespaces.size()));
+    
     try {
-      if (rand.nextBoolean()) {
+      int dice = rand.nextInt(2);
+      if (dice == 0) {
         log.debug("Checking systerm permission " + userName);
         conn.securityOperations().hasSystemPermission(userName, SystemPermission.values()[rand.nextInt(SystemPermission.values().length)]);
-      } else {
+      } else if (dice == 1) {
         log.debug("Checking table permission " + userName + " " + tableName);
         conn.securityOperations().hasTablePermission(userName, tableName, TablePermission.values()[rand.nextInt(TablePermission.values().length)]);
+      } else if (dice == 2) {
+        log.debug("Checking table namespace permission " + userName + " " + tableNamespace);
+        conn.securityOperations().hasTableNamespacePermission(userName, tableNamespace, TableNamespacePermission.values()[rand.nextInt(TableNamespacePermission.values().length)]);
       }
       
     } catch (AccumuloSecurityException ex) {