1 22 package org.jboss.invocation; 23 24 import java.security.PrivilegedAction ; 25 import java.security.AccessController ; 26 27 33 class SecurityActions 34 { 35 interface TCLAction 36 { 37 class UTIL 38 { 39 static TCLAction getTCLAction() 40 { 41 return System.getSecurityManager() == null ? NON_PRIVILEGED : PRIVILEGED; 42 } 43 44 static ClassLoader getContextClassLoader() 45 { 46 return getTCLAction().getContextClassLoader(); 47 } 48 49 static ClassLoader getContextClassLoader(Thread thread) 50 { 51 return getTCLAction().getContextClassLoader(thread); 52 } 53 54 static void setContextClassLoader(ClassLoader cl) 55 { 56 getTCLAction().setContextClassLoader(cl); 57 } 58 59 static void setContextClassLoader(Thread thread, ClassLoader cl) 60 { 61 getTCLAction().setContextClassLoader(thread, cl); 62 } 63 } 64 65 TCLAction NON_PRIVILEGED = new TCLAction() 66 { 67 public ClassLoader getContextClassLoader() 68 { 69 return Thread.currentThread().getContextClassLoader(); 70 } 71 72 public ClassLoader getContextClassLoader(Thread thread) 73 { 74 return thread.getContextClassLoader(); 75 } 76 77 public void setContextClassLoader(ClassLoader cl) 78 { 79 Thread.currentThread().setContextClassLoader(cl); 80 } 81 82 public void setContextClassLoader(Thread thread, ClassLoader cl) 83 { 84 thread.setContextClassLoader(cl); 85 } 86 }; 87 88 TCLAction PRIVILEGED = new TCLAction() 89 { 90 private final PrivilegedAction getTCLPrivilegedAction = new PrivilegedAction () 91 { 92 public Object run() 93 { 94 return Thread.currentThread().getContextClassLoader(); 95 } 96 }; 97 98 public ClassLoader getContextClassLoader() 99 { 100 return (ClassLoader ) AccessController.doPrivileged(getTCLPrivilegedAction); 101 } 102 103 public ClassLoader getContextClassLoader(final Thread thread) 104 { 105 return (ClassLoader )AccessController.doPrivileged(new PrivilegedAction () 106 { 107 public Object run() 108 { 109 return thread.getContextClassLoader(); 110 } 111 }); 112 } 113 114 public void setContextClassLoader(final ClassLoader cl) 115 { 116 AccessController.doPrivileged( 117 new PrivilegedAction () 118 { 119 public Object run() 120 { 121 Thread.currentThread().setContextClassLoader(cl); 122 return null; 123 } 124 } 125 ); 126 } 127 128 public void setContextClassLoader(final Thread thread, final ClassLoader cl) 129 { 130 AccessController.doPrivileged( 131 new PrivilegedAction () 132 { 133 public Object run() 134 { 135 thread.setContextClassLoader(cl); 136 return null; 137 } 138 } 139 ); 140 } 141 }; 142 143 ClassLoader getContextClassLoader(); 144 145 ClassLoader getContextClassLoader(Thread thread); 146 147 void setContextClassLoader(ClassLoader cl); 148 149 void setContextClassLoader(Thread thread, ClassLoader cl); 150 } 151 152 static ClassLoader getContextClassLoader() 153 { 154 return TCLAction.UTIL.getContextClassLoader(); 155 } 156 157 } 158
| Popular Tags
|