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 @@ -35,6 +35,7 @@
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketImplFactory;
import java.net.URI;
import java.net.URL;
import java.net.URLStreamHandler;
import java.net.URLStreamHandlerFactory;
Expand All @@ -50,17 +51,24 @@
import java.nio.channels.SocketChannel;
import java.nio.channels.spi.SelectorProvider;
import java.nio.charset.Charset;
import java.nio.file.AccessMode;
import java.nio.file.CopyOption;
import java.nio.file.DirectoryStream;
import java.nio.file.FileStore;
import java.nio.file.LinkOption;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.UserPrincipal;
import java.nio.file.spi.FileSystemProvider;
import java.security.cert.CertStoreParameters;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.ExecutorService;
import java.util.function.Consumer;

import javax.net.ssl.HostnameVerifier;
Expand Down Expand Up @@ -553,8 +561,79 @@ public interface EntitlementChecker {
void check$java_nio_file_Files$$setOwner(Class<?> callerClass, Path path, UserPrincipal principal);

// file system providers
void check$java_nio_file_spi_FileSystemProvider$(Class<?> callerClass);

void checkNewFileSystem(Class<?> callerClass, FileSystemProvider that, URI uri, Map<String, ?> env);

void checkNewFileSystem(Class<?> callerClass, FileSystemProvider that, Path path, Map<String, ?> env);

void checkNewInputStream(Class<?> callerClass, FileSystemProvider that, Path path, OpenOption... options);

void checkNewOutputStream(Class<?> callerClass, FileSystemProvider that, Path path, OpenOption... options);

void checkNewFileChannel(
Class<?> callerClass,
FileSystemProvider that,
Path path,
Set<? extends OpenOption> options,
FileAttribute<?>... attrs
);

void checkNewAsynchronousFileChannel(
Class<?> callerClass,
FileSystemProvider that,
Path path,
Set<? extends OpenOption> options,
ExecutorService executor,
FileAttribute<?>... attrs
);

void checkNewByteChannel(
Class<?> callerClass,
FileSystemProvider that,
Path path,
Set<? extends OpenOption> options,
FileAttribute<?>... attrs
);

void checkNewDirectoryStream(Class<?> callerClass, FileSystemProvider that, Path dir, DirectoryStream.Filter<? super Path> filter);

void checkCreateDirectory(Class<?> callerClass, FileSystemProvider that, Path dir, FileAttribute<?>... attrs);

void checkCreateSymbolicLink(Class<?> callerClass, FileSystemProvider that, Path link, Path target, FileAttribute<?>... attrs);

void checkCreateLink(Class<?> callerClass, FileSystemProvider that, Path link, Path existing);

void checkDelete(Class<?> callerClass, FileSystemProvider that, Path path);

void checkDeleteIfExists(Class<?> callerClass, FileSystemProvider that, Path path);

void checkReadSymbolicLink(Class<?> callerClass, FileSystemProvider that, Path link);

void checkCopy(Class<?> callerClass, FileSystemProvider that, Path source, Path target, CopyOption... options);

void checkMove(Class<?> callerClass, FileSystemProvider that, Path source, Path target, CopyOption... options);

void checkIsSameFile(Class<?> callerClass, FileSystemProvider that, Path path, Path path2);

void checkIsHidden(Class<?> callerClass, FileSystemProvider that, Path path);

void checkGetFileStore(Class<?> callerClass, FileSystemProvider that, Path path);

void checkCheckAccess(Class<?> callerClass, FileSystemProvider that, Path path, AccessMode... modes);

void checkGetFileAttributeView(Class<?> callerClass, FileSystemProvider that, Path path, Class<?> type, LinkOption... options);

void checkReadAttributes(Class<?> callerClass, FileSystemProvider that, Path path, Class<?> type, LinkOption... options);

void checkReadAttributes(Class<?> callerClass, FileSystemProvider that, Path path, String attributes, LinkOption... options);

void checkReadAttributesIfExists(Class<?> callerClass, FileSystemProvider that, Path path, Class<?> type, LinkOption... options);

void checkSetAttribute(Class<?> callerClass, FileSystemProvider that, Path path, String attribute, Object value, LinkOption... options);

void checkExists(Class<?> callerClass, FileSystemProvider that, Path path, LinkOption... options);

// file store
void checkGetFileStoreAttributeView(Class<?> callerClass, FileStore that, Class<?> type);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,26 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.UserPrincipal;
import java.security.SecureRandom;

@SuppressForbidden(reason = "Exposes forbidden APIs for testing purposes")
public final class EntitledActions {
private EntitledActions() {}

@SuppressForbidden(reason = "Exposes forbidden APIs for testing purposes")
private static final SecureRandom random = new SecureRandom();

private static final Path testRootDir = Paths.get(System.getProperty("es.entitlements.testdir"));

private static Path readDir() {
return testRootDir.resolve("read_dir");
}

private static Path readWriteDir() {
return testRootDir.resolve("read_write_dir");
}

static void System_clearProperty(String key) {
System.clearProperty(key);
}
Expand All @@ -31,4 +45,20 @@ public static UserPrincipal getFileOwner(Path path) throws IOException {
public static void createFile(Path path) throws IOException {
Files.createFile(path);
}

public static Path createTempFileForRead() throws IOException {
return Files.createFile(readDir().resolve("entitlements-" + random.nextLong() + ".tmp"));
}

public static Path createTempFileForWrite() throws IOException {
return Files.createFile(readWriteDir().resolve("entitlements-" + random.nextLong() + ".tmp"));
}

public static Path createTempDirectoryForWrite() throws IOException {
return Files.createDirectory(readWriteDir().resolve("entitlements-dir-" + random.nextLong()));
}

public static Path createTempSymbolicLink() throws IOException {
return Files.createSymbolicLink(readDir().resolve("entitlements-link-" + random.nextLong()), readWriteDir());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,32 @@
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.SocketImpl;
import java.net.URI;
import java.nio.channels.AsynchronousChannelGroup;
import java.nio.channels.AsynchronousServerSocketChannel;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.DatagramChannel;
import java.nio.channels.Pipe;
import java.nio.channels.SeekableByteChannel;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.channels.spi.AbstractSelector;
import java.nio.channels.spi.AsynchronousChannelProvider;
import java.nio.channels.spi.SelectorProvider;
import java.nio.charset.Charset;
import java.nio.charset.spi.CharsetProvider;
import java.nio.file.AccessMode;
import java.nio.file.CopyOption;
import java.nio.file.DirectoryStream;
import java.nio.file.FileStore;
import java.nio.file.FileSystem;
import java.nio.file.LinkOption;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.FileAttributeView;
import java.nio.file.spi.FileSystemProvider;
import java.security.cert.Certificate;
import java.text.BreakIterator;
import java.text.Collator;
Expand All @@ -51,6 +65,7 @@
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.spi.CalendarDataProvider;
Expand Down Expand Up @@ -568,4 +583,97 @@ public Charset charsetForName(String charsetName) {
return null;
}
}

static class DummyFileSystemProvider extends FileSystemProvider {
@Override
public String getScheme() {
return "";
}

@Override
public FileSystem newFileSystem(URI uri, Map<String, ?> env) throws IOException {
return null;
}

@Override
public FileSystem getFileSystem(URI uri) {
return null;
}

@Override
public Path getPath(URI uri) {
return null;
}

@Override
public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs)
throws IOException {
return null;
}

@Override
public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException {
return null;
}

@Override
public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException {

}

@Override
public void delete(Path path) throws IOException {

}

@Override
public void copy(Path source, Path target, CopyOption... options) throws IOException {

}

@Override
public void move(Path source, Path target, CopyOption... options) throws IOException {

}

@Override
public boolean isSameFile(Path path, Path path2) throws IOException {
return false;
}

@Override
public boolean isHidden(Path path) throws IOException {
return false;
}

@Override
public FileStore getFileStore(Path path) throws IOException {
return null;
}

@Override
public void checkAccess(Path path, AccessMode... modes) throws IOException {

}

@Override
public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) {
return null;
}

@Override
public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException {
return null;
}

@Override
public Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException {
return Map.of();
}

@Override
public void setAttribute(Path path, String attribute, Object value, LinkOption... options) throws IOException {

}
}
}
Loading