use of org.apache.accumulo.core.security.TablePermission in project accumulo by apache.
the class ZKPermHandler method revokeTablePermission.
@Override
public void revokeTablePermission(String user, String table, TablePermission permission) throws AccumuloSecurityException {
byte[] serializedPerms = zooCache.get(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table);
// User had no table permission, nothing to revoke.
if (serializedPerms == null)
return;
Set<TablePermission> tablePerms = ZKSecurityTool.convertTablePermissions(serializedPerms);
try {
if (tablePerms.remove(permission)) {
zooCache.clear();
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
if (tablePerms.size() == 0)
zoo.recursiveDelete(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table, NodeMissingPolicy.SKIP);
else
zoo.putPersistentData(ZKUserPath + "/" + user + ZKUserTablePerms + "/" + table, ZKSecurityTool.convertTablePermissions(tablePerms), NodeExistsPolicy.OVERWRITE);
}
} catch (KeeperException e) {
log.error("{}", e.getMessage(), e);
throw new AccumuloSecurityException(user, SecurityErrorCode.CONNECTION_ERROR, e);
} catch (InterruptedException e) {
log.error("{}", e.getMessage(), e);
throw new RuntimeException(e);
}
}
use of org.apache.accumulo.core.security.TablePermission in project accumulo by apache.
the class PermissionsIT method tablePermissionTest.
@Test
public void tablePermissionTest() throws Exception {
// create the test user
ClusterUser testUser = getUser(0), rootUser = getAdminUser();
String principal = testUser.getPrincipal();
AuthenticationToken token = testUser.getToken();
PasswordToken passwordToken = null;
if (token instanceof PasswordToken) {
passwordToken = (PasswordToken) token;
}
loginAs(rootUser);
Connector c = getConnector();
c.securityOperations().createLocalUser(principal, passwordToken);
loginAs(testUser);
Connector test_user_conn = c.getInstance().getConnector(principal, token);
// check for read-only access to metadata table
loginAs(rootUser);
verifyHasOnlyTheseTablePermissions(c, c.whoami(), MetadataTable.NAME, TablePermission.READ, TablePermission.ALTER_TABLE);
verifyHasOnlyTheseTablePermissions(c, principal, MetadataTable.NAME, TablePermission.READ);
String tableName = getUniqueNames(1)[0] + "__TABLE_PERMISSION_TEST__";
// test each permission
for (TablePermission perm : TablePermission.values()) {
log.debug("Verifying the {} permission", perm);
// test permission before and after granting it
createTestTable(c, principal, tableName);
loginAs(testUser);
testMissingTablePermission(test_user_conn, testUser, perm, tableName);
loginAs(rootUser);
c.securityOperations().grantTablePermission(principal, tableName, perm);
verifyHasOnlyTheseTablePermissions(c, principal, tableName, perm);
loginAs(testUser);
testGrantedTablePermission(test_user_conn, testUser, perm, tableName);
loginAs(rootUser);
createTestTable(c, principal, tableName);
c.securityOperations().revokeTablePermission(principal, tableName, perm);
verifyHasNoTablePermissions(c, principal, tableName, perm);
}
}
Aggregations