1 19 20 package org.netbeans.core.execution; 21 22 import java.security.ProtectionDomain ; 23 import java.security.AccessControlContext ; 24 import java.security.AccessController ; 25 import java.security.PermissionCollection ; 26 import java.lang.reflect.Field ; 27 import java.util.logging.Level ; 28 import java.util.logging.Logger ; 29 30 34 class AccController { 35 36 37 static Field context; 38 39 static Field getContextField() throws Exception { 40 if (context == null) { 41 Field ctx; 42 try { 43 ctx = AccessControlContext .class.getDeclaredField("context"); } catch (NoSuchFieldException nsfe) { ctx = AccessControlContext .class.getDeclaredField("domainsArray"); } 47 ctx.setAccessible(true); 48 context = ctx; 49 } 50 return context; 51 } 52 53 54 static ProtectionDomain [] getDomains(AccessControlContext acc) throws Exception { 55 Object o = getContextField().get(acc); 56 if (o.getClass() == Object [].class) { Object [] array = (Object []) o; 58 ProtectionDomain [] domains = new ProtectionDomain [array.length]; 59 for (int i = 0; i < array.length; i++) { 60 domains[i] = (ProtectionDomain ) array[i]; 61 } 62 return domains; 63 } 64 return (ProtectionDomain []) o; 65 } 66 67 68 static IOPermissionCollection getIOPermissionCollection() { 69 return getIOPermissionCollection(AccessController.getContext()); 70 } 71 72 73 static IOPermissionCollection getIOPermissionCollection(AccessControlContext acc) { 74 try { 75 ProtectionDomain [] pds = getDomains(acc); 76 PermissionCollection pc; 77 for (int i = 0; i < pds.length; i++) { 78 pc = pds[i].getPermissions(); 79 if (pc instanceof IOPermissionCollection) { 80 return (IOPermissionCollection) pc; 81 } 82 } 83 return null; 84 } catch (final Exception e) { 85 javax.swing.SwingUtilities.invokeLater(new Runnable () { 86 public void run() { 87 Logger.getLogger(AccController.class.getName()).log(Level.WARNING, null, e); 88 } 89 }); 90 return null; 91 } 92 } 93 } 94 | Popular Tags |