1 23 24 package com.sun.web.security; 25 26 import java.util.HashMap ; 27 import java.util.Map ; 28 import com.sun.enterprise.deployment.WebBundleDescriptor; 29 import java.util.logging.*; 30 import com.sun.logging.LogDomains; 31 import java.util.List ; 32 import java.util.ArrayList ; 33 34 37 public class WebSecurityManagerFactory { 38 private static Logger logger = 39 Logger.getLogger(LogDomains.SECURITY_LOGGER); 40 41 private Map securityManagerPool = new HashMap (); 42 private Map CONTEXT_ID = new HashMap (); 44 private static WebSecurityManagerFactory factory = null; 45 46 private WebSecurityManagerFactory() { 47 } 48 public static synchronized WebSecurityManagerFactory getInstance(){ 50 if (factory == null){ 51 factory = new WebSecurityManagerFactory(); 52 } 53 return factory; 54 } 55 public WebSecurityManager newWebSecurityManager(WebBundleDescriptor wbd){ 57 String contextId = WebSecurityManager.getContextID(wbd); 58 String appname = wbd.getApplication().getRegistrationName(); 59 60 synchronized (CONTEXT_ID) { 61 List lst = (List )CONTEXT_ID.get(appname); 62 if(lst == null){ 63 lst = new ArrayList (); 64 CONTEXT_ID.put(appname, lst); 65 } 66 if (!lst.contains(contextId)) { 67 lst.add(contextId); 68 } 69 } 70 71 if(logger.isLoggable(Level.FINE)){ 72 logger.log(Level.FINE, "[Web-Security] Web Security:Creating WebSecurityManager for contextId = "+contextId); 73 } 74 75 WebSecurityManager wsManager = getWebSecurityManager(contextId); 76 if (wsManager == null) { 77 78 try{ 83 wsManager = new WebSecurityManager(wbd); 84 } catch (javax.security.jacc.PolicyContextException e){ 85 logger.log(Level.FINE, "[Web-Security] FATAl Exception. Unable to create WebSecurityManager: " + e.getMessage() ); 86 throw new RuntimeException (e); 87 } 88 89 synchronized (securityManagerPool) { 90 WebSecurityManager other = 91 (WebSecurityManager)securityManagerPool.get(contextId); 92 if (other == null) { 93 securityManagerPool.put(contextId, wsManager); 94 } else { 95 wsManager = other; 96 } 97 } 98 } 99 return wsManager; 100 } 101 102 public WebSecurityManager getWebSecurityManager(String contextId){ 103 synchronized (securityManagerPool) { 104 return (WebSecurityManager)securityManagerPool.get(contextId); 105 } 106 } 107 108 public void removeWebSecurityManager(String contextId){ 109 synchronized (securityManagerPool){ 110 securityManagerPool.remove(contextId); 111 } 112 } 113 114 117 public String [] getContextIdsOfApp(String appName){ 118 synchronized(CONTEXT_ID) { 119 List contextId = (List ) CONTEXT_ID.get(appName); 120 if(contextId == null) 121 return null; 122 String [] arrayContext = new String [contextId.size()]; 123 arrayContext = (String [])contextId.toArray(arrayContext); 124 return arrayContext; 125 } 126 } 127 128 131 public String [] getAndRemoveContextIdForWebAppName(String appName){ 132 synchronized(CONTEXT_ID) { 133 String [] rvalue = getContextIdsOfApp(appName); 134 CONTEXT_ID.remove(appName); 135 return rvalue; 136 } 137 } 138 139 } 140 | Popular Tags |