I have the following problem:
I have a Java program that receives via Applet a binary file.
I received that file with getParameter(file) and read that file with java.io.FileInputStream(file).
I put this file on web server and call the java program via javascript
First, when I was running the program, was occuring the message error:
Java.security.Access.ControlException: access denied("java.io.FilePermission" "[object file]" "read")
I created 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 occuring:
Java.security.Access.ControlException: access denied("java.io.FilePermission" "[object file]" "read").
Therefore, the error persists even after signing.
I really do not know what to do.
Can anyone help me?
Below the 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 ;
}
}
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 that your applet jar(s) are signed, and that you understand all other consequences of running an applet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With