FileDocCategorySizeDatePackage
WebModuleContextConfig.javaAPI DocGlassfish v2 API15716Fri May 04 22:36:02 BST 2007com.sun.enterprise.web

WebModuleContextConfig

public class WebModuleContextConfig extends org.apache.catalina.startup.ContextConfig
Startup event listener for a Context that configures the properties of that Context, and the associated defined servlets.
author
Jean-Francois Arcand

Fields Summary
private static final Logger
logger
protected static final ResourceBundle
_rb
public static final int
CHILDREN
public static final int
SERVLET_MAPPINGS
public static final int
LOCAL_EJBS
public static final int
EJBS
public static final int
ENVIRONMENTS
public static final int
ERROR_PAGES
public static final int
FILTER_DEFS
public static final int
FILTER_MAPS
public static final int
APPLICATION_LISTENERS
public static final int
RESOURCES
public static final int
APPLICATION_PARAMETERS
public static final int
MESSAGE_DESTINATIONS
public static final int
MESSAGE_DESTINATION_REFS
public static final int
MIME_MAPPINGS
protected File
file
The File reffering to the default-web.xml
private com.sun.enterprise.deployment.WebBundleDescriptor
webBundleDescriptor
The DOL object representing the web.xml content.
Constructors Summary
public WebModuleContextConfig()
Customized ContextConfig which use the DOL for deployment.

   

    
                 
     
    
Methods Summary
protected synchronized voidauthenticatorConfig()
Always sets up an Authenticator regardless of any security constraints.

        
        LoginConfig loginConfig = context.getLoginConfig();
        if (loginConfig == null) {
            loginConfig = new LoginConfig("NONE", null, null, null);
            context.setLoginConfig(loginConfig);
        }

        // Has an authenticator been configured already?
        if (context instanceof Authenticator)
            return;
        if (context instanceof ContainerBase) {
            Pipeline pipeline = ((ContainerBase) context).getPipeline();
            if (pipeline != null) {
                Valve basic = pipeline.getBasic();
                if ((basic != null) && (basic instanceof Authenticator))
                    return;
                Valve valves[] = pipeline.getValves();
                for (int i = 0; i < valves.length; i++) {
                    if (valves[i] instanceof Authenticator)
                        return;
                }
            }
        } else {
            return;     // Cannot install a Valve even if it would be needed
        }

        // Has a Realm been configured for us to authenticate against?
        /* START IASRI 4856062
        if (context.getRealm() == null) {
        */
        // BEGIN IASRI 4856062
        Realm rlm = context.getRealm();
        if (rlm == null) {
        // END IASRI 4856062
            logger.log(Level.SEVERE, "webModuleContextConfig.missingRealm");
            ok = false;
            return;
        }

        // BEGIN IASRI 4856062
        // If a realm is available set its name in the Realm(Adapter)
        rlm.setRealmName(loginConfig.getRealmName(),
                         loginConfig.getAuthMethod());

        // END IASRI 4856062

        /*
         * First check to see if there is a custom mapping for the login
         * method. If so, use it. Otherwise, check if there is a mapping in
         * org/apache/catalina/startup/Authenticators.properties.
         */
        Valve authenticator = null;
        if (customAuthenticators != null) {
            authenticator = (Valve)
                customAuthenticators.get(loginConfig.getAuthMethod());
        }
        if (authenticator == null) {
            // Load our mapping properties if necessary
            if (authenticators == null) {
                try {
                    InputStream is=this.getClass().getClassLoader().getResourceAsStream("org/apache/catalina/startup/Authenticators.properties");
                    if( is!=null ) {
                        authenticators = new Properties();
                        authenticators.load(is);
                    } else {
                        logger.log(Level.SEVERE, "webModuleContextConfig.authenticatorResources");
                        ok=false;
                        return;
                    }
                } catch (IOException e) {
                    logger.log(Level.SEVERE, "webModuleContextConfig.authenticatorResources", e);
                    ok = false;
                    return;
                }
            }

            // Identify the class name of the Valve we should configure
            String authenticatorName = null;

            // BEGIN RIMOD 4808402
            // If login-config is given but auth-method is null, use NONE
            // so that NonLoginAuthenticator is picked
            String authMethod = loginConfig.getAuthMethod();
            if (authMethod == null) {
                authMethod = "NONE";
            }
            authenticatorName = authenticators.getProperty(authMethod);
            // END RIMOD 4808402
            /* RIMOD 4808402
            authenticatorName =
                    authenticators.getProperty(loginConfig.getAuthMethod());
            */

            if (authenticatorName == null) {
                logger.log(Level.SEVERE, "webModuleContextConfig.authenticatorMissing",
                           loginConfig.getAuthMethod());
                ok = false;
                return;
            }

            // Instantiate and install an Authenticator of the requested class
            try {
                Class authenticatorClass = Class.forName(authenticatorName);
                authenticator = (Valve) authenticatorClass.newInstance();
            } catch (Throwable t) {
                logger.log(Level.SEVERE, "webModuleContextConfig.authenticatorInstantiate", authenticatorName);
                logger.log(Level.SEVERE, "webModuleContextConfig.authenticatorInstantiate", t);
                ok = false;
            }
        }

        if (authenticator != null && context instanceof ContainerBase) {
            Pipeline pipeline = ((ContainerBase) context).getPipeline();
            if (pipeline != null) {
                ((ContainerBase) context).addValve(authenticator);
                if (logger.isLoggable(Level.FINEST)) {
                    logger.log(Level.FINEST, "webModuleContextConfig.authenticatorConfigured",
                               loginConfig.getAuthMethod());
                }
            }
        }
    
protected synchronized voidconfigureResource()

        
        try {
            ApplicationParameter[] appParams = 
                    context.findApplicationParameters();
            ContextParameter contextParam;
            for (int i=0; i<appParams.length; i++) {
                contextParam = new EnvironmentProperty(appParams[i].getName(),
                    appParams[i].getValue(), appParams[i].getDescription());
                webBundleDescriptor.addContextParameter(contextParam);
            }

            ContextEnvironment[] envs = context.findEnvironments();
            EnvironmentProperty envEntry;
            for (int i=0; i<envs.length; i++) {
                envEntry = new EnvironmentProperty(
                        envs[i].getName(), envs[i].getValue(),
                        envs[i].getDescription(), envs[i].getType()); 
                if (envs[i].getValue()!=null) {
                    envEntry.setValue(envs[i].getValue());
                }
                webBundleDescriptor.addEnvironmentProperty(envEntry);
            }

            ContextResource[] resources = context.findResources();
            ResourceReferenceDescriptor resourceReference;
            SunWebApp iasBean = webBundleDescriptor.getSunDescriptor();
            ResourceRef[] rr = iasBean.getResourceRef();
            DefaultResourcePrincipal drp;
            ResourcePrincipal rp;
            
            for (int i=0; i<resources.length; i++) {
                resourceReference = new ResourceReferenceDescriptor(
                        resources[i].getName(), resources[i].getDescription(),
                        resources[i].getType());
                resourceReference.setJndiName(resources[i].getName());
                if (rr!=null) {
                    for (int j=0; j<rr.length; j++) {
                        if (resources[i].getName().equals(rr[j].getResRefName())) {
                            resourceReference.setJndiName(rr[i].getJndiName());
                            drp = rr[i].getDefaultResourcePrincipal();
                            if (drp!=null) {
                                rp = new ResourcePrincipal(drp.getName(), drp.getPassword());
                                resourceReference.setResourcePrincipal(rp);
                            }
                        }
                    }
                }
                resourceReference.setAuthorization(resources[i].getAuth());
                webBundleDescriptor.addResourceReference(resourceReference);
            }
        
            Switch sw = Switch.getSwitch();
            sw.getNamingManager().bindObjects(webBundleDescriptor);
            sw.setDescriptorFor(context, webBundleDescriptor);
            
        } catch (Exception exception) { 
            context.setAvailable(false);
            String msg = _rb.getString("webcontainer.webModuleDisabled");
            msg = MessageFormat.format(msg,
                                       new Object[] { context.getName() });
            logger.log(Level.SEVERE, msg, exception);
        }
    
    
protected voiddefaultConfig()
Process the default configuration file, if it exists. The default config must be read with the container loader - so container servlets can be loaded

        ;
    
public voidlifecycleEvent(org.apache.catalina.LifecycleEvent event)
Process the START event for an associated Context.

param
event The lifecycle event that has occurred


        // Identify the context we are associated with
        try {
            context = (Context) event.getLifecycle();
        } catch (ClassCastException e) {
            return;
        }

        // Called from ContainerBase.addChild() -> StandardContext.start()
        // Process the event that has occurred
        if (event.getType().equals(Lifecycle.START_EVENT)) 
            start();
        else if (event.getType().equals(Lifecycle.STOP_EVENT))
            stop();
        else if (event.getType().equals(Lifecycle.INIT_EVENT)) {
            super.init();
            configureResource();
        }

    
public voidsetDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor wbd)
Set the DOL object associated with this class.

        webBundleDescriptor = wbd;
    
protected synchronized voidstart()
Process a "start" event for this Context - in background

        
        try{
            TomcatDeploymentConfig.configureWebModule((WebModule)context,
                                                      webBundleDescriptor);
        } catch (Throwable t){
            context.setAvailable(false);
            Object[] objs = {context.getName(), t};
            logger.log(Level.SEVERE, 
                       "webModuleContextConfig.webModuleDisabled", objs);
        }

        context.setConfigured(false);
        ok = true;

        authenticatorConfig();
        if (ok) {
            managerConfig();
        }
        
        if (ok) {
            context.setConfigured(true);
        } else {
            context.setConfigured(false);
            logger.log(Level.SEVERE,
                       "webModuleContextConfig.webModuleDisabledNoException",
                       new Object[] { context.getName() });
        }