use of org.apache.hadoop.hive.ql.security.authorization.HDFSPermissionPolicyProvider in project hive by apache.
the class TestHDFSPermissionPolicyProvider method testPolicyProvider.
@Test
public void testPolicyProvider() throws Exception {
HDFSPermissionPolicyProvider policyProvider = new HDFSPermissionPolicyProvider(conf);
FileSystem fs = FileSystem.get(conf);
fs.setOwner(new Path(defaultTbl1Loc), "user1", "group1");
fs.setOwner(new Path(defaultTbl2Loc), "user1", "group1");
fs.setOwner(new Path(db1Loc), "user1", "group1");
fs.setOwner(new Path(db1Tbl1Loc), "user1", "group1");
// r--r--r--
fs.setPermission(new Path(defaultTbl1Loc), new FsPermission("444"));
HiveResourceACLs acls = policyProvider.getResourceACLs(new HivePrivilegeObject(HivePrivilegeObjectType.TABLE_OR_VIEW, "default", "tbl1"));
assertEquals(acls.getUserPermissions().size(), 1);
assertTrue(acls.getUserPermissions().keySet().contains("user1"));
assertEquals(acls.getGroupPermissions().size(), 2);
assertTrue(acls.getGroupPermissions().keySet().contains("group1"));
assertTrue(acls.getGroupPermissions().keySet().contains("public"));
// r--r-----
fs.setPermission(new Path(defaultTbl1Loc), new FsPermission("440"));
acls = policyProvider.getResourceACLs(new HivePrivilegeObject(HivePrivilegeObjectType.TABLE_OR_VIEW, "default", "tbl1"));
assertEquals(acls.getUserPermissions().size(), 1);
assertEquals(acls.getUserPermissions().keySet().iterator().next(), "user1");
assertEquals(acls.getGroupPermissions().size(), 1);
assertTrue(acls.getGroupPermissions().keySet().contains("group1"));
// r-----r--
fs.setPermission(new Path(defaultTbl1Loc), new FsPermission("404"));
acls = policyProvider.getResourceACLs(new HivePrivilegeObject(HivePrivilegeObjectType.TABLE_OR_VIEW, "default", "tbl1"));
assertEquals(acls.getUserPermissions().size(), 1);
assertTrue(acls.getUserPermissions().keySet().contains("user1"));
assertEquals(acls.getGroupPermissions().size(), 1);
assertTrue(acls.getGroupPermissions().keySet().contains("public"));
// r--------
fs.setPermission(new Path(defaultTbl1Loc), new FsPermission("400"));
acls = policyProvider.getResourceACLs(new HivePrivilegeObject(HivePrivilegeObjectType.TABLE_OR_VIEW, "default", "tbl1"));
assertEquals(acls.getUserPermissions().size(), 1);
assertTrue(acls.getUserPermissions().keySet().contains("user1"));
assertEquals(acls.getGroupPermissions().size(), 0);
// ------r--
fs.setPermission(new Path(defaultTbl1Loc), new FsPermission("004"));
// rwxrwxrwx
fs.setPermission(new Path(defaultTbl2Loc), new FsPermission("777"));
acls = policyProvider.getResourceACLs(new HivePrivilegeObject(HivePrivilegeObjectType.TABLE_OR_VIEW, "default", "tbl1"));
assertEquals(acls.getUserPermissions().size(), 0);
assertEquals(acls.getGroupPermissions().size(), 1);
assertTrue(acls.getGroupPermissions().keySet().contains("public"));
acls = policyProvider.getResourceACLs(new HivePrivilegeObject(HivePrivilegeObjectType.TABLE_OR_VIEW, "default", "tbl2"));
assertEquals(acls.getUserPermissions().size(), 1);
assertTrue(acls.getUserPermissions().keySet().contains("user1"));
assertEquals(acls.getGroupPermissions().size(), 2);
assertTrue(acls.getGroupPermissions().keySet().contains("group1"));
assertTrue(acls.getGroupPermissions().keySet().contains("public"));
// ------r--
fs.setPermission(new Path(db1Loc), new FsPermission("400"));
fs.delete(new Path(db1Tbl1Loc), true);
acls = policyProvider.getResourceACLs(new HivePrivilegeObject(HivePrivilegeObjectType.DATABASE, "db1", null));
assertEquals(acls.getUserPermissions().size(), 1);
assertTrue(acls.getUserPermissions().keySet().contains("user1"));
assertEquals(acls.getGroupPermissions().size(), 0);
acls = policyProvider.getResourceACLs(new HivePrivilegeObject(HivePrivilegeObjectType.TABLE_OR_VIEW, "db1", "tbl1"));
assertEquals(acls.getUserPermissions().size(), 1);
assertTrue(acls.getUserPermissions().keySet().contains("user1"));
assertEquals(acls.getGroupPermissions().size(), 0);
}
Aggregations