1 52 53 package freemarker.template.utility; 54 55 import java.security.AccessControlException ; 56 import java.security.AccessController ; 57 import java.security.PrivilegedAction ; 58 59 import freemarker.log.Logger; 60 61 65 public class SecurityUtilities 66 { 67 private static final Logger logger = Logger.getLogger("freemarker.security"); 68 private SecurityUtilities() 69 { 70 } 71 72 public static String getSystemProperty(final String key) 73 { 74 return (String ) AccessController.doPrivileged( 75 new PrivilegedAction () 76 { 77 public Object run() 78 { 79 return System.getProperty(key); 80 } 81 }); 82 } 83 84 public static String getSystemProperty(final String key, final String defValue) 85 { 86 try 87 { 88 return (String ) AccessController.doPrivileged( 89 new PrivilegedAction () 90 { 91 public Object run() 92 { 93 return System.getProperty(key, defValue); 94 } 95 }); 96 } 97 catch(AccessControlException e) 98 { 99 logger.warn("Insufficient permissions to read system property '" + 100 key + "', using default value '" + defValue + "'"); 101 return defValue; 102 } 103 } 104 105 public static Integer getSystemProperty(final String key, final int defValue) 106 { 107 try 108 { 109 return (Integer ) AccessController.doPrivileged( 110 new PrivilegedAction () 111 { 112 public Object run() 113 { 114 return Integer.getInteger(key, defValue); 115 } 116 }); 117 } 118 catch(AccessControlException e) 119 { 120 logger.warn("Insufficient permissions to read system property '" + 121 key + "', using default value " + defValue + ""); 122 return new Integer (defValue); 123 } 124 } 125 } 126 | Popular Tags |