I'm the owner of a platform which allows anyone to upload their own products (jar files), I'm looking to secure the platform using java policy files.
I'm using JRE azul-1.8.9_345,
I'm testing with this program,
public static void main(String[] args) {
String url = "http://www.java2s.com/Code/JarDownload/test/test.jar.zip";
try {
download(url, "C:\\Users\\User\\Desktop\\Test.jar");
} catch (IOException exception) {
exception.printStackTrace();
}
}
private static void download(String urlStr, String file) throws IOException{
URL url = new URL(urlStr);
BufferedInputStream bis = new BufferedInputStream(url.openStream());
FileOutputStream fis = new FileOutputStream(file);
byte[] buffer = new byte[1024];
int count=0;
while((count = bis.read(buffer,0,1024)) != -1)
{
fis.write(buffer, 0, count);
}
fis.close();
bis.close();
}
I would like to use policy files to prevent this program from running,
None of my attempts so far have worked, I'm starting to wonder this might be a unsupported feature, and it might not work anymore.
This is my policy
grant CodeBase "file:HelloWorld.jar" {
permission java.io.FilePermission "C:\Users\User\Desktop\", "read";
};
I've tried using other permissions but they seem to do nothing as well, I appreciate the help.
Could someone layout, why this doesn't work?, why I need to specify the file?, even though given when I run the jar, where to find a list of permissions and their arguments? (permission java.io.ExamplePermission (args), (args))
Launcher\files\azul-1.8.9_345\bin\java.exe -jar HelloWorld.jar -Djava.security.manager -Djava.security.policy=C:\Users\User\Desktop\policy.policy
I've attempted using other permissions, they didn't effect the program either.