tags:

views:

26

answers:

1

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 duties.

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?

A: 
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)

Tom Hawtin - tackline