1 22 package org.jboss.test.security; 23 24 import java.lang.reflect.Constructor ; 25 import java.io.FilePermission ; 26 import java.security.AllPermission ; 27 import java.security.PermissionCollection ; 28 import java.security.Permissions ; 29 import java.security.Policy ; 30 31 38 public abstract class PolicyPlugin extends Policy 39 { 40 41 private static PermissionCollection none; 42 43 44 private static PermissionCollection fileRead; 45 46 47 private static PermissionCollection all; 48 49 62 public static PolicyPlugin getInstance(Class clazz) 63 throws Exception 64 { 65 String policyClassName = System.getProperty("org.jboss.test.security.PolicyPlugin", 66 "org.jboss.test.security.TestsPolicyPlugin"); 67 Class policyClass = Thread.currentThread().getContextClassLoader().loadClass(policyClassName); 68 Class [] sig = {Class .class}; 69 Constructor ctor = policyClass.getConstructor(sig); 70 Object [] args = {clazz}; 71 return (PolicyPlugin) ctor.newInstance(args); 72 } 73 74 77 public void refresh() 78 { 79 } 80 81 85 protected PermissionCollection noPermissions() 86 { 87 if (none == null) 88 none = new Permissions (); 89 return none; 90 } 91 92 97 protected PermissionCollection fileReadPermissions() 98 { 99 if (fileRead == null) 100 { 101 fileRead = new Permissions (); 102 fileRead.add(new FilePermission ("<<ALL FILES>>", "read")); 103 } 104 return fileRead; 105 } 106 107 114 protected PermissionCollection allPermissions() 115 { 116 if (all == null) 117 { 118 all = new Permissions (); 119 all.add(new AllPermission ()); 120 } 121 return all; 122 } 123 } 124 | Popular Tags |