1 11 package org.eclipse.ant.internal.core; 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 import org.eclipse.ant.core.AntSecurityException; 20 21 28 public class AntSecurityManager extends SecurityManager { 29 30 private SecurityManager fSecurityManager= null; 31 private Thread fRestrictedThread= null; 32 private static final PropertyPermission fgPropertyPermission= new PropertyPermission ("*", "write"); 36 private boolean fAllowSettingSystemProperties= true; 37 38 public AntSecurityManager(SecurityManager securityManager, Thread restrictedThread, boolean allowSettingProperties) { 39 fSecurityManager= securityManager; 40 fRestrictedThread= restrictedThread; 41 fAllowSettingSystemProperties= allowSettingProperties; 42 } 43 44 public AntSecurityManager(SecurityManager securityManager, Thread restrictedThread) { 45 this(securityManager, restrictedThread, true); 46 } 47 48 51 public void checkExit(int status) { 52 if (Thread.currentThread() == fRestrictedThread) { 56 throw new AntSecurityException(); 57 } 58 if (fSecurityManager != null) { 59 fSecurityManager.checkExit(status); 60 } 61 } 62 65 public void checkAccept(String host, int port) { 66 if (fSecurityManager != null) { 67 fSecurityManager.checkAccept(host, port); 68 } 69 } 70 71 74 public void checkAccess(Thread t) { 75 if (fSecurityManager != null) { 76 fSecurityManager.checkAccess(t); 77 } 78 } 79 80 83 public void checkAccess(ThreadGroup g) { 84 if (fSecurityManager != null) { 85 fSecurityManager.checkAccess(g); 86 } 87 } 88 89 92 public void checkAwtEventQueueAccess() { 93 if (fSecurityManager != null) { 94 fSecurityManager.checkAwtEventQueueAccess(); 95 } 96 } 97 98 101 public void checkConnect(String host, int port, Object context) { 102 if (fSecurityManager != null) { 103 fSecurityManager.checkConnect(host, port, context); 104 } 105 } 106 107 110 public void checkConnect(String host, int port) { 111 if (fSecurityManager != null) { 112 fSecurityManager.checkConnect(host, port); 113 } 114 } 115 116 119 public void checkCreateClassLoader() { 120 if (fSecurityManager != null) { 121 fSecurityManager.checkCreateClassLoader(); 122 } 123 } 124 125 128 public void checkDelete(String file) { 129 if (fSecurityManager != null) { 130 fSecurityManager.checkDelete(file); 131 } 132 } 133 134 137 public void checkExec(String cmd) { 138 if (fSecurityManager != null) { 139 fSecurityManager.checkExec(cmd); 140 } 141 } 142 143 146 public void checkLink(String lib) { 147 if (fSecurityManager != null) { 148 fSecurityManager.checkLink(lib); 149 } 150 } 151 152 155 public void checkListen(int port) { 156 if (fSecurityManager != null) { 157 fSecurityManager.checkListen(port); 158 } 159 } 160 161 164 public void checkMemberAccess(Class clazz, int which) { 165 if (fSecurityManager != null) { 166 fSecurityManager.checkMemberAccess(clazz, which); 167 } 168 } 169 170 174 public void checkMulticast(InetAddress maddr, byte ttl) { 175 if (fSecurityManager != null) { 176 String host = maddr.getHostAddress(); 177 if (!host.startsWith("[") && host.indexOf(':') != -1) { host = "[" + host + "]"; } 180 checkPermission(new SocketPermission (host, "accept,connect")); } 182 } 183 184 187 public void checkMulticast(InetAddress maddr) { 188 if (fSecurityManager != null) { 189 fSecurityManager.checkMulticast(maddr); 190 } 191 } 192 193 196 public void checkPackageAccess(String pkg) { 197 if (fSecurityManager != null) { 198 fSecurityManager.checkPackageAccess(pkg); 199 } 200 } 201 202 205 public void checkPackageDefinition(String pkg) { 206 if (fSecurityManager != null) { 207 fSecurityManager.checkPackageDefinition(pkg); 208 } 209 } 210 211 214 public void checkPermission(Permission perm, Object context) { 215 if (fSecurityManager != null) { 216 fSecurityManager.checkPermission(perm, context); 217 } 218 } 219 220 223 public void checkPermission(Permission perm) { 224 if (!fAllowSettingSystemProperties && fgPropertyPermission.implies(perm) && fRestrictedThread == Thread.currentThread()) { 225 throw new AntSecurityException(); 227 } 228 if (fSecurityManager != null) { 229 fSecurityManager.checkPermission(perm); 230 } 231 } 232 233 236 public void checkPrintJobAccess() { 237 if (fSecurityManager != null) { 238 fSecurityManager.checkPrintJobAccess(); 239 } 240 } 241 242 245 public void checkPropertiesAccess() { 246 if (fSecurityManager != null) { 247 fSecurityManager.checkPropertiesAccess(); 248 } 249 super.checkPropertiesAccess(); 250 } 251 252 255 public void checkPropertyAccess(String key) { 256 if (fSecurityManager != null) { 257 fSecurityManager.checkPropertyAccess(key); 258 } 259 } 260 261 264 public void checkRead(FileDescriptor fd) { 265 if (fSecurityManager != null) { 266 fSecurityManager.checkRead(fd); 267 } 268 } 269 270 273 public void checkRead(String file, Object context) { 274 if (fSecurityManager != null) { 275 fSecurityManager.checkRead(file, context); 276 } 277 } 278 279 282 public void checkRead(String file) { 283 if (fSecurityManager != null) { 284 fSecurityManager.checkRead(file); 285 } 286 } 287 288 291 public void checkSecurityAccess(String target) { 292 if (fSecurityManager != null) { 293 fSecurityManager.checkSecurityAccess(target); 294 } 295 } 296 297 300 public void checkSetFactory() { 301 if (fSecurityManager != null) { 302 fSecurityManager.checkSetFactory(); 303 } 304 } 305 306 309 public void checkSystemClipboardAccess() { 310 if (fSecurityManager != null) { 311 fSecurityManager.checkSystemClipboardAccess(); 312 } 313 } 314 315 318 public boolean checkTopLevelWindow(Object window) { 319 if (fSecurityManager != null) { 320 return fSecurityManager.checkTopLevelWindow(window); 321 } 322 return super.checkTopLevelWindow(window); 323 } 324 325 328 public void checkWrite(FileDescriptor fd) { 329 if (fSecurityManager != null) { 330 fSecurityManager.checkWrite(fd); 331 } 332 } 333 334 337 public void checkWrite(String file) { 338 if (fSecurityManager != null) { 339 fSecurityManager.checkWrite(file); 340 } 341 } 342 343 347 public boolean getInCheck() { 348 if (fSecurityManager != null) { 349 return fSecurityManager.getInCheck(); 350 } 351 return super.getInCheck(); 352 } 353 354 357 public Object getSecurityContext() { 358 if (fSecurityManager != null) { 359 return fSecurityManager.getSecurityContext(); 360 } 361 return super.getSecurityContext(); 362 } 363 364 367 public ThreadGroup getThreadGroup() { 368 if (fSecurityManager != null) { 369 fSecurityManager.getThreadGroup(); 370 } 371 return super.getThreadGroup(); 372 } 373 } 374 | Popular Tags |