Search in sources :

Example 1 with GlassFishValve

use of org.glassfish.web.valve.GlassFishValve 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 2 with GlassFishValve

use of org.glassfish.web.valve.GlassFishValve in project Payara by payara.

the class ContextConfig method start.

// END GlassFish 2439
/**
 * Process a "start" event for this Context - in background
 */
protected synchronized void start() throws LifecycleException {
    if (log.isLoggable(Level.FINEST)) {
        log.log(Level.FINEST, LogFacade.PROCESSING_START_FINEST);
    }
    context.setConfigured(false);
    // Set properties based on DefaultContext
    Container container = context.getParent();
    if (!context.getOverride()) {
        if (container instanceof Host) {
            // Reset the value only if the attribute wasn't
            // set on the context.
            xmlValidation = context.getXmlValidation();
            if (!xmlValidation) {
                xmlValidation = ((Host) container).getXmlValidation();
            }
            xmlNamespaceAware = context.getXmlNamespaceAware();
            if (!xmlNamespaceAware) {
                xmlNamespaceAware = ((Host) container).getXmlNamespaceAware();
            }
        }
    }
    // Process the default and application web.xml files
    defaultConfig();
    applicationConfig();
    validateSecurityRoles();
    // Configure an authenticator if we need one
    authenticatorConfig();
    // Configure a manager
    managerConfig();
    // Dump the contents of this pipeline if requested
    if ((log.isLoggable(Level.FINEST)) && (context instanceof ContainerBase)) {
        log.log(Level.FINEST, "Pipline Configuration:");
        Pipeline pipeline = ((ContainerBase) context).getPipeline();
        GlassFishValve[] valves = null;
        if (pipeline != null)
            valves = pipeline.getValves();
        if (valves != null) {
            for (GlassFishValve valve : valves) {
                log.log(Level.FINEST, "  " + valve.getInfo());
            }
        }
        log.log(Level.FINEST, "======================");
    }
    // Make our application available because no problems
    // were encountered
    context.setConfigured(true);
}
Also used : GlassFishValve(org.glassfish.web.valve.GlassFishValve)

Example 3 with GlassFishValve

use of org.glassfish.web.valve.GlassFishValve in project Payara by payara.

the class ContextConfig method authenticatorConfig.

/**
 * Set up an Authenticator automatically if required, and one has not
 * already been configured.
 */
protected synchronized void authenticatorConfig() throws LifecycleException {
    // Does this Context require an Authenticator?
    /* START IASRI 4856062
           // This constraints check is relocated to happen after
           // setRealmName(). This allows apps which have no constraints
           // and no authenticator to still have a realm name set in
           // their RealmAdapater. This is only relevant in the case where
           // the core ACLs are doing all access control AND the servlet
           // wishes to call isUserInRole AND the application does have
           // security-role-mapping elements in sun-web.xml. This is probably
           // not an interesting scenario. But might as well allow it to
           // work, maybe it is of some use.
        SecurityConstraint constraints[] = context.findConstraints();
        if ((constraints == null) || (constraints.length == 0))
            return;
        */
    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) {
            GlassFishValve basic = pipeline.getBasic();
            if ((basic != null) && (basic instanceof Authenticator))
                return;
            GlassFishValve[] valves = pipeline.getValves();
            for (GlassFishValve valve : valves) {
                if (valve instanceof Authenticator) {
                    return;
                }
            }
        }
    } else {
        // Cannot install a Valve even if it would be needed
        return;
    }
    // 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
        throw new LifecycleException(rb.getString(LogFacade.NO_REALM_BEEN_CONFIGURED_EXCEPTION));
    }
    // BEGIN IASRI 4856062
    // If a realm is available set its name in the Realm(Adapter)
    rlm.setRealmName(loginConfig.getRealmName(), loginConfig.getAuthMethod());
    if (!context.hasConstraints()) {
        return;
    }
    // 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.
         */
    GlassFishValve authenticator = null;
    if (customAuthenticators != null) {
        /* PWC 6392537
            authenticator = (Valve)
                customAuthenticators.get(loginConfig.getAuthMethod());
            */
        // START PWC 6392537
        String loginMethod = loginConfig.getAuthMethod();
        if (loginMethod != null && customAuthenticators.containsKey(loginMethod)) {
            authenticator = getGlassFishValveAuthenticator(loginMethod);
            if (authenticator == null) {
                String msg = MessageFormat.format(rb.getString(LogFacade.CANNOT_CONFIG_AUTHENTICATOR_EXCEPTION), loginMethod);
                throw new LifecycleException(msg);
            }
        }
    // END PWC 6392537
    }
    if (authenticator == null) {
        // 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);
        if (authenticatorName == null) {
            String msg = MessageFormat.format(rb.getString(LogFacade.CANNOT_CONFIG_AUTHENTICATOR_EXCEPTION), loginConfig.getAuthMethod());
            throw new LifecycleException(msg);
        }
        // Instantiate and install an Authenticator of the requested class
        try {
            Class authenticatorClass = Class.forName(authenticatorName);
            authenticator = (GlassFishValve) authenticatorClass.newInstance();
        } catch (Throwable t) {
            String msg = MessageFormat.format(rb.getString(LogFacade.CANNOT_INSTANTIATE_AUTHENTICATOR_EXCEPTION), authenticatorName);
            throw new LifecycleException(msg, t);
        }
    }
    if (authenticator != null && context instanceof ContainerBase) {
        Pipeline pipeline = ((ContainerBase) context).getPipeline();
        if (pipeline != null) {
            ((ContainerBase) context).addValve(authenticator);
            if (log.isLoggable(Level.FINE)) {
                log.log(Level.FINE, LogFacade.CONFIGURED_AUTHENTICATOR_FINE, loginConfig.getAuthMethod());
            }
        }
    }
}
Also used : LoginConfig(org.apache.catalina.deploy.LoginConfig) GlassFishValve(org.glassfish.web.valve.GlassFishValve)

Example 4 with GlassFishValve

use of org.glassfish.web.valve.GlassFishValve in project Payara by payara.

the class StandardPipeline method addValve.

/**
 * <p>
 * Add a new Valve to the end of the pipeline associated with this Container. Prior to adding the
 * Valve, the Valve's <code>setContainer()</code> method will be called, if it implements
 * <code>Contained</code>, with the owning Container as an argument. The method may throw an
 * <code>IllegalArgumentException</code> if this Valve chooses not to be associated with this
 * Container, or <code>IllegalStateException</code> if it is already associated with a different
 * Container.
 * </p>
 *
 * @param valve Valve to be added
 *
 * @exception IllegalArgumentException if this Container refused to accept the specified Valve
 * @exception IllegalArgumentException if the specified Valve refuses to be associated with this
 * Container
 * @exception IllegalStateException if the specified Valve is already associated with a different
 * Container
 */
@Override
public void addValve(GlassFishValve valve) {
    if (firstTcValve != null) {
        // Wrap GlassFish-style valve inside Tomcat-style valve
        addValve(new TomcatValveAdapter(valve));
        return;
    }
    // Validate that we can add this Valve
    if (valve instanceof Contained)
        ((Contained) valve).setContainer(this.container);
    // Start the new component if necessary
    if (started) {
        if (valve instanceof Lifecycle) {
            try {
                ((Lifecycle) valve).start();
            } catch (LifecycleException e) {
                log.log(Level.SEVERE, LogFacade.ADD_VALVE_EXCEPTION, e);
            }
        }
    /**
     * CR 6411114 (MBean registration moved to ValveBase.start()) // Register the newly added valve
     * registerValve(valve);
     */
    }
    // Add this Valve to the set associated with this Pipeline
    GlassFishValve[] results = new GlassFishValve[valves.length + 1];
    System.arraycopy(valves, 0, results, 0, valves.length);
    results[valves.length] = valve;
    valves = results;
}
Also used : TomcatValveAdapter(org.glassfish.web.valve.TomcatValveAdapter) GlassFishValve(org.glassfish.web.valve.GlassFishValve)

Example 5 with GlassFishValve

use of org.glassfish.web.valve.GlassFishValve in project Payara by payara.

the class StandardPipeline method stop.

/**
 * Gracefully shut down active use of the public methods of this Component.
 *
 * @exception IllegalStateException if this component has not been started
 * @exception LifecycleException if this component detects a fatal error that needs to be reported
 */
@Override
public synchronized void stop() throws LifecycleException {
    // Validate and update our current component state
    if (!started)
        throw new LifecycleException(rb.getString(LogFacade.PIPLINE_NOT_STARTED));
    started = false;
    // Notify our interested LifecycleListeners
    lifecycle.fireLifecycleEvent(BEFORE_STOP_EVENT, null);
    // Notify our interested LifecycleListeners
    lifecycle.fireLifecycleEvent(STOP_EVENT, null);
    // Stop the Valves in our pipeline (including the basic), if any
    if ((basic != null) && (basic instanceof Lifecycle))
        ((Lifecycle) basic).stop();
    /**
     * CR 6411114 (MBean deregistration moved to ValveBase.stop()) if( basic!=null ) {
     * unregisterValve(basic); }
     */
    for (GlassFishValve valve : valves) {
        if (valve instanceof Lifecycle) {
            ((Lifecycle) valve).stop();
        /**
         * CR 6411114 (MBean deregistration moved to ValveBase.stop()) unregisterValve(valves[i]);
         */
        }
    }
    // Notify our interested LifecycleListeners
    lifecycle.fireLifecycleEvent(AFTER_STOP_EVENT, null);
}
Also used : GlassFishValve(org.glassfish.web.valve.GlassFishValve)

Aggregations

GlassFishValve (org.glassfish.web.valve.GlassFishValve)18 Method (java.lang.reflect.Method)2 ServletException (javax.servlet.ServletException)2 Container (org.apache.catalina.Container)2 ContainerBase (org.apache.catalina.core.ContainerBase)2 LoginConfig (org.apache.catalina.deploy.LoginConfig)2 ProxyHandler (com.sun.appserv.ProxyHandler)1 Config (com.sun.enterprise.config.serverbeans.Config)1 SecurityService (com.sun.enterprise.config.serverbeans.SecurityService)1 LoginConfiguration (com.sun.enterprise.deployment.web.LoginConfiguration)1 SecurityConstraint (com.sun.enterprise.deployment.web.SecurityConstraint)1 UserDataConstraint (com.sun.enterprise.deployment.web.UserDataConstraint)1 WebResourceCollection (com.sun.enterprise.deployment.web.WebResourceCollection)1 RealmInitializer (com.sun.enterprise.security.integration.RealmInitializer)1 GlassFishSingleSignOn (com.sun.enterprise.security.web.GlassFishSingleSignOn)1 LoginConfigDecorator (com.sun.enterprise.web.deploy.LoginConfigDecorator)1 IOException (java.io.IOException)1 String (java.lang.String)1 CertificateException (java.security.cert.CertificateException)1 X509Certificate (java.security.cert.X509Certificate)1