1 23 package com.sun.enterprise; 24 25 import java.net.SocketPermission ; 26 import java.util.PropertyPermission ; 27 import com.sun.enterprise.security.CachedPermissionImpl; 28 import com.sun.enterprise.security.PermissionCache; 29 import com.sun.enterprise.security.PermissionCacheFactory; 30 31 import java.util.*; 32 import java.util.logging.*; 34 import com.sun.logging.*; 35 37 41 public class J2EESecurityManager extends java.rmi.RMISecurityManager { 42 43 private static Logger _logger=null; 45 static{ 46 _logger=LogDomains.getLogger(LogDomains.ROOT_LOGGER); 47 } 48 50 private CachedPermissionImpl connectPerm; 51 52 private PermissionCache cache; 53 54 private boolean cacheEnabled = false; 55 56 public J2EESecurityManager() { 57 } 58 59 87 88 public void checkAccess(ThreadGroup t) { 89 super.checkAccess(t); 90 checkPermission(new java.lang.RuntimePermission ("modifyThreadGroup")); 91 } 92 93 public void checkPackageAccess(final String pkgname) { 94 if(!pkgname.startsWith("sun.")) 96 super.checkPackageAccess(pkgname); 97 } 98 99 public void checkExit(int status) { 100 super.checkExit(status); 102 } 103 104 public void checkConnect(String host, int port) { 105 if (checkConnectPermission()) { 106 return; 107 } 108 super.checkConnect(host, port); 109 } 110 111 public void checkConnect(String host, int port, Object context) { 112 if (checkConnectPermission()) { 113 return; 114 } 115 super.checkConnect(host, port, context); 116 } 117 118 public void checkPropertyAccess(String key) { 119 if (checkProperty(key)) { 120 return; 121 } 122 super.checkPropertyAccess(key); 123 } 124 125 private boolean checkConnectPermission() { 126 if (cacheEnabled()) { 127 return connectPerm.checkPermission(); 128 } 129 return false; 130 } 131 132 private boolean checkProperty(String key) { 133 if (cacheEnabled()) { 134 return cache.checkPermission(new PropertyPermission (key, "read")); 135 } 136 return false; 137 } 138 139 public synchronized boolean cacheEnabled() { 140 return cacheEnabled; 141 } 142 143 public synchronized void enablePermissionCache(PermissionCache c) { 144 if (c != null) { 145 cache = c; 146 connectPerm = new CachedPermissionImpl 147 (cache, new SocketPermission ("*","connect")); 148 cacheEnabled = true; 149 } 150 } 151 152 } 153 154 155 156 157 158 | Popular Tags |