提交 56dc9c09 编写于 作者: A alanb

8028270: Files.readSymbolicLink calls AccessController directly so security...

8028270: Files.readSymbolicLink calls AccessController directly so security manager can't grant the permission
Reviewed-by: mchung, martin, chegar
上级 8adcb764
...@@ -484,7 +484,7 @@ public abstract class UnixFileSystemProvider ...@@ -484,7 +484,7 @@ public abstract class UnixFileSystemProvider
if (sm != null) { if (sm != null) {
FilePermission perm = new FilePermission(link.getPathForPermissionCheck(), FilePermission perm = new FilePermission(link.getPathForPermissionCheck(),
SecurityConstants.FILE_READLINK_ACTION); SecurityConstants.FILE_READLINK_ACTION);
AccessController.checkPermission(perm); sm.checkPermission(perm);
} }
try { try {
byte[] target = readlink(link); byte[] target = readlink(link);
......
...@@ -614,7 +614,7 @@ public class WindowsFileSystemProvider ...@@ -614,7 +614,7 @@ public class WindowsFileSystemProvider
if (sm != null) { if (sm != null) {
FilePermission perm = new FilePermission(link.getPathForPermissionCheck(), FilePermission perm = new FilePermission(link.getPathForPermissionCheck(),
SecurityConstants.FILE_READLINK_ACTION); SecurityConstants.FILE_READLINK_ACTION);
AccessController.checkPermission(perm); sm.checkPermission(perm);
} }
String target = WindowsLinkSupport.readLink(link); String target = WindowsLinkSupport.readLink(link);
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
*/ */
/* @test /* @test
* @bug 6866804 7006126 * @bug 6866804 7006126 8028270
* @summary Unit test for java.nio.file.Files * @summary Unit test for java.nio.file.Files
* @library .. * @library ..
* @build CheckPermissions * @build CheckPermissions
...@@ -73,14 +73,9 @@ public class CheckPermissions { ...@@ -73,14 +73,9 @@ public class CheckPermissions {
myChecks.set(new Checks()); myChecks.set(new Checks());
} }
static void assertCheckPermission(Class<? extends Permission> type, static void assertCheckPermission(Permission expected) {
String name) if (!myChecks.get().permissionsChecked().contains(expected))
{ throw new RuntimeException(expected + " not checked");
for (Permission perm: myChecks.get().permissionsChecked()) {
if (type.isInstance(perm) && perm.getName().equals(name))
return;
}
throw new RuntimeException(type.getName() + "(\"" + name + "\") not checked");
} }
static void assertCheckPropertyAccess(String key) { static void assertCheckPropertyAccess(String key) {
...@@ -191,22 +186,22 @@ public class CheckPermissions { ...@@ -191,22 +186,22 @@ public class CheckPermissions {
prepare(); prepare();
PosixFileAttributes attrs = view.readAttributes(); PosixFileAttributes attrs = view.readAttributes();
assertCheckRead(file); assertCheckRead(file);
assertCheckPermission(RuntimePermission.class, "accessUserInformation"); assertCheckPermission(new RuntimePermission("accessUserInformation"));
prepare(); prepare();
view.setPermissions(attrs.permissions()); view.setPermissions(attrs.permissions());
assertCheckWrite(file); assertCheckWrite(file);
assertCheckPermission(RuntimePermission.class, "accessUserInformation"); assertCheckPermission(new RuntimePermission("accessUserInformation"));
prepare(); prepare();
view.setOwner(attrs.owner()); view.setOwner(attrs.owner());
assertCheckWrite(file); assertCheckWrite(file);
assertCheckPermission(RuntimePermission.class, "accessUserInformation"); assertCheckPermission(new RuntimePermission("accessUserInformation"));
prepare(); prepare();
view.setOwner(attrs.owner()); view.setOwner(attrs.owner());
assertCheckWrite(file); assertCheckWrite(file);
assertCheckPermission(RuntimePermission.class, "accessUserInformation"); assertCheckPermission(new RuntimePermission("accessUserInformation"));
} }
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
...@@ -256,10 +251,14 @@ public class CheckPermissions { ...@@ -256,10 +251,14 @@ public class CheckPermissions {
try { try {
assertCheckRead(link); assertCheckRead(link);
assertCheckWrite(target); assertCheckWrite(target);
assertCheckPermission(LinkPermission.class, "symbolic"); assertCheckPermission(new LinkPermission("symbolic"));
} finally { } finally {
delete(target); delete(target);
} }
prepare();
readSymbolicLink(link);
assertCheckPermission(new FilePermission(link.toString(), "readlink"));
} finally { } finally {
delete(link); delete(link);
} }
...@@ -295,7 +294,7 @@ public class CheckPermissions { ...@@ -295,7 +294,7 @@ public class CheckPermissions {
createSymbolicLink(link, file); createSymbolicLink(link, file);
try { try {
assertCheckWrite(link); assertCheckWrite(link);
assertCheckPermission(LinkPermission.class, "symbolic"); assertCheckPermission(new LinkPermission("symbolic"));
} finally { } finally {
delete(link); delete(link);
} }
...@@ -309,7 +308,7 @@ public class CheckPermissions { ...@@ -309,7 +308,7 @@ public class CheckPermissions {
createLink(link, file); createLink(link, file);
try { try {
assertCheckWrite(link); assertCheckWrite(link);
assertCheckPermission(LinkPermission.class, "hard"); assertCheckPermission(new LinkPermission("hard"));
} finally { } finally {
delete(link); delete(link);
} }
...@@ -382,7 +381,7 @@ public class CheckPermissions { ...@@ -382,7 +381,7 @@ public class CheckPermissions {
prepare(); prepare();
getFileStore(file); getFileStore(file);
assertCheckRead(file); assertCheckRead(file);
assertCheckPermission(RuntimePermission.class, "getFileStoreAttributes"); assertCheckPermission(new RuntimePermission("getFileStoreAttributes"));
// -- isSameFile -- // -- isSameFile --
...@@ -620,12 +619,12 @@ public class CheckPermissions { ...@@ -620,12 +619,12 @@ public class CheckPermissions {
prepare(); prepare();
UserPrincipal owner = view.getOwner(); UserPrincipal owner = view.getOwner();
assertCheckRead(file); assertCheckRead(file);
assertCheckPermission(RuntimePermission.class, "accessUserInformation"); assertCheckPermission(new RuntimePermission("accessUserInformation"));
prepare(); prepare();
view.setOwner(owner); view.setOwner(owner);
assertCheckWrite(file); assertCheckWrite(file);
assertCheckPermission(RuntimePermission.class, "accessUserInformation"); assertCheckPermission(new RuntimePermission("accessUserInformation"));
} else { } else {
System.out.println("FileOwnerAttributeView not tested"); System.out.println("FileOwnerAttributeView not tested");
...@@ -643,32 +642,27 @@ public class CheckPermissions { ...@@ -643,32 +642,27 @@ public class CheckPermissions {
prepare(); prepare();
view.write("test", ByteBuffer.wrap(new byte[100])); view.write("test", ByteBuffer.wrap(new byte[100]));
assertCheckWrite(file); assertCheckWrite(file);
assertCheckPermission(RuntimePermission.class, assertCheckPermission(new RuntimePermission("accessUserDefinedAttributes"));
"accessUserDefinedAttributes");
prepare(); prepare();
view.read("test", ByteBuffer.allocate(100)); view.read("test", ByteBuffer.allocate(100));
assertCheckRead(file); assertCheckRead(file);
assertCheckPermission(RuntimePermission.class, assertCheckPermission(new RuntimePermission("accessUserDefinedAttributes"));
"accessUserDefinedAttributes");
prepare(); prepare();
view.size("test"); view.size("test");
assertCheckRead(file); assertCheckRead(file);
assertCheckPermission(RuntimePermission.class, assertCheckPermission(new RuntimePermission("accessUserDefinedAttributes"));
"accessUserDefinedAttributes");
prepare(); prepare();
view.list(); view.list();
assertCheckRead(file); assertCheckRead(file);
assertCheckPermission(RuntimePermission.class, assertCheckPermission(new RuntimePermission("accessUserDefinedAttributes"));
"accessUserDefinedAttributes");
prepare(); prepare();
view.delete("test"); view.delete("test");
assertCheckWrite(file); assertCheckWrite(file);
assertCheckPermission(RuntimePermission.class, assertCheckPermission(new RuntimePermission("accessUserDefinedAttributes"));
"accessUserDefinedAttributes");
} else { } else {
System.out.println("UserDefinedFileAttributeView not tested"); System.out.println("UserDefinedFileAttributeView not tested");
} }
...@@ -684,11 +678,11 @@ public class CheckPermissions { ...@@ -684,11 +678,11 @@ public class CheckPermissions {
prepare(); prepare();
List<AclEntry> acl = view.getAcl(); List<AclEntry> acl = view.getAcl();
assertCheckRead(file); assertCheckRead(file);
assertCheckPermission(RuntimePermission.class, "accessUserInformation"); assertCheckPermission(new RuntimePermission("accessUserInformation"));
prepare(); prepare();
view.setAcl(acl); view.setAcl(acl);
assertCheckWrite(file); assertCheckWrite(file);
assertCheckPermission(RuntimePermission.class, "accessUserInformation"); assertCheckPermission(new RuntimePermission("accessUserInformation"));
} else { } else {
System.out.println("AclFileAttributeView not tested"); System.out.println("AclFileAttributeView not tested");
} }
...@@ -702,15 +696,13 @@ public class CheckPermissions { ...@@ -702,15 +696,13 @@ public class CheckPermissions {
prepare(); prepare();
lookupService.lookupPrincipalByName(owner.getName()); lookupService.lookupPrincipalByName(owner.getName());
assertCheckPermission(RuntimePermission.class, assertCheckPermission(new RuntimePermission("lookupUserInformation"));
"lookupUserInformation");
try { try {
UserPrincipal group = readAttributes(file, PosixFileAttributes.class).group(); UserPrincipal group = readAttributes(file, PosixFileAttributes.class).group();
prepare(); prepare();
lookupService.lookupPrincipalByGroupName(group.getName()); lookupService.lookupPrincipalByGroupName(group.getName());
assertCheckPermission(RuntimePermission.class, assertCheckPermission(new RuntimePermission("lookupUserInformation"));
"lookupUserInformation");
} catch (UnsupportedOperationException ignore) { } catch (UnsupportedOperationException ignore) {
System.out.println("lookupPrincipalByGroupName not tested"); System.out.println("lookupPrincipalByGroupName not tested");
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册