HDFS-13626. Fix incorrect username when deny the setOwner operation. Contributed by Zsolt Venczel.

This commit is contained in:
Yiqun Lin 2018-05-30 16:52:21 +08:00
parent 5f6769f796
commit b24098bc8f
2 changed files with 10 additions and 7 deletions

View File

@ -82,12 +82,12 @@ static FileStatus setOwner(
fsd.checkOwner(pc, iip);
if (!pc.isSuperUser()) {
if (username != null && !pc.getUser().equals(username)) {
throw new AccessControlException("User " + username
throw new AccessControlException("User " + pc.getUser()
+ " is not a super user (non-super user cannot change owner).");
}
if (group != null && !pc.isMemberOfGroup(group)) {
throw new AccessControlException(
"User " + username + " does not belong to " + group);
"User " + pc.getUser() + " does not belong to " + group);
}
}
unprotectedSetOwner(fsd, iip, username, group);

View File

@ -337,7 +337,8 @@ private void testNonSuperCannotChangeToOtherGroup() throws Exception {
fail("Expect ACE when a non-super user tries to change a file to a " +
"group where the user does not belong.");
} catch (AccessControlException e) {
assertThat(e.getMessage(), startsWith("User null does not belong to"));
assertThat(e.getMessage(), startsWith("User " +
userfs.getFileStatus(file).getOwner() + " does not belong to"));
}
}
@ -371,8 +372,9 @@ private void testNonSuperCannotChangeOwner() throws Exception {
userfs.setOwner(file, NOUSER, null);
fail("Expect ACE when a non-super user tries to change owner");
} catch (AccessControlException e) {
assertThat(e.getMessage(), startsWith("User " + NOUSER
+ " is not a super user (non-super user cannot change owner)"));
assertThat(e.getMessage(), startsWith("User " +
userfs.getFileStatus(file).getOwner() +
" is not a super user (non-super user cannot change owner)"));
}
}
@ -397,8 +399,9 @@ private void testNonSuperCannotChangeOwnerForNonExistentFile()
fail("Expect ACE or FNFE when a non-super user tries to change owner " +
"for a non-existent file");
} catch (AccessControlException e) {
assertThat(e.getMessage(), startsWith("User " + NOUSER
+ " is not a super user (non-super user cannot change owner)"));
assertThat(e.getMessage(), startsWith("User " +
userfs.getFileStatus(file).getOwner() +
" is not a super user (non-super user cannot change owner)"));
} catch (FileNotFoundException e) {
}
}