1 23 24 package javax.security.jacc; 25 26 import java.util.Hashtable ; 27 28 import java.util.Set ; 29 30 import java.security.SecurityPermission ; 31 32 import javax.security.jacc.PolicyContextHandler ; 33 34 89 90 public final class PolicyContext { 91 92 private PolicyContext() { 93 } 94 95 98 99 private static ThreadLocal thisContextID = new ThreadLocal (); 100 101 104 105 private static ThreadLocal thisHandlerData = new ThreadLocal (); 106 107 111 112 private static Hashtable handlerTable = new Hashtable (); 113 114 127 128 public static void setContextID(String contextID) 129 { 130 java.lang.SecurityManager sm = System.getSecurityManager(); 131 if (sm != null) 132 sm.checkPermission(new SecurityPermission ("setPolicy")); 133 134 thisContextID.set(contextID); 135 } 136 137 152 153 public static String getContextID() 154 { 155 return (String ) thisContextID.get(); 156 } 157 158 175 176 public static void setHandlerData(Object data) 177 { 178 179 java.lang.SecurityManager sm = System.getSecurityManager(); 180 if (sm != null) 181 sm.checkPermission(new SecurityPermission ("setPolicy")); 182 183 thisHandlerData.set(data); 184 } 185 186 219 220 public static void 221 registerHandler(String key, PolicyContextHandler handler, boolean replace) 222 throws javax.security.jacc.PolicyContextException 223 { 224 if (handler == null || key == null) 225 throw new 226 IllegalArgumentException ("invalid (null) key or handler"); 227 if (!handler.supports(key)) 228 throw new IllegalArgumentException ("handler does not support key"); 229 java.lang.SecurityManager sm = System.getSecurityManager(); 230 if (sm != null) 231 sm.checkPermission(new SecurityPermission ("setPolicy")); 232 233 if (handlerTable.containsKey(key) && replace == false) 234 throw new IllegalArgumentException ("handler exists"); 235 handlerTable.put(key,handler); 236 } 237 238 251 252 public static Set getHandlerKeys() 253 { 254 return handlerTable.keySet(); 255 } 256 257 287 288 public static Object getContext(String key) 289 throws javax.security.jacc.PolicyContextException 290 { 291 if (key == null) 292 throw new IllegalArgumentException ("invalid key"); 293 PolicyContextHandler handler = 294 (PolicyContextHandler ) handlerTable.get(key); 295 if (handler == null || !handler.supports(key)) 296 throw new IllegalArgumentException ("unknown handler key"); 297 298 java.lang.SecurityManager sm = System.getSecurityManager(); 299 if (sm != null) 300 sm.checkPermission(new SecurityPermission ("setPolicy")); 301 302 return handler.getContext(key,thisHandlerData.get()); 303 } 304 305 } 306 307 308 309 310 311 | Popular Tags |