如何在受限小程序中安全地触发 Swing-Action?
我只想从我自己的弹出菜单中调用摆动动作。 但由于有一个安全管理器,我需要一个解决方案来调用此操作而不直接调用它。 例如,文本组件的粘贴操作将失败,因为如果调用堆栈中存在我的任何类,则无法加载 sun.swing.SwingUtilities2。
有什么方法可以将事件排队到事件线程吗? JComponent.dispatchEvent 不执行该工作,因为它本身处理事件。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短的回答:如果不签署小程序就不能。
长答案:如果您可以在没有权限的情况下,您可以对所有类型的有趣消息进行排队。 您的示例,粘贴或长形式:可以访问客户之前复制的内容,是客户需要了解和授权的操作。 想象一下一个监视剪贴板的胭脂小程序,“粘贴”所有内容并将其通过线路发送到远程服务器。 例如您的 PIN 码。
解决方案是对您的小程序进行签名,从而告诉客户“这个小程序不是邪恶的,这是(您的名字)的责任。” 并询问用户是否相信你。 如果是,安全管理员将不再阻止您。 如果不是——那么,用户不信任你,为什么 JVM 应该这样做呢?
请参阅 http://java.sun.com/developer/onlineTraining/Programming /JDCBook/signed.html
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