1 22 package org.jboss.aop.pointcut; 23 24 import java.security.AccessController ; 25 import java.security.PrivilegedActionException ; 26 import java.security.PrivilegedExceptionAction ; 27 28 33 class SecurityActions 34 { 35 36 interface LoadClassAction 37 { 38 Class loadClass(String name); 39 40 LoadClassAction PRIVILEGED = new LoadClassAction() 41 { 42 public Class loadClass(final String name) 43 { 44 try 45 { 46 return (Class )AccessController.doPrivileged(new PrivilegedExceptionAction () 47 { 48 public Object run() throws Exception 49 { 50 return Thread.currentThread().getContextClassLoader().loadClass(name); 51 } 52 }); 53 } 54 catch (PrivilegedActionException e) 55 { 56 throw new RuntimeException (name, e); 57 } 58 } 59 }; 60 61 LoadClassAction NON_PRIVILEGED = new LoadClassAction() 62 { 63 public Class loadClass(final String name) 64 { 65 try 66 { 67 return Thread.currentThread().getContextClassLoader().loadClass(name); 68 } 69 catch (ClassNotFoundException e) 70 { 71 throw new RuntimeException (e); 72 } 73 } 74 }; 75 } 76 77 static Class loadClass(String name) 78 { 79 if (System.getSecurityManager() == null) 80 { 81 return LoadClassAction.NON_PRIVILEGED.loadClass(name); 82 } 83 else 84 { 85 return LoadClassAction.PRIVILEGED.loadClass(name); 86 } 87 } 88 89 } 90 | Popular Tags |