FileDocCategorySizeDatePackage
WebSecurityManagerFactory.javaAPI DocGlassfish v2 API5495Fri May 04 22:36:20 BST 2007com.sun.web.security

WebSecurityManagerFactory

public class WebSecurityManagerFactory extends Object
author
JeanFrancois Arcand
author
Harpreet Singh

Fields Summary
private static Logger
logger
private Map
securityManagerPool
private Map
CONTEXT_ID
private static WebSecurityManagerFactory
factory
Constructors Summary
private WebSecurityManagerFactory()

        
      
    
Methods Summary
public java.lang.String[]getAndRemoveContextIdForWebAppName(java.lang.String appName)
valid for standalone web apps

	synchronized(CONTEXT_ID) {
	    String [] rvalue = getContextIdsOfApp(appName);
	    CONTEXT_ID.remove(appName);
	    return rvalue;
	}
    
public java.lang.String[]getContextIdsOfApp(java.lang.String appName)
valid for standalone web apps

	synchronized(CONTEXT_ID) {
	    List contextId = (List) CONTEXT_ID.get(appName);
	    if(contextId == null)
		return null;
	    String[] arrayContext = new String[contextId.size()];
	    arrayContext = (String[])contextId.toArray(arrayContext);
	    return arrayContext;
	}
    
public static synchronized com.sun.web.security.WebSecurityManagerFactorygetInstance()

        if (factory == null){
	    factory = new WebSecurityManagerFactory();
        }   
        return  factory;
    
public WebSecurityManagergetWebSecurityManager(java.lang.String contextId)

	synchronized (securityManagerPool) {
	    return (WebSecurityManager)securityManagerPool.get(contextId);
	}
    
public WebSecurityManagernewWebSecurityManager(com.sun.enterprise.deployment.WebBundleDescriptor wbd)

        String contextId = WebSecurityManager.getContextID(wbd);
        String appname = wbd.getApplication().getRegistrationName();

	synchronized (CONTEXT_ID) {
	    List lst = (List)CONTEXT_ID.get(appname);
	    if(lst == null){
		lst = new ArrayList();
		CONTEXT_ID.put(appname, lst);
	    }
	    if (!lst.contains(contextId)) {
		lst.add(contextId);
	    }
	}

        if(logger.isLoggable(Level.FINE)){
            logger.log(Level.FINE, "[Web-Security] Web Security:Creating WebSecurityManager for contextId = "+contextId);
        }

        WebSecurityManager wsManager = getWebSecurityManager(contextId);
	if (wsManager == null) {

	    // we should see if it is safe to do the security manager 
	    // construction within the synchronize block.
	    // for the time being, we will just make sure that we 
	    // synchronize access to the pool.
	    try{
		wsManager = new WebSecurityManager(wbd);
	    } catch (javax.security.jacc.PolicyContextException e){
		logger.log(Level.FINE, "[Web-Security] FATAl Exception. Unable to create WebSecurityManager: " + e.getMessage() );
		throw new RuntimeException(e);
	    }

	    synchronized (securityManagerPool) {
		WebSecurityManager other = 
		    (WebSecurityManager)securityManagerPool.get(contextId);
		if (other == null) {
		    securityManagerPool.put(contextId, wsManager);
		} else {
		    wsManager = other;
		}
	    }
	}
	return wsManager;
    
public voidremoveWebSecurityManager(java.lang.String contextId)

        synchronized (securityManagerPool){
	    securityManagerPool.remove(contextId);
        }