1 22 package org.jboss.logging.jdk; 23 24 import java.security.AccessController ; 25 import java.security.PrivilegedAction ; 26 27 31 class SecurityActions 32 { 33 interface Actions 34 { 35 Actions NON_PRIVILEGED = new Actions() 36 { 37 public String getProperty(final String name) 38 { 39 return System.getProperty(name); 40 } 41 42 public String getProperty(final String name, final String def) 43 { 44 return System.getProperty(name, def); 45 } 46 }; 47 48 Actions PRIVILEGED = new Actions() 49 { 50 public String getProperty(final String name) 51 { 52 return (String ) AccessController.doPrivileged(new PrivilegedAction () 53 { 54 public Object run() 55 { 56 return System.getProperty(name); 57 } 58 }); 59 } 60 public String getProperty(final String name, final String def) 61 { 62 return (String )AccessController.doPrivileged(new PrivilegedAction () 63 { 64 public Object run() 65 { 66 return System.getProperty(name, def); 67 } 68 }); 69 } 70 }; 71 72 String getProperty(String name); 73 String getProperty(String name, String def); 74 } 75 76 77 static String getProperty(String name) 78 { 79 String value; 80 if( System.getSecurityManager() == null ) 81 value = Actions.NON_PRIVILEGED.getProperty(name); 82 else 83 value = Actions.PRIVILEGED.getProperty(name); 84 return value; 85 } 86 static String getProperty(String name, String def) 87 { 88 String value; 89 if( System.getSecurityManager() == null ) 90 value = Actions.NON_PRIVILEGED.getProperty(name, def); 91 else 92 value = Actions.PRIVILEGED.getProperty(name, def); 93 return value; 94 } 95 } 96 97 | Popular Tags |