HDFS-10455. Logging the username when deny the setOwner operation. Contributed by Rakesh R.

This commit is contained in:
Brahma Reddy Battula 2016-10-31 00:22:51 +05:30
parent aa3cab1eb2
commit e9c7a97089
2 changed files with 9 additions and 7 deletions

View File

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

View File

@ -337,7 +337,7 @@ public class TestPermission {
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 does not belong to"));
assertThat(e.getMessage(), startsWith("User null does not belong to"));
}
}
@ -371,8 +371,8 @@ public class TestPermission {
userfs.setOwner(file, NOUSER, null);
fail("Expect ACE when a non-super user tries to change owner");
} catch (AccessControlException e) {
assertThat(e.getMessage(), startsWith(
"Non-super user cannot change owner"));
assertThat(e.getMessage(), startsWith("User " + NOUSER
+ " is not a super user (non-super user cannot change owner)"));
}
}
@ -397,8 +397,8 @@ public class TestPermission {
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(
"Non-super user cannot change owner"));
assertThat(e.getMessage(), startsWith("User " + NOUSER
+ " is not a super user (non-super user cannot change owner)"));
} catch (FileNotFoundException e) {
}
}