开发者

How do I detect the current security-context from a Java Applet

I have an applet that needs access to the host system (to launch programs, query for system settings etc). The applet is signed, and when the end-user accepts my certificate, the applet is free to do pretty much whatever it desires on the end-users machine. If the end-user refuses the certificate, the applet is still run, but it cannot perform it's d开发者_JAVA百科uties.

I have used System.getProperty("java.io.tmpdir") to determine if the applet is restricted. This works fine with Windows, but somehow Java behaves differently on Mac OS. (I thought part of the point with Java was to have a system-independent language with a well defined behavior - but I end up writing specific code for Mac and Windows - just like I do with C++).

Is there a reliable way to determine what security-context the applet is running within?


public static boolean isTrusted() {
     SecurityManager security = System.getSecurityManager();
     if (security == null) {
         return true;
     } else {
         try {
             security.checkPermission(new AllPermission());
             return true;
         } catch (SecurityException exc) {
             return false;
         }
     }
}

(Usual disclaimer: not tested, not compiled)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜