Skip to content

Commit 776e685

Browse files
authored
[Entitlements] Add check functions for NIO Files (#122591) (#122966)
1 parent 2d0a4c6 commit 776e685

File tree

25 files changed

+1234
-57
lines changed

25 files changed

+1234
-57
lines changed

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

Lines changed: 175 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.lang.foreign.AddressLayout;
@@ -58,12 +59,18 @@
5859
import java.nio.file.CopyOption;
5960
import java.nio.file.DirectoryStream;
6061
import java.nio.file.FileStore;
62+
import java.nio.file.FileVisitOption;
63+
import java.nio.file.FileVisitor;
6164
import java.nio.file.LinkOption;
6265
import java.nio.file.OpenOption;
6366
import java.nio.file.Path;
6467
import java.nio.file.WatchEvent;
6568
import java.nio.file.WatchService;
69+
import java.nio.file.attribute.BasicFileAttributes;
6670
import java.nio.file.attribute.FileAttribute;
71+
import java.nio.file.attribute.FileAttributeView;
72+
import java.nio.file.attribute.FileTime;
73+
import java.nio.file.attribute.PosixFilePermission;
6774
import java.nio.file.attribute.UserPrincipal;
6875
import java.nio.file.spi.FileSystemProvider;
6976
import java.security.KeyStore;
@@ -77,6 +84,7 @@
7784
import java.util.TimeZone;
7885
import java.util.concurrent.ExecutorService;
7986
import java.util.concurrent.ForkJoinPool;
87+
import java.util.function.BiPredicate;
8088
import java.util.function.Consumer;
8189

8290
import javax.net.ssl.HostnameVerifier;
@@ -674,6 +682,173 @@ public interface EntitlementChecker {
674682

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

685+
void check$java_nio_file_Files$$newInputStream(Class<?> callerClass, Path path, OpenOption... options);
686+
687+
void check$java_nio_file_Files$$newOutputStream(Class<?> callerClass, Path path, OpenOption... options);
688+
689+
void check$java_nio_file_Files$$newByteChannel(
690+
Class<?> callerClass,
691+
Path path,
692+
Set<? extends OpenOption> options,
693+
FileAttribute<?>... attrs
694+
);
695+
696+
void check$java_nio_file_Files$$newByteChannel(Class<?> callerClass, Path path, OpenOption... options);
697+
698+
void check$java_nio_file_Files$$newDirectoryStream(Class<?> callerClass, Path dir);
699+
700+
void check$java_nio_file_Files$$newDirectoryStream(Class<?> callerClass, Path dir, String glob);
701+
702+
void check$java_nio_file_Files$$newDirectoryStream(Class<?> callerClass, Path dir, DirectoryStream.Filter<? super Path> filter);
703+
704+
void check$java_nio_file_Files$$createFile(Class<?> callerClass, Path path, FileAttribute<?>... attrs);
705+
706+
void check$java_nio_file_Files$$createDirectory(Class<?> callerClass, Path dir, FileAttribute<?>... attrs);
707+
708+
void check$java_nio_file_Files$$createDirectories(Class<?> callerClass, Path dir, FileAttribute<?>... attrs);
709+
710+
void check$java_nio_file_Files$$createTempFile(Class<?> callerClass, Path dir, String prefix, String suffix, FileAttribute<?>... attrs);
711+
712+
void check$java_nio_file_Files$$createTempFile(Class<?> callerClass, String prefix, String suffix, FileAttribute<?>... attrs);
713+
714+
void check$java_nio_file_Files$$createTempDirectory(Class<?> callerClass, Path dir, String prefix, FileAttribute<?>... attrs);
715+
716+
void check$java_nio_file_Files$$createTempDirectory(Class<?> callerClass, String prefix, FileAttribute<?>... attrs);
717+
718+
void check$java_nio_file_Files$$createSymbolicLink(Class<?> callerClass, Path link, Path target, FileAttribute<?>... attrs);
719+
720+
void check$java_nio_file_Files$$createLink(Class<?> callerClass, Path link, Path existing);
721+
722+
void check$java_nio_file_Files$$delete(Class<?> callerClass, Path path);
723+
724+
void check$java_nio_file_Files$$deleteIfExists(Class<?> callerClass, Path path);
725+
726+
void check$java_nio_file_Files$$copy(Class<?> callerClass, Path source, Path target, CopyOption... options);
727+
728+
void check$java_nio_file_Files$$move(Class<?> callerClass, Path source, Path target, CopyOption... options);
729+
730+
void check$java_nio_file_Files$$readSymbolicLink(Class<?> callerClass, Path link);
731+
732+
void check$java_nio_file_Files$$getFileStore(Class<?> callerClass, Path path);
733+
734+
void check$java_nio_file_Files$$isSameFile(Class<?> callerClass, Path path, Path path2);
735+
736+
void check$java_nio_file_Files$$mismatch(Class<?> callerClass, Path path, Path path2);
737+
738+
void check$java_nio_file_Files$$isHidden(Class<?> callerClass, Path path);
739+
740+
void check$java_nio_file_Files$$getFileAttributeView(
741+
Class<?> callerClass,
742+
Path path,
743+
Class<? extends FileAttributeView> type,
744+
LinkOption... options
745+
);
746+
747+
void check$java_nio_file_Files$$readAttributes(
748+
Class<?> callerClass,
749+
Path path,
750+
Class<? extends BasicFileAttributes> type,
751+
LinkOption... options
752+
);
753+
754+
void check$java_nio_file_Files$$setAttribute(Class<?> callerClass, Path path, String attribute, Object value, LinkOption... options);
755+
756+
void check$java_nio_file_Files$$getAttribute(Class<?> callerClass, Path path, String attribute, LinkOption... options);
757+
758+
void check$java_nio_file_Files$$readAttributes(Class<?> callerClass, Path path, String attributes, LinkOption... options);
759+
760+
void check$java_nio_file_Files$$getPosixFilePermissions(Class<?> callerClass, Path path, LinkOption... options);
761+
762+
void check$java_nio_file_Files$$setPosixFilePermissions(Class<?> callerClass, Path path, Set<PosixFilePermission> perms);
763+
764+
void check$java_nio_file_Files$$isSymbolicLink(Class<?> callerClass, Path path);
765+
766+
void check$java_nio_file_Files$$isDirectory(Class<?> callerClass, Path path, LinkOption... options);
767+
768+
void check$java_nio_file_Files$$isRegularFile(Class<?> callerClass, Path path, LinkOption... options);
769+
770+
void check$java_nio_file_Files$$getLastModifiedTime(Class<?> callerClass, Path path, LinkOption... options);
771+
772+
void check$java_nio_file_Files$$setLastModifiedTime(Class<?> callerClass, Path path, FileTime time);
773+
774+
void check$java_nio_file_Files$$size(Class<?> callerClass, Path path);
775+
776+
void check$java_nio_file_Files$$exists(Class<?> callerClass, Path path, LinkOption... options);
777+
778+
void check$java_nio_file_Files$$notExists(Class<?> callerClass, Path path, LinkOption... options);
779+
780+
void check$java_nio_file_Files$$isReadable(Class<?> callerClass, Path path);
781+
782+
void check$java_nio_file_Files$$isWritable(Class<?> callerClass, Path path);
783+
784+
void check$java_nio_file_Files$$isExecutable(Class<?> callerClass, Path path);
785+
786+
void check$java_nio_file_Files$$walkFileTree(
787+
Class<?> callerClass,
788+
Path start,
789+
Set<FileVisitOption> options,
790+
int maxDepth,
791+
FileVisitor<? super Path> visitor
792+
);
793+
794+
void check$java_nio_file_Files$$walkFileTree(Class<?> callerClass, Path start, FileVisitor<? super Path> visitor);
795+
796+
void check$java_nio_file_Files$$newBufferedReader(Class<?> callerClass, Path path, Charset cs);
797+
798+
void check$java_nio_file_Files$$newBufferedReader(Class<?> callerClass, Path path);
799+
800+
void check$java_nio_file_Files$$newBufferedWriter(Class<?> callerClass, Path path, Charset cs, OpenOption... options);
801+
802+
void check$java_nio_file_Files$$newBufferedWriter(Class<?> callerClass, Path path, OpenOption... options);
803+
804+
void check$java_nio_file_Files$$copy(Class<?> callerClass, InputStream in, Path target, CopyOption... options);
805+
806+
void check$java_nio_file_Files$$copy(Class<?> callerClass, Path source, OutputStream out);
807+
808+
void check$java_nio_file_Files$$readAllBytes(Class<?> callerClass, Path path);
809+
810+
void check$java_nio_file_Files$$readString(Class<?> callerClass, Path path);
811+
812+
void check$java_nio_file_Files$$readString(Class<?> callerClass, Path path, Charset cs);
813+
814+
void check$java_nio_file_Files$$readAllLines(Class<?> callerClass, Path path, Charset cs);
815+
816+
void check$java_nio_file_Files$$readAllLines(Class<?> callerClass, Path path);
817+
818+
void check$java_nio_file_Files$$write(Class<?> callerClass, Path path, byte[] bytes, OpenOption... options);
819+
820+
void check$java_nio_file_Files$$write(
821+
Class<?> callerClass,
822+
Path path,
823+
Iterable<? extends CharSequence> lines,
824+
Charset cs,
825+
OpenOption... options
826+
);
827+
828+
void check$java_nio_file_Files$$write(Class<?> callerClass, Path path, Iterable<? extends CharSequence> lines, OpenOption... options);
829+
830+
void check$java_nio_file_Files$$writeString(Class<?> callerClass, Path path, CharSequence csq, OpenOption... options);
831+
832+
void check$java_nio_file_Files$$writeString(Class<?> callerClass, Path path, CharSequence csq, Charset cs, OpenOption... options);
833+
834+
void check$java_nio_file_Files$$list(Class<?> callerClass, Path dir);
835+
836+
void check$java_nio_file_Files$$walk(Class<?> callerClass, Path start, int maxDepth, FileVisitOption... options);
837+
838+
void check$java_nio_file_Files$$walk(Class<?> callerClass, Path start, FileVisitOption... options);
839+
840+
void check$java_nio_file_Files$$find(
841+
Class<?> callerClass,
842+
Path start,
843+
int maxDepth,
844+
BiPredicate<Path, BasicFileAttributes> matcher,
845+
FileVisitOption... options
846+
);
847+
848+
void check$java_nio_file_Files$$lines(Class<?> callerClass, Path path, Charset cs);
849+
850+
void check$java_nio_file_Files$$lines(Class<?> callerClass, Path path);
851+
677852
// file system providers
678853
void check$java_nio_file_spi_FileSystemProvider$(Class<?> callerClass);
679854

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)