Search in sources :

Example 1 with TAccessControlEntity

use of org.apache.hadoop.hbase.thrift2.generated.TAccessControlEntity in project hbase by apache.

the class TestThriftHBaseServiceHandler method testPerformNamespacePermissions.

@Test
public void testPerformNamespacePermissions() throws Throwable {
    // initialize fake objects. We test the permission grant and revoke on default NS.
    String fakeUser = "user";
    String defaultNameSpace = "default";
    TAccessControlEntity tce = new TAccessControlEntity();
    tce.setActions("R");
    tce.setNsName(defaultNameSpace);
    tce.setScope(TPermissionScope.NAMESPACE);
    tce.setUsername(fakeUser);
    ThriftHBaseServiceHandler handler = createHandler();
    handler.grant(tce);
    List<UserPermission> permissionList = AccessControlClient.getUserPermissions(UTIL.getConnection(), "@" + defaultNameSpace, fakeUser);
    // we only grant one R permission
    assertEquals(permissionList.size(), 1);
    Permission.Action[] actions = permissionList.get(0).getPermission().getActions();
    assertEquals(actions.length, 1);
    assertEquals(actions[0], Permission.Action.READ);
    // revoke the permission
    handler.revoke(tce);
    permissionList = AccessControlClient.getUserPermissions(UTIL.getConnection(), "@" + defaultNameSpace, fakeUser);
    // it should return an empty list
    assertEquals(0, permissionList.size());
}
Also used : TAccessControlEntity(org.apache.hadoop.hbase.thrift2.generated.TAccessControlEntity) UserPermission(org.apache.hadoop.hbase.security.access.UserPermission) Test(org.junit.Test)

Example 2 with TAccessControlEntity

use of org.apache.hadoop.hbase.thrift2.generated.TAccessControlEntity in project hbase by apache.

the class TestThriftHBaseServiceHandler method testPerformTablePermissions.

@Test
public void testPerformTablePermissions() throws Throwable {
    // initialize fake objects.
    String fakeUser = "user";
    TAccessControlEntity tce = new TAccessControlEntity();
    tce.setActions("R");
    tce.setTableName(Bytes.toString(tableAname));
    tce.setScope(TPermissionScope.TABLE);
    tce.setUsername(fakeUser);
    ThriftHBaseServiceHandler handler = createHandler();
    handler.grant(tce);
    List<UserPermission> permissionList = AccessControlClient.getUserPermissions(UTIL.getConnection(), Bytes.toString(tableAname), fakeUser);
    // we only grant one R permission
    assertEquals(permissionList.size(), 1);
    Permission.Action[] actions = permissionList.get(0).getPermission().getActions();
    assertEquals(actions.length, 1);
    assertEquals(actions[0], Permission.Action.READ);
    // than revoke the permission
    handler.revoke(tce);
    permissionList = AccessControlClient.getUserPermissions(UTIL.getConnection(), Bytes.toString(tableAname), fakeUser);
    // it should return an empty list
    assertEquals(0, permissionList.size());
}
Also used : TAccessControlEntity(org.apache.hadoop.hbase.thrift2.generated.TAccessControlEntity) UserPermission(org.apache.hadoop.hbase.security.access.UserPermission) Test(org.junit.Test)

Aggregations

UserPermission (org.apache.hadoop.hbase.security.access.UserPermission)2 TAccessControlEntity (org.apache.hadoop.hbase.thrift2.generated.TAccessControlEntity)2 Test (org.junit.Test)2