Index: hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseRegionObserver.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseRegionObserver.java (revision 1349120) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseRegionObserver.java (working copy) @@ -74,17 +74,21 @@ boolean abortRequested) { } @Override - public void preFlush(ObserverContext e) { } + public void preFlush(ObserverContext e) throws IOException { + } @Override - public void postFlush(ObserverContext e) { } + public void postFlush(ObserverContext e) throws IOException { + } @Override - public void preSplit(ObserverContext e) { } + public void preSplit(ObserverContext e) throws IOException { + } @Override - public void postSplit(ObserverContext e, - HRegion l, HRegion r) { } + public void postSplit(ObserverContext e, HRegion l, HRegion r) + throws IOException { + } @Override public void preCompactSelection(final ObserverContext c, @@ -96,13 +100,14 @@ @Override public InternalScanner preCompact(ObserverContext e, - final Store store, final InternalScanner scanner) { + final Store store, final InternalScanner scanner) throws IOException { return scanner; } @Override - public void postCompact(ObserverContext e, - final Store store, final StoreFile resultFile) { } + public void postCompact(ObserverContext e, final Store store, + final StoreFile resultFile) throws IOException { + } @Override public void preGetClosestRowBefore(final ObserverContext e, Index: hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionObserver.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionObserver.java (revision 1349120) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionObserver.java (working copy) @@ -66,14 +66,16 @@ /** * Called before the memstore is flushed to disk. * @param c the environment provided by the region server + * @throws IOException if an error occurred on the coprocessor */ - void preFlush(final ObserverContext c); + void preFlush(final ObserverContext c) throws IOException; /** * Called after the memstore is flushed to disk. * @param c the environment provided by the region server + * @throws IOException if an error occurred on the coprocessor */ - void postFlush(final ObserverContext c); + void postFlush(final ObserverContext c) throws IOException; /** * Called prior to selecting the {@link StoreFile}s to compact from the list @@ -118,9 +120,10 @@ * rewriting * @return the scanner to use during compaction. Should not be {@code null} * unless the implementation is writing new store files on its own. + * @throws IOException if an error occurred on the coprocessor */ InternalScanner preCompact(final ObserverContext c, - final Store store, final InternalScanner scanner); + final Store store, final InternalScanner scanner) throws IOException; /** * Called after compaction has completed and the new store file has been @@ -128,16 +131,18 @@ * @param c the environment provided by the region server * @param store the store being compacted * @param resultFile the new store file written out during compaction + * @throws IOException if an error occurred on the coprocessor */ - void postCompact(final ObserverContext c, - final Store store, StoreFile resultFile); + void postCompact(final ObserverContext c, final Store store, + StoreFile resultFile) throws IOException; /** * Called before the region is split. * @param c the environment provided by the region server * (e.getRegion() returns the parent region) + * @throws IOException if an error occurred on the coprocessor */ - void preSplit(final ObserverContext c); + void preSplit(final ObserverContext c) throws IOException; /** * Called after the region is split. @@ -145,9 +150,10 @@ * (e.getRegion() returns the parent region) * @param l the left daughter region * @param r the right daughter region + * @throws IOException if an error occurred on the coprocessor */ void postSplit(final ObserverContext c, final HRegion l, - final HRegion r); + final HRegion r) throws IOException; /** * Called before the region is reported as closed to the master. Index: hbase-server/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java (revision 1349120) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java (working copy) @@ -1195,11 +1195,13 @@ .setScope(HConstants.REPLICATION_SCOPE_LOCAL) }); + @Deprecated public void setOwner(User owner) { setOwnerString(owner != null ? owner.getShortName() : null); } // used by admin.rb:alter(table_name,*args) to update owner. + @Deprecated public void setOwnerString(String ownerString) { if (ownerString != null) { setValue(OWNER_KEY, Bytes.toBytes(ownerString)); @@ -1208,12 +1210,14 @@ } } + @Deprecated public String getOwnerString() { if (getValue(OWNER_KEY) != null) { return Bytes.toString(getValue(OWNER_KEY)); } // Note that every table should have an owner (i.e. should have OWNER_KEY set). - // .META. and -ROOT- should return system user as owner, not null (see MasterFileSystem.java:bootstrap()). + // .META. and -ROOT- should return system user as owner, not null (see + // MasterFileSystem.java:bootstrap()). return null; } Index: hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java (revision 1349120) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java (working copy) @@ -355,8 +355,9 @@ * Called prior to rewriting the store files selected for compaction * @param store the store being compacted * @param scanner the scanner used to read store data during compaction + * @throws IOException */ - public InternalScanner preCompact(Store store, InternalScanner scanner) { + public InternalScanner preCompact(Store store, InternalScanner scanner) throws IOException { ObserverContext ctx = null; boolean bypass = false; for (RegionEnvironment env: coprocessors) { @@ -366,7 +367,7 @@ scanner = ((RegionObserver)env.getInstance()).preCompact( ctx, store, scanner); } catch (Throwable e) { - handleCoprocessorThrowableNoRethrow(env,e); + handleCoprocessorThrowable(env,e); } bypass |= ctx.shouldBypass(); if (ctx.shouldComplete()) { @@ -381,8 +382,9 @@ * Called after the store compaction has completed. * @param store the store being compacted * @param resultFile the new store file written during compaction + * @throws IOException */ - public void postCompact(Store store, StoreFile resultFile) { + public void postCompact(Store store, StoreFile resultFile) throws IOException { ObserverContext ctx = null; for (RegionEnvironment env: coprocessors) { if (env.getInstance() instanceof RegionObserver) { @@ -390,7 +392,7 @@ try { ((RegionObserver)env.getInstance()).postCompact(ctx, store, resultFile); } catch (Throwable e) { - handleCoprocessorThrowableNoRethrow(env, e); + handleCoprocessorThrowable(env, e); } if (ctx.shouldComplete()) { break; @@ -401,8 +403,9 @@ /** * Invoked before a memstore flush + * @throws IOException */ - public void preFlush() { + public void preFlush() throws IOException { ObserverContext ctx = null; for (RegionEnvironment env: coprocessors) { if (env.getInstance() instanceof RegionObserver) { @@ -410,7 +413,7 @@ try { ((RegionObserver)env.getInstance()).preFlush(ctx); } catch (Throwable e) { - handleCoprocessorThrowableNoRethrow(env, e); + handleCoprocessorThrowable(env, e); } if (ctx.shouldComplete()) { break; @@ -421,8 +424,9 @@ /** * Invoked after a memstore flush + * @throws IOException */ - public void postFlush() { + public void postFlush() throws IOException { ObserverContext ctx = null; for (RegionEnvironment env: coprocessors) { if (env.getInstance() instanceof RegionObserver) { @@ -430,7 +434,7 @@ try { ((RegionObserver)env.getInstance()).postFlush(ctx); } catch (Throwable e) { - handleCoprocessorThrowableNoRethrow(env, e); + handleCoprocessorThrowable(env, e); } if (ctx.shouldComplete()) { break; @@ -441,8 +445,9 @@ /** * Invoked just before a split + * @throws IOException */ - public void preSplit() { + public void preSplit() throws IOException { ObserverContext ctx = null; for (RegionEnvironment env: coprocessors) { if (env.getInstance() instanceof RegionObserver) { @@ -450,7 +455,7 @@ try { ((RegionObserver)env.getInstance()).preSplit(ctx); } catch (Throwable e) { - handleCoprocessorThrowableNoRethrow(env, e); + handleCoprocessorThrowable(env, e); } if (ctx.shouldComplete()) { break; @@ -463,8 +468,9 @@ * Invoked just after a split * @param l the new left-hand daughter region * @param r the new right-hand daughter region + * @throws IOException */ - public void postSplit(HRegion l, HRegion r) { + public void postSplit(HRegion l, HRegion r) throws IOException { ObserverContext ctx = null; for (RegionEnvironment env: coprocessors) { if (env.getInstance() instanceof RegionObserver) { @@ -472,7 +478,7 @@ try { ((RegionObserver)env.getInstance()).postSplit(ctx, l, r); } catch (Throwable e) { - handleCoprocessorThrowableNoRethrow(env, e); + handleCoprocessorThrowable(env, e); } if (ctx.shouldComplete()) { break; Index: hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java (revision 1349120) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java (working copy) @@ -15,7 +15,6 @@ package org.apache.hadoop.hbase.security.access; import java.io.*; -import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; @@ -54,9 +53,11 @@ import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.InternalScanner; import org.apache.hadoop.hbase.regionserver.RegionScanner; +import org.apache.hadoop.hbase.regionserver.Store; import org.apache.hadoop.hbase.regionserver.wal.WALEdit; import org.apache.hadoop.hbase.security.AccessDeniedException; import org.apache.hadoop.hbase.security.User; +import org.apache.hadoop.hbase.security.access.Permission.Action; import org.apache.hadoop.hbase.util.Bytes; import com.google.common.collect.ListMultimap; @@ -248,7 +249,6 @@ RegionCoprocessorEnvironment e, Map> families) { HRegionInfo hri = e.getRegion().getRegionInfo(); - HTableDescriptor htd = e.getRegion().getTableDesc(); byte[] tableName = hri.getTableName(); // 1. All users need read access to .META. and -ROOT- tables. @@ -277,19 +277,12 @@ return AuthResult.allow("Table permission granted", user, permRequest, tableName); } - // 2. The table owner has full privileges - String owner = htd.getOwnerString(); - if (user.getShortName().equals(owner)) { - // owner of the table has full access - return AuthResult.allow("User is table owner", user, permRequest, tableName); - } - - // 3. check for the table-level, if successful we can short-circuit + // 2. check for the table-level, if successful we can short-circuit if (authManager.authorize(user, tableName, (byte[])null, permRequest)) { return AuthResult.allow("Table permission granted", user, permRequest, tableName); } - // 4. check permissions against the requested families + // 3. check permissions against the requested families if (families != null && families.size() > 0) { // all families must pass for (Map.Entry> family : families.entrySet()) { @@ -333,7 +326,7 @@ tableName); } - // 5. no families to check and table level access failed + // 4. no families to check and table level access failed return AuthResult.deny("No families to check and table permission failed", user, permRequest, tableName); } @@ -363,38 +356,24 @@ } /** - * Authorizes that the current user has "admin" privileges for the given table. - * that means he/she can edit/modify/delete the table. - * If current user is the table owner, and has CREATE permission, - * then he/she has table admin permission. otherwise ADMIN rights are checked. - * @param e Master coprocessor environment + * Authorizes that the current user has any of the given permissions for the given table. * @param tableName Table requested * @throws IOException if obtaining the current user fails - * @throws AccessDeniedException if authorization is denied + * @throws AccessDeniedException if user has no authorization */ - private void requireTableAdminPermission(MasterCoprocessorEnvironment e, byte[] tableName) + private void requireAnyTablePermission(byte[] tableName, Action... permissions) throws IOException { User user = getActiveUser(); AuthResult result = null; - // Table admins are allowed to perform DDL - if (authManager.authorize(user, tableName, (byte[]) null, TablePermission.Action.ADMIN)) { - result = AuthResult.allow("Table permission granted", user, TablePermission.Action.ADMIN, - tableName); - } else if (isActiveUserTableOwner(e, tableName)) { - // Table owners with Create permission are allowed to perform DDL - if (authManager.authorize(user, tableName, (byte[]) null, TablePermission.Action.CREATE)) { - result = AuthResult.allow("Owner has table permission", user, - TablePermission.Action.CREATE, tableName); + for (Action permission : permissions) { + if (authManager.authorize(user, tableName, (byte[]) null, permission)) { + result = AuthResult.allow("Table permission granted", user, permission, tableName); + break; } else { - // Table owners without Create permission cannot perform DDL - result = AuthResult.deny("Insufficient permissions", user, TablePermission.Action.CREATE, - tableName); + // rest of the world + result = AuthResult.deny("Insufficient permissions", user, permission, tableName); } - } else { - // rest of the world - result = AuthResult.deny("Insufficient permissions", user, TablePermission.Action.ADMIN, - tableName); } logResult(result); if (!result.isAllowed()) { @@ -538,14 +517,8 @@ public void preCreateTable(ObserverContext c, HTableDescriptor desc, HRegionInfo[] regions) throws IOException { requirePermission(Permission.Action.CREATE); - - // default the table owner if not specified - User owner = getActiveUser(); - if (desc.getOwnerString() == null || - desc.getOwnerString().equals("")) { - desc.setOwner(owner); - } } + @Override public void preCreateTableHandler(ObserverContext c, HTableDescriptor desc, HRegionInfo[] regions) throws IOException {} @@ -560,7 +533,7 @@ @Override public void preDeleteTable(ObserverContext c, byte[] tableName) throws IOException { - requireTableAdminPermission(c.getEnvironment(), tableName); + requireAnyTablePermission(tableName, Action.ADMIN, Action.CREATE); } @Override public void preDeleteTableHandler(ObserverContext c, @@ -577,7 +550,7 @@ @Override public void preModifyTable(ObserverContext c, byte[] tableName, HTableDescriptor htd) throws IOException { - requireTableAdminPermission(c.getEnvironment(), tableName); + requireAnyTablePermission(tableName, Action.ADMIN, Action.CREATE); } @Override public void preModifyTableHandler(ObserverContext c, @@ -593,7 +566,7 @@ @Override public void preAddColumn(ObserverContext c, byte[] tableName, HColumnDescriptor column) throws IOException { - requireTableAdminPermission(c.getEnvironment(), tableName); + requireAnyTablePermission(tableName, Action.ADMIN, Action.CREATE); } @Override public void preAddColumnHandler(ObserverContext c, @@ -608,7 +581,7 @@ @Override public void preModifyColumn(ObserverContext c, byte[] tableName, HColumnDescriptor descriptor) throws IOException { - requireTableAdminPermission(c.getEnvironment(), tableName); + requireAnyTablePermission(tableName, Action.ADMIN, Action.CREATE); } @Override public void preModifyColumnHandler(ObserverContext c, @@ -624,7 +597,7 @@ @Override public void preDeleteColumn(ObserverContext c, byte[] tableName, byte[] col) throws IOException { - requireTableAdminPermission(c.getEnvironment(), tableName); + requireAnyTablePermission(tableName, Action.ADMIN, Action.CREATE); } @Override public void preDeleteColumnHandler(ObserverContext c, @@ -642,7 +615,7 @@ @Override public void preEnableTable(ObserverContext c, byte[] tableName) throws IOException { - requireTableAdminPermission(c.getEnvironment(), tableName); + requireAnyTablePermission(tableName, Action.ADMIN, Action.CREATE); } @Override public void preEnableTableHandler(ObserverContext c, @@ -657,7 +630,7 @@ @Override public void preDisableTable(ObserverContext c, byte[] tableName) throws IOException { - requireTableAdminPermission(c.getEnvironment(), tableName); + requireAnyTablePermission(tableName, Action.ADMIN, Action.CREATE); } @Override public void preDisableTableHandler(ObserverContext c, @@ -770,6 +743,23 @@ } @Override + public void preFlush(ObserverContext e) throws IOException { + requireAnyTablePermission(getTableName(e.getEnvironment()), Action.ADMIN); + } + + @Override + public void preSplit(ObserverContext e) throws IOException { + requireAnyTablePermission(getTableName(e.getEnvironment()), Action.ADMIN); + } + + @Override + public InternalScanner preCompact(ObserverContext e, + final Store store, final InternalScanner scanner) throws IOException { + requireAnyTablePermission(getTableName(e.getEnvironment()), Action.ADMIN); + return scanner; + } + + @Override public void preGetClosestRowBefore(final ObserverContext c, final byte [] row, final byte [] family, final Result result) throws IOException { @@ -1136,16 +1126,4 @@ } return tableName; } - - private String getTableOwner(MasterCoprocessorEnvironment e, - byte[] tableName) throws IOException { - HTableDescriptor htd = e.getTable(tableName).getTableDescriptor(); - return htd.getOwnerString(); - } - - private boolean isActiveUserTableOwner(MasterCoprocessorEnvironment e, - byte[] tableName) throws IOException { - String activeUser = getActiveUser().getShortName(); - return activeUser.equals(getTableOwner(e, tableName)); - } } Index: hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController.java =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController.java (revision 1349120) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController.java (working copy) @@ -27,8 +27,6 @@ import java.util.List; import java.util.Map; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Coprocessor; import org.apache.hadoop.hbase.HBaseTestingUtility; @@ -51,7 +49,10 @@ import org.apache.hadoop.hbase.coprocessor.CoprocessorException; import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment; import org.apache.hadoop.hbase.coprocessor.ObserverContext; +import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; import org.apache.hadoop.hbase.master.MasterCoprocessorHost; +import org.apache.hadoop.hbase.regionserver.HRegion; +import org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost; import org.apache.hadoop.hbase.security.AccessDeniedException; import org.apache.hadoop.hbase.security.User; import org.apache.hadoop.hbase.util.Bytes; @@ -65,8 +66,8 @@ * levels of authorized users. */ @Category(LargeTests.class) +@SuppressWarnings("rawtypes") public class TestAccessController { - private static Log LOG = LogFactory.getLog(TestAccessController.class); private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private static Configuration conf; @@ -74,14 +75,14 @@ private static User SUPERUSER; // user granted with all global permission private static User USER_ADMIN; - // table owner user - private static User USER_OWNER; // user with rw permissions private static User USER_RW; // user with read-only permissions private static User USER_RO; // user with table admin permissions private static User USER_TBLADM; + // user with all table permissions - equivalent to creator of the table + private static User USER_TBLALL; // user with no permissions private static User USER_NONE; @@ -89,6 +90,7 @@ private static byte[] TEST_FAMILY = Bytes.toBytes("f1"); private static MasterCoprocessorEnvironment CP_ENV; + private static RegionCoprocessorEnvironment RCP_ENV; private static AccessController ACCESS_CONTROLLER; @BeforeClass @@ -109,16 +111,15 @@ // create a set of test users SUPERUSER = User.createUserForTesting(conf, "admin", new String[]{"supergroup"}); USER_ADMIN = User.createUserForTesting(conf, "admin2", new String[0]); - USER_OWNER = User.createUserForTesting(conf, "owner", new String[0]); USER_RW = User.createUserForTesting(conf, "rwuser", new String[0]); USER_RO = User.createUserForTesting(conf, "rouser", new String[0]); USER_TBLADM = User.createUserForTesting(conf, "tbladm", new String[0]); + USER_TBLALL = User.createUserForTesting(conf, "tblall", new String[0]); USER_NONE = User.createUserForTesting(conf, "nouser", new String[0]); HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); HTableDescriptor htd = new HTableDescriptor(TEST_TABLE); htd.addFamily(new HColumnDescriptor(TEST_FAMILY)); - htd.setOwnerString(USER_OWNER.getShortName()); admin.createTable(htd); // initilize access control @@ -126,6 +127,11 @@ AccessControllerProtocol protocol = meta.coprocessorProxy(AccessControllerProtocol.class, TEST_TABLE); + HRegion region = TEST_UTIL.getHBaseCluster().getRegions(TEST_TABLE).get(0); + RegionCoprocessorHost rcpHost = region.getCoprocessorHost(); + RCP_ENV = rcpHost.createEnvironment(AccessController.class, ACCESS_CONTROLLER, + Coprocessor.PRIORITY_HIGHEST, 1, conf); + protocol.grant(new UserPermission(Bytes.toBytes(USER_ADMIN.getShortName()), Permission.Action.ADMIN, Permission.Action.CREATE, Permission.Action.READ, Permission.Action.WRITE)); @@ -137,7 +143,10 @@ TEST_TABLE, TEST_FAMILY, Permission.Action.READ)); protocol.grant(new UserPermission(Bytes.toBytes(USER_TBLADM.getShortName()), - TEST_TABLE, null, Permission.Action.ADMIN)); + TEST_TABLE, null, Permission.Action.CREATE)); + + protocol.grant(new UserPermission(Bytes.toBytes(USER_TBLALL.getShortName()), TEST_TABLE, null, + Permission.Action.values())); } @AfterClass @@ -209,14 +218,10 @@ }; // verify that superuser can create tables - verifyAllowed(SUPERUSER, createTable); - verifyAllowed(USER_ADMIN, createTable); + verifyAllowed(createTable, SUPERUSER, USER_ADMIN); // all others should be denied - verifyDenied(USER_OWNER, createTable); - verifyDenied(USER_RW, createTable); - verifyDenied(USER_RO, createTable); - verifyDenied(USER_NONE, createTable); + verifyDenied(createTable, USER_TBLALL, USER_RW, USER_RO, USER_NONE); } @Test @@ -231,16 +236,8 @@ } }; - // all others should be denied - verifyDenied(USER_OWNER, modifyTable); - verifyDenied(USER_RW, modifyTable); - verifyDenied(USER_RO, modifyTable); - verifyDenied(USER_NONE, modifyTable); - - // verify that superuser can create tables - verifyAllowed(SUPERUSER, modifyTable); - verifyAllowed(USER_ADMIN, modifyTable); - verifyAllowed(USER_TBLADM, modifyTable); + verifyAllowed(modifyTable, SUPERUSER, USER_ADMIN, USER_TBLALL, USER_TBLADM); + verifyDenied(modifyTable, USER_RW, USER_RO, USER_NONE); } @Test @@ -252,16 +249,8 @@ } }; - // all others should be denied - verifyDenied(USER_OWNER, deleteTable); - verifyDenied(USER_RW, deleteTable); - verifyDenied(USER_RO, deleteTable); - verifyDenied(USER_NONE, deleteTable); - - // verify that superuser can create tables - verifyAllowed(SUPERUSER, deleteTable); - verifyAllowed(USER_ADMIN, deleteTable); - verifyAllowed(USER_TBLADM, deleteTable); + verifyAllowed(deleteTable, SUPERUSER, USER_ADMIN, USER_TBLALL, USER_TBLADM); + verifyDenied(deleteTable, USER_RW, USER_RO, USER_NONE); } @Test @@ -274,16 +263,8 @@ } }; - // all others should be denied - verifyDenied(USER_OWNER, action); - verifyDenied(USER_RW, action); - verifyDenied(USER_RO, action); - verifyDenied(USER_NONE, action); - - // verify that superuser can create tables - verifyAllowed(SUPERUSER, action); - verifyAllowed(USER_ADMIN, action); - verifyAllowed(USER_TBLADM, action); + verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_TBLALL, USER_TBLADM); + verifyDenied(action, USER_RW, USER_RO, USER_NONE); } @Test @@ -297,16 +278,8 @@ } }; - // all others should be denied - verifyDenied(USER_OWNER, action); - verifyDenied(USER_RW, action); - verifyDenied(USER_RO, action); - verifyDenied(USER_NONE, action); - - // verify that superuser can create tables - verifyAllowed(SUPERUSER, action); - verifyAllowed(USER_ADMIN, action); - verifyAllowed(USER_TBLADM, action); + verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_TBLALL, USER_TBLADM); + verifyDenied(action, USER_RW, USER_RO, USER_NONE); } @Test @@ -318,16 +291,8 @@ } }; - // all others should be denied - verifyDenied(USER_OWNER, action); - verifyDenied(USER_RW, action); - verifyDenied(USER_RO, action); - verifyDenied(USER_NONE, action); - - // verify that superuser can create tables - verifyAllowed(SUPERUSER, action); - verifyAllowed(USER_ADMIN, action); - verifyAllowed(USER_TBLADM, action); + verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_TBLALL, USER_TBLADM); + verifyDenied(action, USER_RW, USER_RO, USER_NONE); } @Test @@ -339,16 +304,8 @@ } }; - // all others should be denied - verifyDenied(USER_OWNER, disableTable); - verifyDenied(USER_RW, disableTable); - verifyDenied(USER_RO, disableTable); - verifyDenied(USER_NONE, disableTable); - - // verify that superuser can create tables - verifyAllowed(SUPERUSER, disableTable); - verifyAllowed(USER_ADMIN, disableTable); - verifyAllowed(USER_TBLADM, disableTable); + verifyAllowed(disableTable, SUPERUSER, USER_ADMIN, USER_TBLALL, USER_TBLADM); + verifyDenied(disableTable, USER_RW, USER_RO, USER_NONE); } @Test @@ -360,16 +317,8 @@ } }; - // all others should be denied - verifyDenied(USER_OWNER, enableTable); - verifyDenied(USER_RW, enableTable); - verifyDenied(USER_RO, enableTable); - verifyDenied(USER_NONE, enableTable); - - // verify that superuser can create tables - verifyAllowed(SUPERUSER, enableTable); - verifyAllowed(USER_ADMIN, enableTable); - verifyAllowed(USER_TBLADM, enableTable); + verifyAllowed(enableTable, SUPERUSER, USER_ADMIN, USER_TBLALL, USER_TBLADM); + verifyDenied(enableTable, USER_RW, USER_RO, USER_NONE); } @Test @@ -387,15 +336,8 @@ } }; - // all others should be denied - verifyDenied(USER_OWNER, action); - verifyDenied(USER_RW, action); - verifyDenied(USER_RO, action); - verifyDenied(USER_NONE, action); - - // verify that superuser can create tables - verifyAllowed(SUPERUSER, action); - verifyAllowed(USER_ADMIN, action); + verifyAllowed(action, SUPERUSER, USER_ADMIN); + verifyDenied(action, USER_TBLALL, USER_TBLADM, USER_RW, USER_RO, USER_NONE); } @Test @@ -413,15 +355,8 @@ } }; - // all others should be denied - verifyDenied(USER_OWNER, action); - verifyDenied(USER_RW, action); - verifyDenied(USER_RO, action); - verifyDenied(USER_NONE, action); - - // verify that superuser can create tables - verifyAllowed(SUPERUSER, action); - verifyAllowed(USER_ADMIN, action); + verifyAllowed(action, SUPERUSER, USER_ADMIN); + verifyDenied(action, USER_TBLALL, USER_TBLADM, USER_RW, USER_RO, USER_NONE); } @Test @@ -439,15 +374,8 @@ } }; - // all others should be denied - verifyDenied(USER_OWNER, action); - verifyDenied(USER_RW, action); - verifyDenied(USER_RO, action); - verifyDenied(USER_NONE, action); - - // verify that superuser can create tables - verifyAllowed(SUPERUSER, action); - verifyAllowed(USER_ADMIN, action); + verifyAllowed(action, SUPERUSER, USER_ADMIN); + verifyDenied(action, USER_TBLALL, USER_TBLADM, USER_RW, USER_RO, USER_NONE); } @Test @@ -459,15 +387,8 @@ } }; - // all others should be denied - verifyDenied(USER_OWNER, action); - verifyDenied(USER_RW, action); - verifyDenied(USER_RO, action); - verifyDenied(USER_NONE, action); - - // verify that superuser can create tables - verifyAllowed(SUPERUSER, action); - verifyAllowed(USER_ADMIN, action); + verifyAllowed(action, SUPERUSER, USER_ADMIN); + verifyDenied(action, USER_TBLALL, USER_TBLADM, USER_RW, USER_RO, USER_NONE); } @Test @@ -479,15 +400,8 @@ } }; - // all others should be denied - verifyDenied(USER_OWNER, action); - verifyDenied(USER_RW, action); - verifyDenied(USER_RO, action); - verifyDenied(USER_NONE, action); - - // verify that superuser can create tables - verifyAllowed(SUPERUSER, action); - verifyAllowed(USER_ADMIN, action); + verifyAllowed(action, SUPERUSER, USER_ADMIN); + verifyDenied(action, USER_TBLALL, USER_TBLADM, USER_RW, USER_RO, USER_NONE); } @Test @@ -499,15 +413,8 @@ } }; - // all others should be denied - verifyDenied(USER_OWNER, action); - verifyDenied(USER_RW, action); - verifyDenied(USER_RO, action); - verifyDenied(USER_NONE, action); - - // verify that superuser can create tables - verifyAllowed(SUPERUSER, action); - verifyAllowed(USER_ADMIN, action); + verifyAllowed(action, SUPERUSER, USER_ADMIN); + verifyDenied(action, USER_TBLALL, USER_TBLADM, USER_RW, USER_RO, USER_NONE); } @Test @@ -519,53 +426,64 @@ } }; - // all others should be denied - verifyDenied(USER_OWNER, action); - verifyDenied(USER_RW, action); - verifyDenied(USER_RO, action); - verifyDenied(USER_NONE, action); - - // verify that superuser can create tables - verifyAllowed(SUPERUSER, action); - verifyAllowed(USER_ADMIN, action); + verifyAllowed(action, SUPERUSER, USER_ADMIN); + verifyDenied(action, USER_TBLALL, USER_TBLADM, USER_RW, USER_RO, USER_NONE); } private void verifyWrite(PrivilegedExceptionAction action) throws Exception { - // should be denied - verifyDenied(USER_NONE, action); - verifyDenied(USER_RO, action); + verifyDenied(action, USER_NONE, USER_RO); + verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_TBLALL, USER_RW); + } - // should be allowed - verifyAllowed(SUPERUSER, action); - verifyAllowed(USER_ADMIN, action); - verifyAllowed(USER_OWNER, action); - verifyAllowed(USER_RW, action); + @Test + public void testSplit() throws Exception { + PrivilegedExceptionAction action = new PrivilegedExceptionAction() { + public Object run() throws Exception { + ACCESS_CONTROLLER.preSplit(ObserverContext.createAndPrepare(RCP_ENV, null)); + return null; + } + }; + + verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_TBLALL); + verifyDenied(action, USER_TBLADM, USER_RW, USER_RO, USER_NONE); } - private void verifyRead(PrivilegedExceptionAction action) throws Exception { - // should be denied - verifyDenied(USER_NONE, action); + @Test + public void testFlush() throws Exception { + PrivilegedExceptionAction action = new PrivilegedExceptionAction() { + public Object run() throws Exception { + ACCESS_CONTROLLER.preFlush(ObserverContext.createAndPrepare(RCP_ENV, null)); + return null; + } + }; - // should be allowed - verifyAllowed(SUPERUSER, action); - verifyAllowed(USER_ADMIN, action); - verifyAllowed(USER_OWNER, action); - verifyAllowed(USER_RW, action); - verifyAllowed(USER_RO, action); + verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_TBLALL); + verifyDenied(action, USER_TBLADM, USER_RW, USER_RO, USER_NONE); } - private void verifyReadWrite(PrivilegedExceptionAction action) throws Exception { - // should be denied - verifyDenied(USER_NONE, action); - verifyDenied(USER_RO, action); + @Test + public void testCompact() throws Exception { + PrivilegedExceptionAction action = new PrivilegedExceptionAction() { + public Object run() throws Exception { + ACCESS_CONTROLLER.preCompact(ObserverContext.createAndPrepare(RCP_ENV, null), null, null); + return null; + } + }; - // should be allowed - verifyAllowed(SUPERUSER, action); - verifyAllowed(USER_ADMIN, action); - verifyAllowed(USER_OWNER, action); - verifyAllowed(USER_RW, action); + verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_TBLALL); + verifyDenied(action, USER_TBLADM, USER_RW, USER_RO, USER_NONE); } + private void verifyRead(PrivilegedExceptionAction action) throws Exception { + verifyDenied(action, USER_NONE); + verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_TBLALL, USER_RW, USER_RO); + } + + private void verifyReadWrite(PrivilegedExceptionAction action) throws Exception { + verifyDenied(action, USER_NONE, USER_RO); + verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_TBLALL, USER_RW); + } + @Test public void testRead() throws Exception { // get action @@ -691,7 +609,6 @@ HTableDescriptor htd = new HTableDescriptor(tableName); htd.addFamily(new HColumnDescriptor(family1)); htd.addFamily(new HColumnDescriptor(family2)); - htd.setOwnerString(USER_OWNER.getShortName()); admin.createTable(htd); // create temp users @@ -923,7 +840,6 @@ HTableDescriptor htd = new HTableDescriptor(tableName); htd.addFamily(new HColumnDescriptor(family1)); htd.addFamily(new HColumnDescriptor(family2)); - htd.setOwnerString(USER_OWNER.getShortName()); admin.createTable(htd); // create temp users @@ -1028,7 +944,6 @@ HTableDescriptor htd = new HTableDescriptor(tableName); htd.addFamily(new HColumnDescriptor(family1)); htd.addFamily(new HColumnDescriptor(family2)); - htd.setOwnerString(USER_OWNER.getShortName()); admin.createTable(htd); HTable acl = new HTable(conf, AccessControlLists.ACL_TABLE_NAME); @@ -1081,14 +996,9 @@ /** global operations*/ private void verifyGlobal(PrivilegedExceptionAction action) throws Exception { - // should be allowed - verifyAllowed(SUPERUSER, action); + verifyAllowed(action, SUPERUSER); - // should be denied - verifyDenied(USER_OWNER, action); - verifyDenied(USER_RW, action); - verifyDenied(USER_NONE, action); - verifyDenied(USER_RO, action); + verifyDenied(action, USER_TBLALL, USER_RW, USER_NONE, USER_RO); } public void checkGlobalPerms(Permission.Action... actions) throws IOException { @@ -1251,7 +1161,7 @@ } }; // should be allowed - verifyAllowed(familyReadWrite, SUPERUSER, USER_OWNER, USER_RW); + verifyAllowed(familyReadWrite, SUPERUSER, USER_TBLALL, USER_RW); // should be denied verifyDenied(familyReadWrite, USER_NONE, USER_RO);