Skip to content

Commit 8af575c

Browse files
committed
[Entitlements] Add check functions for NIO Files (elastic#122591)
1 parent 1420de7 commit 8af575c

File tree

25 files changed

+1236
-57
lines changed

25 files changed

+1236
-57
lines changed

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

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.io.FileFilter;
1515
import java.io.FilenameFilter;
1616
import java.io.InputStream;
17+
import java.io.OutputStream;
1718
import java.io.PrintStream;
1819
import java.io.PrintWriter;
1920
import java.net.ContentHandlerFactory;
@@ -51,12 +52,18 @@
5152
import java.nio.file.CopyOption;
5253
import java.nio.file.DirectoryStream;
5354
import java.nio.file.FileStore;
55+
import java.nio.file.FileVisitOption;
56+
import java.nio.file.FileVisitor;
5457
import java.nio.file.LinkOption;
5558
import java.nio.file.OpenOption;
5659
import java.nio.file.Path;
5760
import java.nio.file.WatchEvent;
5861
import java.nio.file.WatchService;
62+
import java.nio.file.attribute.BasicFileAttributes;
5963
import java.nio.file.attribute.FileAttribute;
64+
import java.nio.file.attribute.FileAttributeView;
65+
import java.nio.file.attribute.FileTime;
66+
import java.nio.file.attribute.PosixFilePermission;
6067
import java.nio.file.attribute.UserPrincipal;
6168
import java.nio.file.spi.FileSystemProvider;
6269
import java.security.KeyStore;
@@ -70,6 +77,8 @@
7077
import java.util.TimeZone;
7178
import java.util.concurrent.ExecutorService;
7279
import java.util.concurrent.ForkJoinPool;
80+
import java.util.function.BiPredicate;
81+
import java.util.function.Consumer;
7382

7483
import javax.net.ssl.HostnameVerifier;
7584
import javax.net.ssl.HttpsURLConnection;
@@ -612,6 +621,173 @@ public interface EntitlementChecker {
612621

613622
void check$java_nio_file_Files$$setOwner(Class<?> callerClass, Path path, UserPrincipal principal);
614623

624+
void check$java_nio_file_Files$$newInputStream(Class<?> callerClass, Path path, OpenOption... options);
625+
626+
void check$java_nio_file_Files$$newOutputStream(Class<?> callerClass, Path path, OpenOption... options);
627+
628+
void check$java_nio_file_Files$$newByteChannel(
629+
Class<?> callerClass,
630+
Path path,
631+
Set<? extends OpenOption> options,
632+
FileAttribute<?>... attrs
633+
);
634+
635+
void check$java_nio_file_Files$$newByteChannel(Class<?> callerClass, Path path, OpenOption... options);
636+
637+
void check$java_nio_file_Files$$newDirectoryStream(Class<?> callerClass, Path dir);
638+
639+
void check$java_nio_file_Files$$newDirectoryStream(Class<?> callerClass, Path dir, String glob);
640+
641+
void check$java_nio_file_Files$$newDirectoryStream(Class<?> callerClass, Path dir, DirectoryStream.Filter<? super Path> filter);
642+
643+
void check$java_nio_file_Files$$createFile(Class<?> callerClass, Path path, FileAttribute<?>... attrs);
644+
645+
void check$java_nio_file_Files$$createDirectory(Class<?> callerClass, Path dir, FileAttribute<?>... attrs);
646+
647+
void check$java_nio_file_Files$$createDirectories(Class<?> callerClass, Path dir, FileAttribute<?>... attrs);
648+
649+
void check$java_nio_file_Files$$createTempFile(Class<?> callerClass, Path dir, String prefix, String suffix, FileAttribute<?>... attrs);
650+
651+
void check$java_nio_file_Files$$createTempFile(Class<?> callerClass, String prefix, String suffix, FileAttribute<?>... attrs);
652+
653+
void check$java_nio_file_Files$$createTempDirectory(Class<?> callerClass, Path dir, String prefix, FileAttribute<?>... attrs);
654+
655+
void check$java_nio_file_Files$$createTempDirectory(Class<?> callerClass, String prefix, FileAttribute<?>... attrs);
656+
657+
void check$java_nio_file_Files$$createSymbolicLink(Class<?> callerClass, Path link, Path target, FileAttribute<?>... attrs);
658+
659+
void check$java_nio_file_Files$$createLink(Class<?> callerClass, Path link, Path existing);
660+
661+
void check$java_nio_file_Files$$delete(Class<?> callerClass, Path path);
662+
663+
void check$java_nio_file_Files$$deleteIfExists(Class<?> callerClass, Path path);
664+
665+
void check$java_nio_file_Files$$copy(Class<?> callerClass, Path source, Path target, CopyOption... options);
666+
667+
void check$java_nio_file_Files$$move(Class<?> callerClass, Path source, Path target, CopyOption... options);
668+
669+
void check$java_nio_file_Files$$readSymbolicLink(Class<?> callerClass, Path link);
670+
671+
void check$java_nio_file_Files$$getFileStore(Class<?> callerClass, Path path);
672+
673+
void check$java_nio_file_Files$$isSameFile(Class<?> callerClass, Path path, Path path2);
674+
675+
void check$java_nio_file_Files$$mismatch(Class<?> callerClass, Path path, Path path2);
676+
677+
void check$java_nio_file_Files$$isHidden(Class<?> callerClass, Path path);
678+
679+
void check$java_nio_file_Files$$getFileAttributeView(
680+
Class<?> callerClass,
681+
Path path,
682+
Class<? extends FileAttributeView> type,
683+
LinkOption... options
684+
);
685+
686+
void check$java_nio_file_Files$$readAttributes(
687+
Class<?> callerClass,
688+
Path path,
689+
Class<? extends BasicFileAttributes> type,
690+
LinkOption... options
691+
);
692+
693+
void check$java_nio_file_Files$$setAttribute(Class<?> callerClass, Path path, String attribute, Object value, LinkOption... options);
694+
695+
void check$java_nio_file_Files$$getAttribute(Class<?> callerClass, Path path, String attribute, LinkOption... options);
696+
697+
void check$java_nio_file_Files$$readAttributes(Class<?> callerClass, Path path, String attributes, LinkOption... options);
698+
699+
void check$java_nio_file_Files$$getPosixFilePermissions(Class<?> callerClass, Path path, LinkOption... options);
700+
701+
void check$java_nio_file_Files$$setPosixFilePermissions(Class<?> callerClass, Path path, Set<PosixFilePermission> perms);
702+
703+
void check$java_nio_file_Files$$isSymbolicLink(Class<?> callerClass, Path path);
704+
705+
void check$java_nio_file_Files$$isDirectory(Class<?> callerClass, Path path, LinkOption... options);
706+
707+
void check$java_nio_file_Files$$isRegularFile(Class<?> callerClass, Path path, LinkOption... options);
708+
709+
void check$java_nio_file_Files$$getLastModifiedTime(Class<?> callerClass, Path path, LinkOption... options);
710+
711+
void check$java_nio_file_Files$$setLastModifiedTime(Class<?> callerClass, Path path, FileTime time);
712+
713+
void check$java_nio_file_Files$$size(Class<?> callerClass, Path path);
714+
715+
void check$java_nio_file_Files$$exists(Class<?> callerClass, Path path, LinkOption... options);
716+
717+
void check$java_nio_file_Files$$notExists(Class<?> callerClass, Path path, LinkOption... options);
718+
719+
void check$java_nio_file_Files$$isReadable(Class<?> callerClass, Path path);
720+
721+
void check$java_nio_file_Files$$isWritable(Class<?> callerClass, Path path);
722+
723+
void check$java_nio_file_Files$$isExecutable(Class<?> callerClass, Path path);
724+
725+
void check$java_nio_file_Files$$walkFileTree(
726+
Class<?> callerClass,
727+
Path start,
728+
Set<FileVisitOption> options,
729+
int maxDepth,
730+
FileVisitor<? super Path> visitor
731+
);
732+
733+
void check$java_nio_file_Files$$walkFileTree(Class<?> callerClass, Path start, FileVisitor<? super Path> visitor);
734+
735+
void check$java_nio_file_Files$$newBufferedReader(Class<?> callerClass, Path path, Charset cs);
736+
737+
void check$java_nio_file_Files$$newBufferedReader(Class<?> callerClass, Path path);
738+
739+
void check$java_nio_file_Files$$newBufferedWriter(Class<?> callerClass, Path path, Charset cs, OpenOption... options);
740+
741+
void check$java_nio_file_Files$$newBufferedWriter(Class<?> callerClass, Path path, OpenOption... options);
742+
743+
void check$java_nio_file_Files$$copy(Class<?> callerClass, InputStream in, Path target, CopyOption... options);
744+
745+
void check$java_nio_file_Files$$copy(Class<?> callerClass, Path source, OutputStream out);
746+
747+
void check$java_nio_file_Files$$readAllBytes(Class<?> callerClass, Path path);
748+
749+
void check$java_nio_file_Files$$readString(Class<?> callerClass, Path path);
750+
751+
void check$java_nio_file_Files$$readString(Class<?> callerClass, Path path, Charset cs);
752+
753+
void check$java_nio_file_Files$$readAllLines(Class<?> callerClass, Path path, Charset cs);
754+
755+
void check$java_nio_file_Files$$readAllLines(Class<?> callerClass, Path path);
756+
757+
void check$java_nio_file_Files$$write(Class<?> callerClass, Path path, byte[] bytes, OpenOption... options);
758+
759+
void check$java_nio_file_Files$$write(
760+
Class<?> callerClass,
761+
Path path,
762+
Iterable<? extends CharSequence> lines,
763+
Charset cs,
764+
OpenOption... options
765+
);
766+
767+
void check$java_nio_file_Files$$write(Class<?> callerClass, Path path, Iterable<? extends CharSequence> lines, OpenOption... options);
768+
769+
void check$java_nio_file_Files$$writeString(Class<?> callerClass, Path path, CharSequence csq, OpenOption... options);
770+
771+
void check$java_nio_file_Files$$writeString(Class<?> callerClass, Path path, CharSequence csq, Charset cs, OpenOption... options);
772+
773+
void check$java_nio_file_Files$$list(Class<?> callerClass, Path dir);
774+
775+
void check$java_nio_file_Files$$walk(Class<?> callerClass, Path start, int maxDepth, FileVisitOption... options);
776+
777+
void check$java_nio_file_Files$$walk(Class<?> callerClass, Path start, FileVisitOption... options);
778+
779+
void check$java_nio_file_Files$$find(
780+
Class<?> callerClass,
781+
Path start,
782+
int maxDepth,
783+
BiPredicate<Path, BasicFileAttributes> matcher,
784+
FileVisitOption... options
785+
);
786+
787+
void check$java_nio_file_Files$$lines(Class<?> callerClass, Path path, Charset cs);
788+
789+
void check$java_nio_file_Files$$lines(Class<?> callerClass, Path path);
790+
615791
// file system providers
616792
void check$java_nio_file_spi_FileSystemProvider$(Class<?> callerClass);
617793

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323
import java.io.IOException;
2424
import java.io.RandomAccessFile;
2525
import java.nio.charset.StandardCharsets;
26-
import java.nio.file.Files;
2726
import java.nio.file.Path;
2827
import java.nio.file.Paths;
29-
import java.nio.file.attribute.UserPrincipal;
3028
import java.security.GeneralSecurityException;
3129
import java.security.KeyStore;
3230
import java.util.Scanner;
@@ -343,22 +341,6 @@ static void createRandomAccessFileReadWrite() throws IOException {
343341
new RandomAccessFile(readWriteFile().toFile(), "rw").close();
344342
}
345343

346-
@EntitlementTest(expectedAccess = PLUGINS)
347-
static void filesGetOwner() throws IOException {
348-
Files.getOwner(readFile());
349-
}
350-
351-
@EntitlementTest(expectedAccess = PLUGINS)
352-
static void filesProbeContentType() throws IOException {
353-
Files.probeContentType(readFile());
354-
}
355-
356-
@EntitlementTest(expectedAccess = PLUGINS)
357-
static void filesSetOwner() throws IOException {
358-
UserPrincipal owner = EntitledActions.getFileOwner(readWriteFile());
359-
Files.setOwner(readWriteFile(), owner); // set to existing owner, just trying to execute the method
360-
}
361-
362344
@EntitlementTest(expectedAccess = PLUGINS)
363345
static void keystoreGetInstance_FileCharArray() throws IOException {
364346
try {

0 commit comments

Comments
 (0)