user704006
user704006

Reputation: 271

Applet Security

I have embedded an applet in an html page which access User's file directory. Its signed. When I write code inside init function then it works very well but when I write this code inside a method and call it with Javascript Then it sends me security exception. Have u any idea how can I solve this problem?

public class App extends javax.swing.JApplet {

@Override
public void init() {


 }

public void callMethod(){
    File file = new File("D:/test.txt");
    if(!file.exists()){
        try {
            file.createNewFile();
        } catch (IOException ex) {
            Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
 }

}


Javascript:  
    window.document.applets[0].callMethod();

Upvotes: 0

Views: 260

Answers (2)

Andrew Thompson
Andrew Thompson

Reputation: 168815

To be trusted, every frame on the stack must be accounted for. Once JavaScript is in the mix, that stops being the case.

To fix it, wrap the trusted code in an AccessController.doPrivileged() method. See the JavaDocs for an example.

Upvotes: 2

WhiteFang34
WhiteFang34

Reputation: 72039

See if the answers to this very similar question can help you: signed applet gives AccessControlException: access denied, when calling from javascript

Upvotes: 2

Related Questions