swing - Java SecurityManager @Override public void checkPermission(Permission perm) -
i'm building swing application , need write custom securitymanager. if write empty class extends securitymanager this
public class sandbox extends securitymanager {}
it works fine, meaning gui rendered correctly , privileges i/o revoked. need customize checkpermission method , whenever override nothing works anymore... why shouldn't work??
public class sandbox extends securitymanager { @overide public void checkpermission(permission perm) { super.checkpermission(perm); } }
update: basic example shows problem this
public static void main(string[] args) { system.setsecuritymanager(new securitymanager() { @override public void checkpermission(permission p) { if (some_condition_here) { // here } else { // resort default implementation super.checkpermission(p); } } }); new jframe().setvisible(true); }
removing "checkpermission" method application works correctly, can't head around this.
the permissions granted based on code on stack. callers must have required permission. if override method , call superclass method, code on stack implies codebase (where custom securitymanager belongs to) must have permission (your callers) ask for.
that’s difference between overriding or not. if don’t override method (possibly privileged) caller’s code on stack , requested permission. if override method code on stack , must have permission well.
so if want implement custom securitymanager invokes inherited check method must configure inherited (policy based) logic give securitymanager permissions should able grant. it’s recommended separate securitymanager rest of application different codebase securitymanager , nothing else gets generous permissions.
Comments
Post a Comment