Search in sources :

Example 6 with Pipeline

use of org.apache.catalina.Pipeline in project Payara by payara.

the class AuthenticatorBase method start.

// ------------------------------------------------------ Lifecycle Methods
/**
 * Add a lifecycle event listener to this component.
 *
 * @param listener The listener to add
 */
/**
 * CR 6411114 (Lifecycle implementation moved to ValveBase) public void addLifecycleListener(LifecycleListener listener)
 * {
 *
 * lifecycle.addLifecycleListener(listener);
 *
 * }
 */
/**
 * Get the lifecycle listeners associated with this lifecycle. If this Lifecycle has no listeners registered, a
 * zero-length array is returned.
 */
/**
 * CR 6411114 (Lifecycle implementation moved to ValveBase) public LifecycleListener[] findLifecycleListeners() {
 *
 * return lifecycle.findLifecycleListeners();
 *
 * }
 */
/**
 * Remove a lifecycle event listener from this component.
 *
 * @param listener The listener to remove
 */
/**
 * CR 6411114 (Lifecycle implementation moved to ValveBase) public void removeLifecycleListener(LifecycleListener
 * listener) {
 *
 * lifecycle.removeLifecycleListener(listener);
 *
 * }
 */
/**
 * Prepare for the beginning of active use of the public methods of this component. This method should be called after
 * <code>configure()</code>, and before any of the public methods of the component are utilized.
 *
 * @exception LifecycleException if this component detects a fatal error that prevents this component from being used
 */
@Override
public void start() throws LifecycleException {
    // START CR 6411114
    if (// Ignore multiple starts
    started)
        return;
    super.start();
    // END CR 6411114
    if (context instanceof org.apache.catalina.core.StandardContext) {
        try {
            // XXX What is this ???
            Class[] paramTypes = new Class[0];
            Object[] paramValues = new Object[0];
            Method method = context.getClass().getMethod("getDebug", paramTypes);
            Integer result = (Integer) method.invoke(context, paramValues);
            setDebug(result);
        } catch (Exception e) {
            log.log(Level.SEVERE, LogFacade.GETTING_DEBUG_VALUE_EXCEPTION, e);
        }
    }
    /**
     * CR 6411114 (Lifecycle implementation moved to ValveBase) started = true;
     */
    // Look up the SingleSignOn implementation in our request processing
    // path, if there is one
    Container parent = context.getParent();
    while ((sso == null) && (parent != null)) {
        if (!(parent instanceof Pipeline)) {
            parent = parent.getParent();
            continue;
        }
        GlassFishValve[] valves = ((Pipeline) parent).getValves();
        for (GlassFishValve valve : valves) {
            if (valve instanceof SingleSignOn) {
                sso = (SingleSignOn) valve;
                break;
            }
        }
        if (sso == null)
            parent = parent.getParent();
    }
    if (log.isLoggable(Level.FINE)) {
        if (sso != null)
            log.log(Level.FINE, "Found SingleSignOn Valve at " + sso);
        else
            log.log(Level.FINE, "No SingleSignOn Valve is present");
    }
}
Also used : Method(java.lang.reflect.Method) ServletException(javax.servlet.ServletException) LifecycleException(org.apache.catalina.LifecycleException) IOException(java.io.IOException) Pipeline(org.apache.catalina.Pipeline) GlassFishValve(org.glassfish.web.valve.GlassFishValve) Container(org.apache.catalina.Container)

Example 7 with Pipeline

use of org.apache.catalina.Pipeline in project tomcat70 by apache.

the class StandardContext method getAuthenticator.

@Override
public Authenticator getAuthenticator() {
    if (this instanceof Authenticator)
        return (Authenticator) this;
    Pipeline pipeline = getPipeline();
    if (pipeline != null) {
        Valve basic = pipeline.getBasic();
        if ((basic != null) && (basic instanceof Authenticator))
            return (Authenticator) basic;
        Valve[] valves = pipeline.getValves();
        for (int i = 0; i < valves.length; i++) {
            if (valves[i] instanceof Authenticator)
                return (Authenticator) valves[i];
        }
    }
    return null;
}
Also used : Valve(org.apache.catalina.Valve) Authenticator(org.apache.catalina.Authenticator) SecurityConstraint(org.apache.catalina.deploy.SecurityConstraint) Pipeline(org.apache.catalina.Pipeline)

Example 8 with Pipeline

use of org.apache.catalina.Pipeline in project tomcat70 by apache.

the class ContextConfig method authenticatorConfig.

/**
 * Set up an Authenticator automatically if required, and one has not
 * already been configured.
 */
protected void authenticatorConfig() {
    LoginConfig loginConfig = context.getLoginConfig();
    if (loginConfig == null) {
        // Need an authenticator to support HttpServletRequest.login()
        loginConfig = DUMMY_LOGIN_CONFIG;
        context.setLoginConfig(loginConfig);
    }
    // Has an authenticator been configured already?
    if (context.getAuthenticator() != null)
        return;
    if (!(context instanceof ContainerBase)) {
        // Cannot install a Valve even if it would be needed
        return;
    }
    // Has a Realm been configured for us to authenticate against?
    if (context.getRealm() == null) {
        log.error(sm.getString("contextConfig.missingRealm"));
        ok = false;
        return;
    }
    /*
         * 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) {
        if (authenticators == null) {
            log.error(sm.getString("contextConfig.authenticatorResources"));
            ok = false;
            return;
        }
        // Identify the class name of the Valve we should configure
        String authenticatorName = null;
        authenticatorName = authenticators.getProperty(loginConfig.getAuthMethod());
        if (authenticatorName == null) {
            log.error(sm.getString("contextConfig.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) {
            ExceptionUtils.handleThrowable(t);
            log.error(sm.getString("contextConfig.authenticatorInstantiate", authenticatorName), t);
            ok = false;
        }
    }
    if (authenticator != null && context instanceof ContainerBase) {
        Pipeline pipeline = ((ContainerBase) context).getPipeline();
        if (pipeline != null) {
            ((ContainerBase) context).getPipeline().addValve(authenticator);
            if (log.isDebugEnabled()) {
                log.debug(sm.getString("contextConfig.authenticatorConfigured", loginConfig.getAuthMethod()));
            }
        }
    }
}
Also used : ContainerBase(org.apache.catalina.core.ContainerBase) LoginConfig(org.apache.catalina.deploy.LoginConfig) Valve(org.apache.catalina.Valve) Pipeline(org.apache.catalina.Pipeline)

Example 9 with Pipeline

use of org.apache.catalina.Pipeline in project tomcat70 by apache.

the class ContextConfig method configureStart.

/**
 * Process a "contextConfig" event for this Context.
 */
protected synchronized void configureStart() {
    if (log.isDebugEnabled())
        log.debug(sm.getString("contextConfig.start"));
    if (log.isDebugEnabled()) {
        log.debug(sm.getString("contextConfig.xmlSettings", context.getName(), Boolean.valueOf(context.getXmlValidation()), Boolean.valueOf(context.getXmlNamespaceAware())));
    }
    webConfig();
    if (!context.getIgnoreAnnotations()) {
        applicationAnnotationsConfig();
    }
    if (ok) {
        validateSecurityRoles();
    }
    // Configure an authenticator if we need one
    if (ok)
        authenticatorConfig();
    // Dump the contents of this pipeline if requested
    if ((log.isDebugEnabled()) && (context instanceof ContainerBase)) {
        log.debug("Pipeline Configuration:");
        Pipeline pipeline = ((ContainerBase) context).getPipeline();
        Valve[] valves = null;
        if (pipeline != null)
            valves = pipeline.getValves();
        if (valves != null) {
            for (int i = 0; i < valves.length; i++) {
                log.debug("  " + valves[i].getInfo());
            }
        }
        log.debug("======================");
    }
    // Make our application available if no problems were encountered
    if (ok)
        context.setConfigured(true);
    else {
        log.error(sm.getString("contextConfig.unavailable"));
        context.setConfigured(false);
    }
}
Also used : ContainerBase(org.apache.catalina.core.ContainerBase) Valve(org.apache.catalina.Valve) SecurityConstraint(org.apache.catalina.deploy.SecurityConstraint) Pipeline(org.apache.catalina.Pipeline)

Example 10 with Pipeline

use of org.apache.catalina.Pipeline in project tomee by apache.

the class TomcatWebAppBuilder method afterStart.

/**
 * {@inheritDoc}
 */
@Override
public void afterStart(final StandardContext standardContext) {
    if (isIgnored(standardContext)) {
        return;
    }
    if (shouldNotDeploy(standardContext)) {
        return;
    }
    final Realm realm = standardContext.getRealm();
    final ClassLoader classLoader = standardContext.getLoader().getClassLoader();
    final Thread thread = Thread.currentThread();
    final ClassLoader originalLoader = thread.getContextClassLoader();
    if (realm != null && !(realm instanceof TomEERealm) && (standardContext.getParent() == null || (!realm.equals(standardContext.getParent().getRealm())))) {
        thread.setContextClassLoader(classLoader);
        try {
            standardContext.setRealm(tomeeRealm(realm));
        } finally {
            thread.setContextClassLoader(originalLoader);
        }
    }
    // if appInfo is null this is a failed deployment... just ignore
    final ContextInfo contextInfo = getContextInfo(standardContext);
    // shouldnt be there after startup (actually we shouldnt need it from info tree but our scanning does)
    contextInfo.module = null;
    if (contextInfo != null && contextInfo.appInfo == null) {
        return;
    } else if (contextInfo == null) {
        // openejb webapp loaded from the LoaderServlet
        return;
    }
    final String id = getId(standardContext);
    WebAppInfo currentWebAppInfo = null;
    for (final WebAppInfo webAppInfo : contextInfo.appInfo.webApps) {
        final String wId = getId(webAppInfo.host, webAppInfo.contextRoot, contextInfo.version);
        if (id.equals(wId)) {
            currentWebAppInfo = webAppInfo;
            break;
        }
    }
    // bind extra stuff at the java:comp level which can only be
    // bound after the context is created
    thread.setContextClassLoader(classLoader);
    final NamingContextListener ncl = standardContext.getNamingContextListener();
    final String listenerName = ncl.getName();
    ContextAccessController.setWritable(listenerName, standardContext.getNamingToken());
    try {
        final Context openejbContext = (Context) getContainerSystem().getJNDIContext().lookup("openejb");
        final Context root = (Context) ContextBindings.getClassLoader().lookup("");
        // usually fails
        final Context comp = (Context) ContextBindings.getClassLoader().lookup("comp");
        // Context root = ncl.getNamingContext();
        // Context comp = (Context) root.lookup("comp");
        safeBind(root, "openejb", openejbContext);
        // add context to WebDeploymentInfo
        if (currentWebAppInfo != null) {
            final WebContext webContext = getContainerSystem().getWebContext(currentWebAppInfo.moduleId);
            if (webContext != null) {
                webContext.setJndiEnc(root);
            }
            try {
                // Bean Validation
                standardContext.getServletContext().setAttribute("javax.faces.validator.beanValidator.ValidatorFactory", openejbContext.lookup(Assembler.VALIDATOR_FACTORY_NAMING_CONTEXT.replaceFirst("openejb", "") + currentWebAppInfo.uniqueId));
            } catch (final NamingException ne) {
                LOGGER.warning("no validator factory found for webapp " + currentWebAppInfo.moduleId);
            }
        }
        try {
            final Class<?> orb = TomcatWebAppBuilder.class.getClassLoader().loadClass("org.omg.CORBA.ORB");
            if (SystemInstance.get().getComponent(orb) != null) {
                safeBind(comp, "ORB", new SystemComponentReference(orb));
            }
        } catch (final NoClassDefFoundError | ClassNotFoundException cnfe) {
        // no-op
        }
        if (SystemInstance.get().getComponent(HandleDelegate.class) != null) {
            safeBind(comp, "HandleDelegate", new SystemComponentReference(HandleDelegate.class));
        }
    } catch (final NamingException e) {
    // no-op
    } finally {
        // see also the start method getContainerSystem().addWebDeployment(webContext);
        try {
            servletContextHandler.getContexts().put(classLoader, standardContext.getServletContext());
            for (final WebAppInfo webAppInfo : contextInfo.appInfo.webApps) {
                final String wId = getId(webAppInfo.host, webAppInfo.contextRoot, contextInfo.version);
                if (id.equals(wId)) {
                    // Allow any post-deployment to happen without the RequestContext of a call to /tomee/ejb
                    final Request request = OpenEJBSecurityListener.requests.get();
                    OpenEJBSecurityListener.requests.remove();
                    SystemInstance.get().fireEvent(new AfterApplicationCreated(contextInfo.appInfo, webAppInfo, standardContext.getServletContext()));
                    if (request != null) {
                        OpenEJBSecurityListener.requests.set(request);
                    }
                    break;
                }
            }
        } finally {
            servletContextHandler.getContexts().remove(classLoader);
        }
        thread.setContextClassLoader(originalLoader);
        ContextAccessController.setReadOnly(listenerName);
    }
    thread.setContextClassLoader(classLoader);
    try {
        // owb integration filters
        final WebBeansContext webBeansContext = getWebBeansContext(contextInfo);
        if (webBeansContext != null) {
            // it is important to have a begin and a end listener
            // to be sure to create contexts before other listeners
            // and destroy contexts after other listeners
            final BeginWebBeansListener beginWebBeansListener = new BeginWebBeansListener(webBeansContext);
            final EndWebBeansListener endWebBeansListener = new EndWebBeansListener(webBeansContext);
            {
                final Object[] appEventListeners = standardContext.getApplicationEventListeners();
                final Object[] newEventListeners = new Object[appEventListeners.length + 2];
                newEventListeners[0] = beginWebBeansListener;
                System.arraycopy(appEventListeners, 0, newEventListeners, 1, appEventListeners.length);
                newEventListeners[newEventListeners.length - 1] = endWebBeansListener;
                standardContext.setApplicationEventListeners(newEventListeners);
            }
            {
                final Object[] lifecycleListeners = standardContext.getApplicationLifecycleListeners();
                final Object[] newLifecycleListeners = new Object[lifecycleListeners.length + 2];
                newLifecycleListeners[0] = beginWebBeansListener;
                System.arraycopy(lifecycleListeners, 0, newLifecycleListeners, 1, lifecycleListeners.length);
                newLifecycleListeners[newLifecycleListeners.length - 1] = endWebBeansListener;
                standardContext.setApplicationLifecycleListeners(newLifecycleListeners);
            }
            // also add the ThreadBindingListener to clean up async thread executions
            {
                WebBeansThreadBindingListener webBeansThreadBindingListener = new WebBeansThreadBindingListener(webBeansContext, standardContext.getThreadBindingListener());
                standardContext.setThreadBindingListener(webBeansThreadBindingListener);
            }
            final ContextsService contextsService = webBeansContext.getContextsService();
            if (CdiAppContextsService.class.isInstance(contextsService)) {
                // here ServletContext is usable
                CdiAppContextsService.class.cast(contextsService).applicationStarted(standardContext.getServletContext());
            }
        } else {
            // just add the end listener to be able to stack tasks to execute at the request end
            final EndWebBeansListener endWebBeansListener = new EndWebBeansListener(webBeansContext);
            {
                final Object[] appEventListeners = standardContext.getApplicationEventListeners();
                final Object[] newEventListeners = new Object[appEventListeners.length + 1];
                System.arraycopy(appEventListeners, 0, newEventListeners, 0, appEventListeners.length);
                newEventListeners[newEventListeners.length - 1] = endWebBeansListener;
                standardContext.setApplicationEventListeners(newEventListeners);
            }
            {
                final Object[] lifecycleListeners = standardContext.getApplicationLifecycleListeners();
                final Object[] newLifecycleListeners = new Object[lifecycleListeners.length + 1];
                System.arraycopy(lifecycleListeners, 0, newLifecycleListeners, 0, lifecycleListeners.length);
                newLifecycleListeners[newLifecycleListeners.length - 1] = endWebBeansListener;
                standardContext.setApplicationLifecycleListeners(newLifecycleListeners);
            }
        }
    } finally {
        thread.setContextClassLoader(originalLoader);
    }
    LinkageErrorProtection.preload(standardContext);
    final Pipeline pipeline = standardContext.getPipeline();
    pipeline.addValve(new OpenEJBValve());
    final String[] valves = SystemInstance.get().getOptions().get("tomee.valves", "").split(" *, *");
    for (final String className : valves) {
        if ("".equals(className)) {
            continue;
        }
        try {
            final Class<?> clazz = classLoader.loadClass(className);
            if (Valve.class.isAssignableFrom(clazz)) {
                final Valve valve = (Valve) clazz.newInstance();
                pipeline.addValve(valve);
            }
        } catch (final Exception e) {
            LOGGER.error("can't add the valve " + className, e);
        }
    }
    // add servlets to webappinfo
    if (currentWebAppInfo != null) {
        for (final String mapping : standardContext.findServletMappings()) {
            final ServletInfo info = new ServletInfo();
            info.servletName = standardContext.findServletMapping(mapping);
            info.mappings.add(mapping);
            final Container container = standardContext.findChild(info.servletName);
            if (container instanceof StandardWrapper) {
                info.servletClass = ((StandardWrapper) container).getServletClass();
            } else {
                info.servletClass = mapping;
            }
            currentWebAppInfo.servlets.add(info);
        }
    }
    addConfiguredDocBases(standardContext, contextInfo);
    ensureMyFacesDontLooseFacesContext(standardContext);
}
Also used : WebContext(org.apache.openejb.core.WebContext) CdiAppContextsService(org.apache.openejb.cdi.CdiAppContextsService) ServletInfo(org.apache.openejb.assembler.classic.ServletInfo) BeginWebBeansListener(org.apache.openejb.server.httpd.BeginWebBeansListener) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) Container(org.apache.catalina.Container) WebBeansContext(org.apache.webbeans.config.WebBeansContext) EndWebBeansListener(org.apache.openejb.server.httpd.EndWebBeansListener) NewEjbAvailableAfterApplicationCreated(org.apache.openejb.assembler.classic.event.NewEjbAvailableAfterApplicationCreated) AfterApplicationCreated(org.apache.tomee.catalina.event.AfterApplicationCreated) RouterValve(org.apache.tomee.catalina.routing.RouterValve) Valve(org.apache.catalina.Valve) NamingException(javax.naming.NamingException) NamingContextListener(org.apache.catalina.core.NamingContextListener) Realm(org.apache.catalina.Realm) WebContext(org.apache.openejb.core.WebContext) InitialContext(javax.naming.InitialContext) WebBeansContext(org.apache.webbeans.config.WebBeansContext) BeanContext(org.apache.openejb.BeanContext) Context(javax.naming.Context) ServletContext(javax.servlet.ServletContext) PolicyContext(org.apache.openejb.assembler.classic.PolicyContext) AppContext(org.apache.openejb.AppContext) StandardContext(org.apache.catalina.core.StandardContext) CdiAppContextsService(org.apache.openejb.cdi.CdiAppContextsService) ContextsService(org.apache.webbeans.spi.ContextsService) WebBeansThreadBindingListener(org.apache.tomee.catalina.cdi.WebBeansThreadBindingListener) Request(org.apache.catalina.connector.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) SystemComponentReference(org.apache.openejb.core.ivm.naming.SystemComponentReference) LifecycleException(org.apache.catalina.LifecycleException) NameNotFoundException(javax.naming.NameNotFoundException) IOException(java.io.IOException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) Pipeline(org.apache.catalina.Pipeline) HandleDelegate(javax.ejb.spi.HandleDelegate) StandardWrapper(org.apache.catalina.core.StandardWrapper)

Aggregations

Pipeline (org.apache.catalina.Pipeline)13 Valve (org.apache.catalina.Valve)10 IOException (java.io.IOException)4 LifecycleException (org.apache.catalina.LifecycleException)4 Container (org.apache.catalina.Container)3 Context (org.apache.catalina.Context)2 Lifecycle (org.apache.catalina.Lifecycle)2 Realm (org.apache.catalina.Realm)2 ContainerBase (org.apache.catalina.core.ContainerBase)2 StandardContext (org.apache.catalina.core.StandardContext)2 SecurityConstraint (org.apache.catalina.deploy.SecurityConstraint)2 LoginConfig (org.apache.tomcat.util.descriptor.web.LoginConfig)2 WebBeansContext (org.apache.webbeans.config.WebBeansContext)2 ServletException (jakarta.servlet.ServletException)1 Cookie (jakarta.servlet.http.Cookie)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1 InputStream (java.io.InputStream)1