I have an java applet running on tomcat 5.5. It is signed ( -selfcert). I still get an java.security.AccessControlException: access denied (java.lang.RuntimePermission createClassLoader)
Exception, when my Applet tries to connect to a webservice (already in this line):
ws_locator = new My_WebserviceLocator(ws_adress + "?wsdl",
new javax.xml.namespace.QName("http://impl.webservice", "My_Webservice"));
Since there are some similar questions here, an i read them:
Yes, the applet is signed. I checked it with -verify.
Tomcat security exception, may be, but i have added to catalina.policy:
grant codeBase "file:/home/me/apache-tomcat-5.5.27/webapps/myapplet/-" {
permission java.security.AllPermission; };
grant codeBase "file:/home/me/apache-tomcat-5.5.27/webapps/myapplet/applet.jar" { permission java.security.AllPermission; };
and the usual stuff like is also in there:
grant codeBase "file:${java.home}/jre/lib/ext/-" {
permission java.security.AllPermission;
};
with no result.
Ok, quick update, adding:
grant{
permission java.security.AllPermission;
};
to the local java.policy file fixes the problem. BUT thats not what i am looking for, the applet should run on an avarage machine, with dafault java.policy file. So it has to be fixed from within the code.
Do you call your WS from the applet main thread or from a thread initiated by a call to the applet's method using javascript?
See example below.
Hope it helps.
public class MyApplet extends JApplet {
@Override
public void start() {
// It will work if your applet is signed
callWebService();
}
public void methodCalledFromJavascriptWrong() {
// It will NOT work even if your applet is signed
callWebService();
}
public void methodCalledFromJavascriptGood() {
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
// It will work if your applet is signed
callWebService();
return null;
}
});
}
private void callWebService() {
//Here you call your web service
}
}