1212import org .elasticsearch .entitlement .runtime .policy .entitlements .FileEntitlement ;
1313
1414import java .nio .file .Path ;
15- import java .nio .file .Paths ;
1615import java .util .ArrayList ;
1716import java .util .Arrays ;
1817import java .util .List ;
1918import java .util .Objects ;
2019
20+ import static org .elasticsearch .entitlement .runtime .policy .entitlements .FileEntitlement .normalizePath ;
21+
2122public final class FileAccessTree {
2223 public static final FileAccessTree EMPTY = new FileAccessTree (List .of ());
2324
@@ -28,7 +29,7 @@ private FileAccessTree(List<FileEntitlement> fileEntitlements) {
2829 List <String > readPaths = new ArrayList <>();
2930 List <String > writePaths = new ArrayList <>();
3031 for (FileEntitlement fileEntitlement : fileEntitlements ) {
31- String path = normalizedPath ( fileEntitlement );
32+ String path = fileEntitlement . path ( );
3233 if (fileEntitlement .mode () == FileEntitlement .Mode .READ_WRITE ) {
3334 writePaths .add (path );
3435 }
@@ -47,19 +48,11 @@ public static FileAccessTree of(List<FileEntitlement> fileEntitlements) {
4748 }
4849
4950 boolean canRead (Path path ) {
50- return checkPath (normalize (path ), readPaths );
51+ return checkPath (normalizePath (path ), readPaths );
5152 }
5253
5354 boolean canWrite (Path path ) {
54- return checkPath (normalize (path ), writePaths );
55- }
56-
57- private static String normalizedPath (FileEntitlement fileEntitlement ) {
58- return normalize (Paths .get (fileEntitlement .path ()));
59- }
60-
61- private static String normalize (Path path ) {
62- return path .toAbsolutePath ().normalize ().toString ().replace ('\\' , '/' );
55+ return checkPath (normalizePath (path ), writePaths );
6356 }
6457
6558 private static boolean checkPath (String path , String [] paths ) {
0 commit comments