Search in sources :

Example 1 with HDFSPermissionPolicyProvider

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);
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) FsPermission(org.apache.hadoop.fs.permission.FsPermission) HivePrivilegeObject(org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject) HiveResourceACLs(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveResourceACLs) HDFSPermissionPolicyProvider(org.apache.hadoop.hive.ql.security.authorization.HDFSPermissionPolicyProvider) Test(org.junit.Test)

Aggregations

FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 FsPermission (org.apache.hadoop.fs.permission.FsPermission)1 HDFSPermissionPolicyProvider (org.apache.hadoop.hive.ql.security.authorization.HDFSPermissionPolicyProvider)1 HivePrivilegeObject (org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject)1 HiveResourceACLs (org.apache.hadoop.hive.ql.security.authorization.plugin.HiveResourceACLs)1 Test (org.junit.Test)1