|
@@ -40,7 +40,7 @@ import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.permission.FsPermission;
|
|
import org.apache.hadoop.fs.permission.FsPermission;
|
|
import org.apache.hadoop.hdfs.server.common.Util;
|
|
import org.apache.hadoop.hdfs.server.common.Util;
|
|
import org.apache.hadoop.security.AccessControlException;
|
|
import org.apache.hadoop.security.AccessControlException;
|
|
-import org.apache.hadoop.security.UnixUserGroupInformation;
|
|
|
|
|
|
+import org.apache.hadoop.security.UserGroupInformation;
|
|
|
|
|
|
/** Unit tests for permission */
|
|
/** Unit tests for permission */
|
|
public class TestDFSPermission extends TestCase {
|
|
public class TestDFSPermission extends TestCase {
|
|
@@ -55,11 +55,11 @@ public class TestDFSPermission extends TestCase {
|
|
final private static String USER2_NAME = "user2";
|
|
final private static String USER2_NAME = "user2";
|
|
final private static String USER3_NAME = "user3";
|
|
final private static String USER3_NAME = "user3";
|
|
|
|
|
|
- private static UnixUserGroupInformation SUPERUSER;
|
|
|
|
- private static UnixUserGroupInformation USER1;
|
|
|
|
- private static UnixUserGroupInformation USER2;
|
|
|
|
- private static UnixUserGroupInformation USER3;
|
|
|
|
-
|
|
|
|
|
|
+ private static UserGroupInformation SUPERUSER;
|
|
|
|
+ private static UserGroupInformation USER1;
|
|
|
|
+ private static UserGroupInformation USER2;
|
|
|
|
+ private static UserGroupInformation USER3;
|
|
|
|
+
|
|
final private static short MAX_PERMISSION = 511;
|
|
final private static short MAX_PERMISSION = 511;
|
|
final private static short DEFAULT_UMASK = 022;
|
|
final private static short DEFAULT_UMASK = 022;
|
|
final private static short FILE_MASK = 0666;
|
|
final private static short FILE_MASK = 0666;
|
|
@@ -96,14 +96,14 @@ public class TestDFSPermission extends TestCase {
|
|
DFSTestUtil.updateConfWithFakeGroupMapping(conf, u2g_map);
|
|
DFSTestUtil.updateConfWithFakeGroupMapping(conf, u2g_map);
|
|
|
|
|
|
// Initiate all four users
|
|
// Initiate all four users
|
|
- SUPERUSER = UnixUserGroupInformation.login(conf);
|
|
|
|
- USER1 = new UnixUserGroupInformation(USER1_NAME, new String[] {
|
|
|
|
- GROUP1_NAME, GROUP2_NAME });
|
|
|
|
- USER2 = new UnixUserGroupInformation(USER2_NAME, new String[] {
|
|
|
|
- GROUP2_NAME, GROUP3_NAME });
|
|
|
|
- USER3 = new UnixUserGroupInformation(USER3_NAME, new String[] {
|
|
|
|
- GROUP3_NAME, GROUP4_NAME });
|
|
|
|
- } catch (LoginException e) {
|
|
|
|
|
|
+ SUPERUSER = UserGroupInformation.getCurrentUser();
|
|
|
|
+ USER1 = UserGroupInformation.createUserForTesting(USER1_NAME,
|
|
|
|
+ new String[] { GROUP1_NAME, GROUP2_NAME });
|
|
|
|
+ USER2 = UserGroupInformation.createUserForTesting(USER2_NAME,
|
|
|
|
+ new String[] { GROUP2_NAME, GROUP3_NAME });
|
|
|
|
+ USER3 = UserGroupInformation.createUserForTesting(USER3_NAME,
|
|
|
|
+ new String[] { GROUP3_NAME, GROUP4_NAME });
|
|
|
|
+ } catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -390,7 +390,7 @@ public class TestDFSPermission extends TestCase {
|
|
* for the given user for operations mkdir, open, setReplication,
|
|
* for the given user for operations mkdir, open, setReplication,
|
|
* getFileInfo, isDirectory, exists, getContentLength, list, rename,
|
|
* getFileInfo, isDirectory, exists, getContentLength, list, rename,
|
|
* and delete */
|
|
* and delete */
|
|
- private void testPermissionCheckingPerUser(UnixUserGroupInformation ugi,
|
|
|
|
|
|
+ private void testPermissionCheckingPerUser(UserGroupInformation ugi,
|
|
short[] ancestorPermission, short[] parentPermission,
|
|
short[] ancestorPermission, short[] parentPermission,
|
|
short[] filePermission, Path[] parentDirs, Path[] files, Path[] dirs)
|
|
short[] filePermission, Path[] parentDirs, Path[] files, Path[] dirs)
|
|
throws Exception {
|
|
throws Exception {
|
|
@@ -477,7 +477,7 @@ public class TestDFSPermission extends TestCase {
|
|
final static protected short opAncestorPermission = SEARCH_MASK;
|
|
final static protected short opAncestorPermission = SEARCH_MASK;
|
|
protected short opParentPermission;
|
|
protected short opParentPermission;
|
|
protected short opPermission;
|
|
protected short opPermission;
|
|
- protected UnixUserGroupInformation ugi;
|
|
|
|
|
|
+ protected UserGroupInformation ugi;
|
|
|
|
|
|
/* initialize */
|
|
/* initialize */
|
|
protected void set(Path path, short ancestorPermission,
|
|
protected void set(Path path, short ancestorPermission,
|
|
@@ -491,7 +491,7 @@ public class TestDFSPermission extends TestCase {
|
|
}
|
|
}
|
|
|
|
|
|
/* Perform an operation and verify if the permission checking is correct */
|
|
/* Perform an operation and verify if the permission checking is correct */
|
|
- void verifyPermission(UnixUserGroupInformation ugi) throws LoginException,
|
|
|
|
|
|
+ void verifyPermission(UserGroupInformation ugi) throws LoginException,
|
|
IOException {
|
|
IOException {
|
|
if (this.ugi != ugi) {
|
|
if (this.ugi != ugi) {
|
|
setRequiredPermissions(ugi);
|
|
setRequiredPermissions(ugi);
|
|
@@ -535,7 +535,7 @@ public class TestDFSPermission extends TestCase {
|
|
}
|
|
}
|
|
|
|
|
|
/* Set the permissions required to pass the permission checking */
|
|
/* Set the permissions required to pass the permission checking */
|
|
- protected void setRequiredPermissions(UnixUserGroupInformation ugi)
|
|
|
|
|
|
+ protected void setRequiredPermissions(UserGroupInformation ugi)
|
|
throws IOException {
|
|
throws IOException {
|
|
if (SUPERUSER.equals(ugi)) {
|
|
if (SUPERUSER.equals(ugi)) {
|
|
requiredAncestorPermission = SUPER_MASK;
|
|
requiredAncestorPermission = SUPER_MASK;
|
|
@@ -612,7 +612,7 @@ public class TestDFSPermission extends TestCase {
|
|
private CreatePermissionVerifier createVerifier =
|
|
private CreatePermissionVerifier createVerifier =
|
|
new CreatePermissionVerifier();
|
|
new CreatePermissionVerifier();
|
|
/* test if the permission checking of create/mkdir is correct */
|
|
/* test if the permission checking of create/mkdir is correct */
|
|
- private void testCreateMkdirs(UnixUserGroupInformation ugi, Path path,
|
|
|
|
|
|
+ private void testCreateMkdirs(UserGroupInformation ugi, Path path,
|
|
short ancestorPermission, short parentPermission) throws Exception {
|
|
short ancestorPermission, short parentPermission) throws Exception {
|
|
createVerifier.set(path, OpType.MKDIRS, ancestorPermission,
|
|
createVerifier.set(path, OpType.MKDIRS, ancestorPermission,
|
|
parentPermission);
|
|
parentPermission);
|
|
@@ -641,7 +641,7 @@ public class TestDFSPermission extends TestCase {
|
|
|
|
|
|
private OpenPermissionVerifier openVerifier = new OpenPermissionVerifier();
|
|
private OpenPermissionVerifier openVerifier = new OpenPermissionVerifier();
|
|
/* test if the permission checking of open is correct */
|
|
/* test if the permission checking of open is correct */
|
|
- private void testOpen(UnixUserGroupInformation ugi, Path path,
|
|
|
|
|
|
+ private void testOpen(UserGroupInformation ugi, Path path,
|
|
short ancestorPermission, short parentPermission, short filePermission)
|
|
short ancestorPermission, short parentPermission, short filePermission)
|
|
throws Exception {
|
|
throws Exception {
|
|
openVerifier
|
|
openVerifier
|
|
@@ -667,7 +667,7 @@ public class TestDFSPermission extends TestCase {
|
|
private SetReplicationPermissionVerifier replicatorVerifier =
|
|
private SetReplicationPermissionVerifier replicatorVerifier =
|
|
new SetReplicationPermissionVerifier();
|
|
new SetReplicationPermissionVerifier();
|
|
/* test if the permission checking of setReplication is correct */
|
|
/* test if the permission checking of setReplication is correct */
|
|
- private void testSetReplication(UnixUserGroupInformation ugi, Path path,
|
|
|
|
|
|
+ private void testSetReplication(UserGroupInformation ugi, Path path,
|
|
short ancestorPermission, short parentPermission, short filePermission)
|
|
short ancestorPermission, short parentPermission, short filePermission)
|
|
throws Exception {
|
|
throws Exception {
|
|
replicatorVerifier.set(path, ancestorPermission, parentPermission,
|
|
replicatorVerifier.set(path, ancestorPermission, parentPermission,
|
|
@@ -695,7 +695,7 @@ public class TestDFSPermission extends TestCase {
|
|
private SetTimesPermissionVerifier timesVerifier =
|
|
private SetTimesPermissionVerifier timesVerifier =
|
|
new SetTimesPermissionVerifier();
|
|
new SetTimesPermissionVerifier();
|
|
/* test if the permission checking of setReplication is correct */
|
|
/* test if the permission checking of setReplication is correct */
|
|
- private void testSetTimes(UnixUserGroupInformation ugi, Path path,
|
|
|
|
|
|
+ private void testSetTimes(UserGroupInformation ugi, Path path,
|
|
short ancestorPermission, short parentPermission, short filePermission)
|
|
short ancestorPermission, short parentPermission, short filePermission)
|
|
throws Exception {
|
|
throws Exception {
|
|
timesVerifier.set(path, ancestorPermission, parentPermission,
|
|
timesVerifier.set(path, ancestorPermission, parentPermission,
|
|
@@ -750,7 +750,7 @@ public class TestDFSPermission extends TestCase {
|
|
private StatsPermissionVerifier statsVerifier = new StatsPermissionVerifier();
|
|
private StatsPermissionVerifier statsVerifier = new StatsPermissionVerifier();
|
|
/* test if the permission checking of isDirectory, exist,
|
|
/* test if the permission checking of isDirectory, exist,
|
|
* getFileInfo, getContentSummary is correct */
|
|
* getFileInfo, getContentSummary is correct */
|
|
- private void testStats(UnixUserGroupInformation ugi, Path path,
|
|
|
|
|
|
+ private void testStats(UserGroupInformation ugi, Path path,
|
|
short ancestorPermission, short parentPermission) throws Exception {
|
|
short ancestorPermission, short parentPermission) throws Exception {
|
|
statsVerifier.set(path, OpType.GET_FILEINFO, ancestorPermission,
|
|
statsVerifier.set(path, OpType.GET_FILEINFO, ancestorPermission,
|
|
parentPermission);
|
|
parentPermission);
|
|
@@ -809,7 +809,7 @@ public class TestDFSPermission extends TestCase {
|
|
|
|
|
|
ListPermissionVerifier listVerifier = new ListPermissionVerifier();
|
|
ListPermissionVerifier listVerifier = new ListPermissionVerifier();
|
|
/* test if the permission checking of list is correct */
|
|
/* test if the permission checking of list is correct */
|
|
- private void testList(UnixUserGroupInformation ugi, Path file, Path dir,
|
|
|
|
|
|
+ private void testList(UserGroupInformation ugi, Path file, Path dir,
|
|
short ancestorPermission, short parentPermission, short filePermission)
|
|
short ancestorPermission, short parentPermission, short filePermission)
|
|
throws Exception {
|
|
throws Exception {
|
|
listVerifier.set(file, InodeType.FILE, ancestorPermission,
|
|
listVerifier.set(file, InodeType.FILE, ancestorPermission,
|
|
@@ -864,7 +864,7 @@ public class TestDFSPermission extends TestCase {
|
|
|
|
|
|
RenamePermissionVerifier renameVerifier = new RenamePermissionVerifier();
|
|
RenamePermissionVerifier renameVerifier = new RenamePermissionVerifier();
|
|
/* test if the permission checking of rename is correct */
|
|
/* test if the permission checking of rename is correct */
|
|
- private void testRename(UnixUserGroupInformation ugi, Path src, Path dst,
|
|
|
|
|
|
+ private void testRename(UserGroupInformation ugi, Path src, Path dst,
|
|
short srcAncestorPermission, short srcParentPermission,
|
|
short srcAncestorPermission, short srcParentPermission,
|
|
short dstAncestorPermission, short dstParentPermission) throws Exception {
|
|
short dstAncestorPermission, short dstParentPermission) throws Exception {
|
|
renameVerifier.set(src, srcAncestorPermission, srcParentPermission, dst,
|
|
renameVerifier.set(src, srcAncestorPermission, srcParentPermission, dst,
|
|
@@ -928,7 +928,7 @@ public class TestDFSPermission extends TestCase {
|
|
new DeletePermissionVerifier();
|
|
new DeletePermissionVerifier();
|
|
|
|
|
|
/* test if the permission checking of file deletion is correct */
|
|
/* test if the permission checking of file deletion is correct */
|
|
- private void testDeleteFile(UnixUserGroupInformation ugi, Path file,
|
|
|
|
|
|
+ private void testDeleteFile(UserGroupInformation ugi, Path file,
|
|
short ancestorPermission, short parentPermission) throws Exception {
|
|
short ancestorPermission, short parentPermission) throws Exception {
|
|
fileDeletionVerifier.set(file, ancestorPermission, parentPermission);
|
|
fileDeletionVerifier.set(file, ancestorPermission, parentPermission);
|
|
fileDeletionVerifier.verifyPermission(ugi);
|
|
fileDeletionVerifier.verifyPermission(ugi);
|
|
@@ -938,7 +938,7 @@ public class TestDFSPermission extends TestCase {
|
|
new DeleteDirPermissionVerifier();
|
|
new DeleteDirPermissionVerifier();
|
|
|
|
|
|
/* test if the permission checking of directory deletion is correct */
|
|
/* test if the permission checking of directory deletion is correct */
|
|
- private void testDeleteDir(UnixUserGroupInformation ugi, Path path,
|
|
|
|
|
|
+ private void testDeleteDir(UserGroupInformation ugi, Path path,
|
|
short ancestorPermission, short parentPermission, short permission,
|
|
short ancestorPermission, short parentPermission, short permission,
|
|
short[] childPermissions) throws Exception {
|
|
short[] childPermissions) throws Exception {
|
|
dirDeletionVerifier.set(path, ancestorPermission, parentPermission,
|
|
dirDeletionVerifier.set(path, ancestorPermission, parentPermission,
|
|
@@ -948,13 +948,13 @@ public class TestDFSPermission extends TestCase {
|
|
}
|
|
}
|
|
|
|
|
|
/* log into dfs as the given user */
|
|
/* log into dfs as the given user */
|
|
- private void login(UnixUserGroupInformation ugi) throws IOException {
|
|
|
|
|
|
+ private void login(UserGroupInformation ugi) throws IOException,
|
|
|
|
+ InterruptedException {
|
|
if (fs != null) {
|
|
if (fs != null) {
|
|
fs.close();
|
|
fs.close();
|
|
}
|
|
}
|
|
- UnixUserGroupInformation.saveToConf(conf,
|
|
|
|
- UnixUserGroupInformation.UGI_PROPERTY_NAME, ugi);
|
|
|
|
- fs = FileSystem.get(conf); // login as ugi
|
|
|
|
|
|
+
|
|
|
|
+ fs = DFSTestUtil.getFileSystemAs(ugi, conf);
|
|
}
|
|
}
|
|
|
|
|
|
/* test non-existent file */
|
|
/* test non-existent file */
|