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());
}
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());
}
Aggregations