1 11 package org.eclipse.ant.internal.ui.antsupport; 12 13 14 import java.io.FileDescriptor ; 15 import java.net.InetAddress ; 16 import java.net.SocketPermission ; 17 import java.security.Permission ; 18 import java.util.PropertyPermission ; 19 20 27 public class AntSecurityManager extends SecurityManager { 28 29 private SecurityManager fSecurityManager= null; 30 private Thread fRestrictedThread= null; 31 private static final PropertyPermission fgPropertyPermission= new PropertyPermission ("*", "write"); 35 private boolean fAllowSettingSystemProperties= true; 36 37 public AntSecurityManager(SecurityManager securityManager, Thread restrictedThread, boolean allowSettingProperties) { 38 fSecurityManager= securityManager; 39 fRestrictedThread= restrictedThread; 40 fAllowSettingSystemProperties= allowSettingProperties; 41 } 42 43 public AntSecurityManager(SecurityManager securityManager, Thread restrictedThread) { 44 this(securityManager, restrictedThread, true); 45 } 46 47 50 public void checkExit(int status) { 51 if (Thread.currentThread() == fRestrictedThread) { 54 throw new AntSecurityException(); 55 } 56 if (fSecurityManager != null) { 57 fSecurityManager.checkExit(status); 58 } 59 } 60 63 public void checkAccept(String host, int port) { 64 if (fSecurityManager != null) { 65 fSecurityManager.checkAccept(host, port); 66 } 67 } 68 69 72 public void checkAccess(Thread t) { 73 if (fSecurityManager != null) { 74 fSecurityManager.checkAccess(t); 75 } 76 } 77 78 81 public void checkAccess(ThreadGroup g) { 82 if (fSecurityManager != null) { 83 fSecurityManager.checkAccess(g); 84 } 85 } 86 87 90 public void checkAwtEventQueueAccess() { 91 if (fSecurityManager != null) { 92 fSecurityManager.checkAwtEventQueueAccess(); 93 } 94 } 95 96 99 public void checkConnect(String host, int port, Object context) { 100 if (fSecurityManager != null) { 101 fSecurityManager.checkConnect(host, port, context); 102 } 103 } 104 105 108 public void checkConnect(String host, int port) { 109 if (fSecurityManager != null) { 110 fSecurityManager.checkConnect(host, port); 111 } 112 } 113 114 117 public void checkCreateClassLoader() { 118 if (fSecurityManager != null) { 119 fSecurityManager.checkCreateClassLoader(); 120 } 121 } 122 123 126 public void checkDelete(String file) { 127 if (fSecurityManager != null) { 128 fSecurityManager.checkDelete(file); 129 } 130 } 131 132 135 public void checkExec(String cmd) { 136 if (fSecurityManager != null) { 137 fSecurityManager.checkExec(cmd); 138 } 139 } 140 141 144 public void checkLink(String lib) { 145 if (fSecurityManager != null) { 146 fSecurityManager.checkLink(lib); 147 } 148 } 149 150 153 public void checkListen(int port) { 154 if (fSecurityManager != null) { 155 fSecurityManager.checkListen(port); 156 } 157 } 158 159 162 public void checkMemberAccess(Class clazz, int which) { 163 if (fSecurityManager != null) { 164 fSecurityManager.checkMemberAccess(clazz, which); 165 } 166 } 167 168 172 public void checkMulticast(InetAddress maddr, byte ttl) { 173 if (fSecurityManager != null) { 174 String host = maddr.getHostAddress(); 175 if (!host.startsWith("[") && host.indexOf(':') != -1) { host = "[" + host + "]"; } 178 checkPermission(new SocketPermission (host, "accept,connect")); } 180 } 181 182 185 public void checkMulticast(InetAddress maddr) { 186 if (fSecurityManager != null) { 187 fSecurityManager.checkMulticast(maddr); 188 } 189 } 190 191 194 public void checkPackageAccess(String pkg) { 195 if (fSecurityManager != null) { 196 fSecurityManager.checkPackageAccess(pkg); 197 } 198 } 199 200 203 public void checkPackageDefinition(String pkg) { 204 if (fSecurityManager != null) { 205 fSecurityManager.checkPackageDefinition(pkg); 206 } 207 } 208 209 212 public void checkPermission(Permission perm, Object context) { 213 if (fSecurityManager != null) { 214 fSecurityManager.checkPermission(perm, context); 215 } 216 } 217 218 221 public void checkPermission(Permission perm) { 222 if (!fAllowSettingSystemProperties && fgPropertyPermission.implies(perm) && fRestrictedThread == Thread.currentThread()) { 223 throw new AntSecurityException(); 225 } 226 if (fSecurityManager != null) { 227 fSecurityManager.checkPermission(perm); 228 } 229 } 230 231 234 public void checkPrintJobAccess() { 235 if (fSecurityManager != null) { 236 fSecurityManager.checkPrintJobAccess(); 237 } 238 } 239 240 243 public void checkPropertiesAccess() { 244 if (fSecurityManager != null) { 245 fSecurityManager.checkPropertiesAccess(); 246 } 247 super.checkPropertiesAccess(); 248 } 249 250 253 public void checkPropertyAccess(String key) { 254 if (fSecurityManager != null) { 255 fSecurityManager.checkPropertyAccess(key); 256 } 257 } 258 259 262 public void checkRead(FileDescriptor fd) { 263 if (fSecurityManager != null) { 264 fSecurityManager.checkRead(fd); 265 } 266 } 267 268 271 public void checkRead(String file, Object context) { 272 if (fSecurityManager != null) { 273 fSecurityManager.checkRead(file, context); 274 } 275 } 276 277 280 public void checkRead(String file) { 281 if (fSecurityManager != null) { 282 fSecurityManager.checkRead(file); 283 } 284 } 285 286 289 public void checkSecurityAccess(String target) { 290 if (fSecurityManager != null) { 291 fSecurityManager.checkSecurityAccess(target); 292 } 293 } 294 295 298 public void checkSetFactory() { 299 if (fSecurityManager != null) { 300 fSecurityManager.checkSetFactory(); 301 } 302 } 303 304 307 public void checkSystemClipboardAccess() { 308 if (fSecurityManager != null) { 309 fSecurityManager.checkSystemClipboardAccess(); 310 } 311 } 312 313 316 public boolean checkTopLevelWindow(Object window) { 317 if (fSecurityManager != null) { 318 return fSecurityManager.checkTopLevelWindow(window); 319 } 320 return super.checkTopLevelWindow(window); 321 } 322 323 326 public void checkWrite(FileDescriptor fd) { 327 if (fSecurityManager != null) { 328 fSecurityManager.checkWrite(fd); 329 } 330 } 331 332 335 public void checkWrite(String file) { 336 if (fSecurityManager != null) { 337 fSecurityManager.checkWrite(file); 338 } 339 } 340 341 345 public boolean getInCheck() { 346 if (fSecurityManager != null) { 347 return fSecurityManager.getInCheck(); 348 } 349 return super.getInCheck(); 350 } 351 352 355 public Object getSecurityContext() { 356 if (fSecurityManager != null) { 357 return fSecurityManager.getSecurityContext(); 358 } 359 return super.getSecurityContext(); 360 } 361 362 365 public ThreadGroup getThreadGroup() { 366 if (fSecurityManager != null) { 367 fSecurityManager.getThreadGroup(); 368 } 369 return super.getThreadGroup(); 370 } 371 } 372 | Popular Tags |