accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [41/54] git commit: ACCUMULO-1479 added table namespaces permission check to RandomWalk
Date Fri, 01 Nov 2013 02:00:42 GMT
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/828e6ada
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/828e6ada
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/828e6ada

Branch: refs/heads/ACCUMULO-802
Commit: 828e6adad368e71c6272a310589704929acf80d8
Parents: b83c6eb
Author: Sean Hickey <tallirishllama@gmail.com>
Authored: Tue Aug 6 10:45:20 2013 -0400
Committer: Christopher Tubbs <ctubbsii@apache.org>
Committed: Thu Oct 31 21:36:25 2013 -0400

----------------------------------------------------------------------
 .../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/828e6ada/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/828e6ada/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) {


Mime
View raw message