Skip to content

Commit 2a1a960

Browse files
committed
NIO FileSystemProvider checks
1 parent 49352fd commit 2a1a960

File tree

8 files changed

+720
-20
lines changed

8 files changed

+720
-20
lines changed

libs/entitlement/bridge/src/main/java/org/elasticsearch/entitlement/bridge/EntitlementChecker.java

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.net.Socket;
3636
import java.net.SocketAddress;
3737
import java.net.SocketImplFactory;
38+
import java.net.URI;
3839
import java.net.URL;
3940
import java.net.URLStreamHandler;
4041
import java.net.URLStreamHandlerFactory;
@@ -50,16 +51,23 @@
5051
import java.nio.channels.SocketChannel;
5152
import java.nio.channels.spi.SelectorProvider;
5253
import java.nio.charset.Charset;
54+
import java.nio.file.AccessMode;
55+
import java.nio.file.CopyOption;
56+
import java.nio.file.DirectoryStream;
5357
import java.nio.file.LinkOption;
5458
import java.nio.file.OpenOption;
5559
import java.nio.file.Path;
60+
import java.nio.file.attribute.FileAttribute;
5661
import java.nio.file.attribute.UserPrincipal;
5762
import java.nio.file.spi.FileSystemProvider;
5863
import java.security.cert.CertStoreParameters;
5964
import java.util.List;
6065
import java.util.Locale;
66+
import java.util.Map;
6167
import java.util.Properties;
68+
import java.util.Set;
6269
import java.util.TimeZone;
70+
import java.util.concurrent.ExecutorService;
6371
import java.util.function.Consumer;
6472

6573
import javax.net.ssl.HostnameVerifier;
@@ -522,5 +530,76 @@ public interface EntitlementChecker {
522530
void check$java_nio_file_Files$$setOwner(Class<?> callerClass, Path path, UserPrincipal principal);
523531

524532
// file system providers
533+
void check$java_nio_file_spi_FileSystemProvider$(Class<?> callerClass);
534+
535+
void checkNewFileSystem(Class<?> callerClass, FileSystemProvider that, URI uri, Map<String, ?> env);
536+
537+
void checkNewFileSystem(Class<?> callerClass, FileSystemProvider that, Path path, Map<String, ?> env);
538+
525539
void checkNewInputStream(Class<?> callerClass, FileSystemProvider that, Path path, OpenOption... options);
540+
541+
void checkNewOutputStream(Class<?> callerClass, FileSystemProvider that, Path path, OpenOption... options);
542+
543+
void checkNewFileChannel(
544+
Class<?> callerClass,
545+
FileSystemProvider that,
546+
Path path,
547+
Set<? extends OpenOption> options,
548+
FileAttribute<?>... attrs
549+
);
550+
551+
void checkNewAsynchronousFileChannel(
552+
Class<?> callerClass,
553+
FileSystemProvider that,
554+
Path path,
555+
Set<? extends OpenOption> options,
556+
ExecutorService executor,
557+
FileAttribute<?>... attrs
558+
);
559+
560+
void checkNewByteChannel(
561+
Class<?> callerClass,
562+
FileSystemProvider that,
563+
Path path,
564+
Set<? extends OpenOption> options,
565+
FileAttribute<?>... attrs
566+
);
567+
568+
void checkNewDirectoryStream(Class<?> callerClass, FileSystemProvider that, Path dir, DirectoryStream.Filter<? super Path> filter);
569+
570+
void checkCreateDirectory(Class<?> callerClass, FileSystemProvider that, Path dir, FileAttribute<?>... attrs);
571+
572+
void checkCreateSymbolicLink(Class<?> callerClass, FileSystemProvider that, Path link, Path target, FileAttribute<?>... attrs);
573+
574+
void checkCreateLink(Class<?> callerClass, FileSystemProvider that, Path link, Path existing);
575+
576+
void checkDelete(Class<?> callerClass, FileSystemProvider that, Path path);
577+
578+
void checkDeleteIfExists(Class<?> callerClass, FileSystemProvider that, Path path);
579+
580+
void checkReadSymbolicLink(Class<?> callerClass, FileSystemProvider that, Path link);
581+
582+
void checkCopy(Class<?> callerClass, FileSystemProvider that, Path source, Path target, CopyOption... options);
583+
584+
void checkMove(Class<?> callerClass, FileSystemProvider that, Path source, Path target, CopyOption... options);
585+
586+
void checkIsSameFile(Class<?> callerClass, FileSystemProvider that, Path path, Path path2);
587+
588+
void checkIsHidden(Class<?> callerClass, FileSystemProvider that, Path path);
589+
590+
void checkGetFileStore(Class<?> callerClass, FileSystemProvider that, Path path);
591+
592+
void checkCheckAccess(Class<?> callerClass, FileSystemProvider that, Path path, AccessMode... modes);
593+
594+
void checkGetFileAttributeView(Class<?> callerClass, FileSystemProvider that, Path path, Class<?> type, LinkOption... options);
595+
596+
void checkReadAttributes(Class<?> callerClass, FileSystemProvider that, Path path, Class<?> type, LinkOption... options);
597+
598+
void checkReadAttributes(Class<?> callerClass, FileSystemProvider that, Path path, String attributes, LinkOption... options);
599+
600+
void checkReadAttributesIfExists(Class<?> callerClass, FileSystemProvider that, Path path, Class<?> type, LinkOption... options);
601+
602+
void checkSetAttribute(Class<?> callerClass, FileSystemProvider that, Path path, String attribute, Object value, LinkOption... options);
603+
604+
void checkExists(Class<?> callerClass, FileSystemProvider that, Path path, LinkOption... options);
526605
}

libs/entitlement/qa/entitled-plugin/src/main/java/org/elasticsearch/entitlement/qa/entitled/EntitledActions.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,23 @@
1616
import java.nio.file.Path;
1717
import java.nio.file.attribute.UserPrincipal;
1818

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

22-
@SuppressForbidden(reason = "Exposes forbidden APIs for testing purposes")
2323
static void System_clearProperty(String key) {
2424
System.clearProperty(key);
2525
}
2626

2727
public static UserPrincipal getFileOwner(Path path) throws IOException {
2828
return Files.getOwner(path);
2929
}
30+
31+
public static Path createTempFile() throws IOException {
32+
return Files.createTempFile("entitlements", "");
33+
}
34+
35+
public static Path createTempDirectory() throws IOException {
36+
return Files.createTempDirectory("entitlements-dir");
37+
}
3038
}

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/DummyImplementations.java

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,32 @@
2323
import java.net.SocketAddress;
2424
import java.net.SocketException;
2525
import java.net.SocketImpl;
26+
import java.net.URI;
2627
import java.nio.channels.AsynchronousChannelGroup;
2728
import java.nio.channels.AsynchronousServerSocketChannel;
2829
import java.nio.channels.AsynchronousSocketChannel;
2930
import java.nio.channels.DatagramChannel;
3031
import java.nio.channels.Pipe;
32+
import java.nio.channels.SeekableByteChannel;
3133
import java.nio.channels.ServerSocketChannel;
3234
import java.nio.channels.SocketChannel;
3335
import java.nio.channels.spi.AbstractSelector;
3436
import java.nio.channels.spi.AsynchronousChannelProvider;
3537
import java.nio.channels.spi.SelectorProvider;
3638
import java.nio.charset.Charset;
3739
import java.nio.charset.spi.CharsetProvider;
40+
import java.nio.file.AccessMode;
41+
import java.nio.file.CopyOption;
42+
import java.nio.file.DirectoryStream;
43+
import java.nio.file.FileStore;
44+
import java.nio.file.FileSystem;
45+
import java.nio.file.LinkOption;
46+
import java.nio.file.OpenOption;
47+
import java.nio.file.Path;
48+
import java.nio.file.attribute.BasicFileAttributes;
49+
import java.nio.file.attribute.FileAttribute;
50+
import java.nio.file.attribute.FileAttributeView;
51+
import java.nio.file.spi.FileSystemProvider;
3852
import java.security.cert.Certificate;
3953
import java.text.BreakIterator;
4054
import java.text.Collator;
@@ -51,6 +65,7 @@
5165
import java.util.Iterator;
5266
import java.util.Locale;
5367
import java.util.Map;
68+
import java.util.Set;
5469
import java.util.concurrent.ExecutorService;
5570
import java.util.concurrent.ThreadFactory;
5671
import java.util.spi.CalendarDataProvider;
@@ -568,4 +583,97 @@ public Charset charsetForName(String charsetName) {
568583
return null;
569584
}
570585
}
586+
587+
static class DummyFileSystemProvider extends FileSystemProvider {
588+
@Override
589+
public String getScheme() {
590+
return "";
591+
}
592+
593+
@Override
594+
public FileSystem newFileSystem(URI uri, Map<String, ?> env) throws IOException {
595+
return null;
596+
}
597+
598+
@Override
599+
public FileSystem getFileSystem(URI uri) {
600+
return null;
601+
}
602+
603+
@Override
604+
public Path getPath(URI uri) {
605+
return null;
606+
}
607+
608+
@Override
609+
public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs)
610+
throws IOException {
611+
return null;
612+
}
613+
614+
@Override
615+
public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException {
616+
return null;
617+
}
618+
619+
@Override
620+
public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException {
621+
622+
}
623+
624+
@Override
625+
public void delete(Path path) throws IOException {
626+
627+
}
628+
629+
@Override
630+
public void copy(Path source, Path target, CopyOption... options) throws IOException {
631+
632+
}
633+
634+
@Override
635+
public void move(Path source, Path target, CopyOption... options) throws IOException {
636+
637+
}
638+
639+
@Override
640+
public boolean isSameFile(Path path, Path path2) throws IOException {
641+
return false;
642+
}
643+
644+
@Override
645+
public boolean isHidden(Path path) throws IOException {
646+
return false;
647+
}
648+
649+
@Override
650+
public FileStore getFileStore(Path path) throws IOException {
651+
return null;
652+
}
653+
654+
@Override
655+
public void checkAccess(Path path, AccessMode... modes) throws IOException {
656+
657+
}
658+
659+
@Override
660+
public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) {
661+
return null;
662+
}
663+
664+
@Override
665+
public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException {
666+
return null;
667+
}
668+
669+
@Override
670+
public Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException {
671+
return Map.of();
672+
}
673+
674+
@Override
675+
public void setAttribute(Path path, String attribute, Object value, LinkOption... options) throws IOException {
676+
677+
}
678+
}
571679
}

0 commit comments

Comments
 (0)