Java.security.Access.ControlException: Access Denied ("java.io.FilePermission" "[object file]" "read")
I have the following problem:
I have a Java program that fetches a binary via Applet.
I got this file with getParameter(file)
and read this file with java.io.FileInputStream(file)
.
I put this file on a web server and call a java program via javascript
First, when I ran the program, there was a message error:
Java.security.Access.ControlException: access denied("java.io.FilePermission" "[object file]" "read")
I generated a key via keytool
and signed the jar file with jarsigner
.
But even executing the command jarsigner
, when I run the Java program again, the error message continues:
Java.security.Access.ControlException: access denied("java.io.FilePermission" "[object file]" "read").
Hence, the error persists even after signing.
I really don't know what to do.
Can anyone help me?
Below java code:
public class InJava extends Applet{
String parametro;
public void sayHello() {
parametro = getParameter("parametro");
java.io.FileInputStream fis = null;
try {
fis = new java.io.FileInputStream(parametro);
}
catch (Exception e) {
String retorno_exc = e.toString();
return ;
}
}
source to share
You need to wrap your code in AccessController.doPrivileged like:
public class InJava extends Applet{
public void sayHello() {
final String parametro = getParameter("parametro");
FileInputStream fis = AccessController.doPrivileged(new PrivilegedAction<FileInputStream>() {
public FileInputStream run() {
try {
retrun new FileInputStream(parametro);
} catch (IOException e) {
// handle exception
}
}
});
}
Make sure your application jar is signed and that you understand all other implications of the running applet .
source to share