Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
requires java.logging;
requires java.net.http;
requires jdk.net;
requires java.desktop;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.util.zip.ZipException;
import java.util.zip.ZipFile;

import javax.imageio.stream.FileImageInputStream;

import static java.nio.charset.Charset.defaultCharset;
import static java.nio.file.StandardOpenOption.CREATE;
import static java.nio.file.StandardOpenOption.WRITE;
Expand Down Expand Up @@ -561,5 +563,13 @@ static void httpResponseBodySubscribersOfFile_FileOpenOptions_readOnly() {
HttpResponse.BodySubscribers.ofFile(readFile(), CREATE, WRITE);
}

@EntitlementTest(expectedAccess = ALWAYS_DENIED)
static void javaDesktopFileAccess() throws Exception {
// Test file access from a java.desktop class. We explicitly exclude that module from the "system modules", so we expect
// any sensitive operation from java.desktop to fail.
var file = EntitledActions.createTempFileForRead();
new FileImageInputStream(file.toFile()).close();
}

private FileCheckActions() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class PolicyManager {

static final Class<?> DEFAULT_FILESYSTEM_CLASS = PathUtils.getDefaultFileSystem().getClass();

static final Set<String> MODULES_EXCLUDED_FROM_SYSTEM_MODULES = Set.of("java.desktop");

/**
* @param componentName the plugin name; or else one of the special component names
* like {@link #SERVER_COMPONENT_NAME} or {@link #APM_AGENT_COMPONENT_NAME}.
Expand Down Expand Up @@ -141,7 +143,13 @@ private static Set<Module> findSystemModules() {
// entitlements is a "system" module, we can do anything from it
Stream.of(PolicyManager.class.getModule()),
// anything in the boot layer is also part of the system
ModuleLayer.boot().modules().stream().filter(m -> systemModulesDescriptors.contains(m.getDescriptor()))
ModuleLayer.boot()
.modules()
.stream()
.filter(
m -> systemModulesDescriptors.contains(m.getDescriptor())
&& MODULES_EXCLUDED_FROM_SYSTEM_MODULES.contains(m.getName()) == false
)
).collect(Collectors.toUnmodifiableSet());
}

Expand Down