1 22 package org.jboss.test.profileservice.support; 23 24 import java.net.URL ; 25 import java.net.URLClassLoader ; 26 import java.security.PrivilegedAction ; 27 import java.security.AccessController ; 28 29 35 class SecurityActions 36 { 37 interface ClassLoaderActions 38 { 39 ClassLoaderActions PRIVILEGED = new ClassLoaderActions() 40 { 41 public URLClassLoader newClassLoader(final URL [] urls) 42 { 43 PrivilegedAction action = new PrivilegedAction () 44 { 45 public Object run() 46 { 47 return new URLClassLoader (urls); 48 } 49 }; 50 return (URLClassLoader ) AccessController.doPrivileged(action); 51 } 52 }; 53 54 ClassLoaderActions NON_PRIVILEGED = new ClassLoaderActions() 55 { 56 public URLClassLoader newClassLoader(URL [] urls) 57 { 58 return new URLClassLoader (urls); 59 } 60 }; 61 62 URLClassLoader newClassLoader(URL [] urls); 63 } 64 65 static URLClassLoader newClassLoader(URL [] urls) 66 { 67 if(System.getSecurityManager() == null) 68 { 69 return ClassLoaderActions.NON_PRIVILEGED.newClassLoader(urls); 70 } 71 else 72 { 73 return ClassLoaderActions.PRIVILEGED.newClassLoader(urls); 74 } 75 } 76 77 static String getSystemProperty(final String name) 78 { 79 PrivilegedAction action = new PrivilegedAction () 80 { 81 public Object run() 82 { 83 return System.getProperty(name); 84 } 85 }; 86 return (String ) AccessController.doPrivileged(action); 87 } 88 } 89 | Popular Tags |