*
The moose likes Applets and the fly likes runtime permission Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "runtime permission" Watch "runtime permission" New topic
Author

runtime permission

Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Hello
I need to permit shutdownhooks in my applet. It is not malicious, honest, promise, no I am not from the govt, grin. I cant edit the individual users' policy file. Is there a way of just having a policy file for the applet or make a modification and restore the original on close? All I want to do is make sure my code fully shuts down before the jvm quits. Any insight, thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41630
    
  55
If altering the policy file is not an option, then you'd need to sign the applet.

But shutdown hooks are only executed when the JVM actually quits, which will most likely be when the browser is closed. That could be a hours or days after the applet is unloaded.

As an alternative, consider doing a proper termination in the applet's "stop" method.


Ping & DNS - my free Android networking tools app
Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Originally posted by Ulf Dittmer:
If altering the policy file is not an option, then you'd need to sign the applet.

But shutdown hooks are only executed when the JVM actually quits, which will most likely be when the browser is closed. That could be a hours or days after the applet is unloaded.

As an alternative, consider doing a proper termination in the applet's "stop" method.
Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Hi Ulf
Sorry for that blank post.

How does the plugin handle it if it is signed? Is it interpreting it, finding the ShutDownHook and then seeing signed permit the grant?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41630
    
  55
How does the plugin handle it if it is signed? Is it interpreting it, finding the ShutDownHook and then seeing signed permit the grant?


If you look at the javadocs for adShutdownHook, you'll see that it throws a SecurityException if a security manager is present (which is the case for an applet), and the code does not have the shutdownHooks RuntimePermission (which is also the case for applets, see here).

Signing the applet in effect grants the applet the that RuntimePermission, thus making it possible to register shutdown hooks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: runtime permission