1 22 package org.jboss.virtual.classloading; 23 24 import java.security.AccessController ; 25 import java.security.Policy ; 26 import java.security.PrivilegedAction ; 27 28 import org.jboss.virtual.VFS; 29 30 36 class SecurityActions 37 { 38 static PrivilegedAction <Policy > getPolicyAction = new PrivilegedAction <Policy >() { 39 public Policy run() 40 { 41 return Policy.getPolicy(); 42 } 43 }; 44 45 interface ClassLoaderActions 46 { 47 ClassLoaderActions PRIVILEGED = new ClassLoaderActions() { 48 public VFSClassLoader newClassLoader(final String [] paths, 49 final VFS vfs, final ClassLoader parent) 50 { 51 PrivilegedAction <VFSClassLoader> action = new PrivilegedAction <VFSClassLoader>() { 52 public VFSClassLoader run() 53 { 54 ClassLoader theParent = parent; 55 if (parent == null) 56 theParent = Thread.currentThread().getContextClassLoader(); 57 return new VFSClassLoader(paths, vfs, theParent); 58 } 59 }; 60 return AccessController.doPrivileged(action); 61 } 62 63 public Policy getPolicy() 64 { 65 return AccessController.doPrivileged(getPolicyAction); 66 } 67 }; 68 69 ClassLoaderActions NON_PRIVILEGED = new ClassLoaderActions() { 70 public VFSClassLoader newClassLoader(final String [] paths, 71 final VFS vfs, final ClassLoader parent) 72 { 73 ClassLoader theParent = parent; 74 if (parent == null) 75 theParent = Thread.currentThread().getContextClassLoader(); 76 return new VFSClassLoader(paths, vfs, theParent); 77 } 78 79 public Policy getPolicy() 80 { 81 return Policy.getPolicy(); 82 } 83 }; 84 85 VFSClassLoader newClassLoader(final String [] paths, final VFS vfs, ClassLoader parent); 86 87 Policy getPolicy(); 88 } 89 90 static VFSClassLoader newClassLoader(final String [] paths, 91 final VFS vfs) 92 { 93 if (System.getSecurityManager() == null) 94 { 95 return ClassLoaderActions.NON_PRIVILEGED.newClassLoader(paths, vfs, null); 96 } 97 else 98 { 99 return ClassLoaderActions.PRIVILEGED.newClassLoader(paths, vfs, null); 100 } 101 } 102 103 static VFSClassLoader newClassLoader(final String [] paths, 104 final VFS vfs, ClassLoader parent) 105 { 106 if (System.getSecurityManager() == null) 107 { 108 return ClassLoaderActions.NON_PRIVILEGED.newClassLoader(paths, vfs, 109 parent); 110 } 111 else 112 { 113 return ClassLoaderActions.PRIVILEGED 114 .newClassLoader(paths, vfs, parent); 115 } 116 } 117 118 static Policy getPolicy() 119 { 120 if (System.getSecurityManager() == null) 121 { 122 return ClassLoaderActions.NON_PRIVILEGED.getPolicy(); 123 } 124 else 125 { 126 return ClassLoaderActions.PRIVILEGED.getPolicy(); 127 } 128 } 129 130 } 131 | Popular Tags |