Skip to content

Commit 7f33bac

Browse files
committed
improve FileAccessTree logging
1 parent a72883e commit 7f33bac

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/FileAccessTree.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,37 @@ public static FileAccessTree of(
215215
}
216216

217217
boolean canRead(Path path) {
218-
return checkPath(normalizePath(path), readPaths);
218+
var normalizedPath = normalizePath(path);
219+
var canRead = checkPath(normalizedPath, readPaths);
220+
221+
logger.trace(
222+
() -> Strings.format(
223+
"checking [%s] (normalized to [%s]) against [%s] for READ: %b",
224+
path,
225+
normalizedPath,
226+
String.join(",", readPaths),
227+
canRead
228+
)
229+
);
230+
231+
return canRead;
219232
}
220233

221234
boolean canWrite(Path path) {
222-
return checkPath(normalizePath(path), writePaths);
235+
var normalizedPath = normalizePath(path);
236+
var canWrite = checkPath(normalizedPath, writePaths);
237+
238+
logger.trace(
239+
() -> Strings.format(
240+
"checking [%s] (normalized to [%s]) against [%s] for READ_WRITE: %b",
241+
path,
242+
normalizedPath,
243+
String.join(",", writePaths),
244+
canWrite
245+
)
246+
);
247+
248+
return canWrite;
223249
}
224250

225251
/**
@@ -237,7 +263,6 @@ static String normalizePath(Path path) {
237263
}
238264

239265
private boolean checkPath(String path, String[] paths) {
240-
logger.trace(() -> Strings.format("checking [%s] against [%s]", path, String.join(",", paths)));
241266
if (paths.length == 0) {
242267
return false;
243268
}
@@ -255,8 +280,9 @@ private boolean checkPath(String path, String[] paths) {
255280
}
256281

257282
private static boolean isParent(String maybeParent, String path) {
258-
logger.trace(() -> Strings.format("checking isParent [%s] for [%s]", maybeParent, path));
259-
return path.startsWith(maybeParent) && path.startsWith(FILE_SEPARATOR, maybeParent.length());
283+
var isParent = path.startsWith(maybeParent) && path.startsWith(FILE_SEPARATOR, maybeParent.length());
284+
logger.trace(() -> Strings.format("checking isParent [%s] for [%s]: %b", maybeParent, path, isParent));
285+
return isParent;
260286
}
261287

262288
@Override

0 commit comments

Comments
 (0)