Java security engineering
Map a finite resource identifier
Only a server-owned constant filename is selected. No file access or symlink-safety claim is made.
Formal Syntax & Structure
java syntaxjava
approvedPath(base, key)Working Example
Example Snippetjava
public class Main { static java.nio.file.Path approvedPath(java.nio.file.Path base,String key) { return switch(key) { case "guide" -> base.resolve("guide.txt"); case "terms" -> base.resolve("terms.txt"); default -> throw new IllegalArgumentException("unknown resource"); }; } public static void main(String[] args) throws Exception { System.out.println(approvedPath(java.nio.file.Path.of("lab"),"guide").getFileName()); }}