use of org.apache.hadoop.hbase.security.access.NamespacePermission in project ranger by apache.
the class HBaseRangerAuthorizationTest method testGetUserPermission.
@Test
public void testGetUserPermission() throws Throwable {
final Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "localhost");
conf.set("hbase.zookeeper.property.clientPort", "" + port);
conf.set("zookeeper.znode.parent", "/hbase-unsecure");
String user = "IT";
UserGroupInformation ugi = UserGroupInformation.createUserForTesting(user, new String[] { "IT" });
ugi.doAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
try (Connection conn = ConnectionFactory.createConnection(conf)) {
AccessControlClient.getUserPermissions(conn, "temp");
Assert.fail();
} catch (Throwable e) {
// expected
}
return null;
}
});
user = "QA";
ugi = UserGroupInformation.createUserForTesting(user, new String[] { "QA" });
ugi.doAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
List<UserPermission> userPermissions;
try (Connection conn = ConnectionFactory.createConnection(conf)) {
userPermissions = AccessControlClient.getUserPermissions(conn, "@test_namespace");
} catch (Throwable e) {
throw new Exception(e);
}
boolean found = false;
for (UserPermission namespacePermission : userPermissions) {
if (namespacePermission.getPermission() instanceof NamespacePermission) {
found = StringUtils.equals(namespacePermission.getUser(), "@QA");
if (found) {
break;
}
}
}
Assert.assertTrue("QA is not found", found);
return null;
}
});
List<UserPermission> userPermissions;
try (Connection conn = ConnectionFactory.createConnection(conf)) {
userPermissions = AccessControlClient.getUserPermissions(conn, "temp5");
} catch (Throwable e) {
throw new Exception(e);
}
UserPermission userPermission = new UserPermission("@IT", Permission.newBuilder(TableName.valueOf("temp5")).withActions(Permission.Action.READ, Permission.Action.WRITE, Permission.Action.EXEC).build());
Assert.assertTrue("@IT permission should be there", userPermissions.contains(userPermission));
}
Aggregations