views:

98

answers:

1

I simply want to call a swing action from my own popup menu. But since there is a security manager I need a solution to invoke this action without calling it directly. For instance the paste action of a text component will fail, because sun.swing.SwingUtilities2 cannot be loaded if there is any of my classes in the call stack.

Is there any way to enqueue an event to the event thread? JComponent.dispatchEvent doesn't do the job because it processes the event itself.

A: 

Short answer: you can't without signing the applet.

Long answer: If you could without permissions, you could queue all kind of interesting messages. Your example, paste, or in long form: have access to something the client has copied before, is an action the client needs to know about and authorize. Think about a rouge applet monitoring the clipboard, "pasting" everything and sending it over the wire to a remote server. Your PIN for example.

The solution is to sign your applet, thereby telling the client "It is in (your name here) responsibility that this applet is not evil." and asking the user if he/she believes you. If yes, the security manager will no longer block you. If not - well, the user distrusts you, why should the JVM do otherwise?

See http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html

Ran Biron