Java 17: guide with Custom Security Manager Denying Access to Resources When Using JavaFX
I'm wondering if anyone has experience with I'm stuck on something that should probably be simple. I'm working with an scenario with my JavaFX application when trying to implement a custom `SecurityManager` in Java 17. My application is designed to load resources from a specific directory, but when I run it with the custom security settings, it throws a `SecurityException` stating that access to the resource is denied. Here's a snippet of my `SecurityManager` implementation: ```java public class CustomSecurityManager extends SecurityManager { @Override public void checkRead(String file) { if (file.contains("restricted_dir")) { throw new SecurityException("Access denied to: " + file); } } } ``` In my `main` method, I set the security manager like this: ```java public static void main(String[] args) { System.setSecurityManager(new CustomSecurityManager()); launch(args); } ``` However, when I attempt to load an image using `Image image = new Image("file:/path/to/restricted_dir/image.png");`, I'm getting the following behavior: ``` Exception in thread "JavaFX Application Thread" java.lang.SecurityException: Access denied to: /path/to/restricted_dir/image.png ``` I've tried adjusting the `checkRead` method by adding specific conditions to allow access to certain files, but it seems to apply broadly. I also checked that the path is correct and the image file exists in the directory. The scenario continues even when I run the application with the `--add-opens` command line argument, which I thought would help with module access in Java 17 non-modular applications. Has anyone dealt with similar issues regarding resource access restrictions with a `SecurityManager` in JavaFX applications? Any guidance on how to properly configure access while ensuring my security policies are effective would be greatly appreciated. This is part of a larger CLI tool I'm building. How would you solve this?