Java 类org.apache.catalina.Valve 实例源码

项目:lazycat    文件:StandardPipeline.java   
public ObjectName[] getValveObjectNames() {

        ArrayList<ObjectName> valveList = new ArrayList<ObjectName>();
        Valve current = first;
        if (current == null) {
            current = basic;
        }
        while (current != null) {
            if (current instanceof ValveBase) {
                valveList.add(((ValveBase) current).getObjectName());
            }
            current = current.getNext();
        }

        return valveList.toArray(new ObjectName[0]);

    }
项目:lazycat    文件:MBeanFactory.java   
/**
 * Create a new Valve and associate it with a {@link Container}.
 *
 * @param className
 *            The fully qualified class name of the {@link Valve} to create
 * @param parent
 *            The MBean name of the associated parent {@link Container}.
 *
 * @return The MBean name of the {@link Valve} that was created or
 *         <code>null</code> if the {@link Valve} does not implement
 *         {@link LifecycleMBeanBase}.
 */
public String createValve(String className, String parent) throws Exception {

    // Look for the parent
    ObjectName parentName = new ObjectName(parent);
    Container container = getParentContainerFromParent(parentName);

    if (container == null) {
        // TODO
        throw new IllegalArgumentException();
    }

    Valve valve = (Valve) Class.forName(className).newInstance();

    container.getPipeline().addValve(valve);

    if (valve instanceof LifecycleMBeanBase) {
        return ((LifecycleMBeanBase) valve).getObjectName().toString();
    } else {
        return null;
    }
}
项目:tomcat7    文件:MBeanUtils.java   
/**
 * Deregister the MBean for this
 * <code>Valve</code> object.
 *
 * @param valve The Valve to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 * @deprecated  Unused. Will be removed in Tomcat 8.0.x
 */
@Deprecated
static void destroyMBean(Valve valve, Container container)
    throws Exception {

    ((Contained)valve).setContainer(container);
    String mname = createManagedName(valve);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        return;
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, valve);
    try {
        ((Contained)valve).setContainer(null);
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
    }
    if( mserver.isRegistered(oname) ) {
        mserver.unregisterMBean(oname);
    }

}
项目:tomcat7    文件:StandardPipeline.java   
/**
 * Stop {@link Valve}s) in this pipeline and implement the requirements
 * of {@link LifecycleBase#stopInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void stopInternal() throws LifecycleException {

    setState(LifecycleState.STOPPING);

    // Stop the Valves in our pipeline (including the basic), if any
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        if (current instanceof Lifecycle)
            ((Lifecycle) current).stop();
        current = current.getNext();
    }
}
项目:lazycat    文件:StandardPipeline.java   
/**
 * Start {@link Valve}s) in this pipeline and implement the requirements of
 * {@link LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException
 *                if this component detects a fatal error that prevents this
 *                component from being used
 */
@Override
protected synchronized void startInternal() throws LifecycleException {

    // Start the Valves in our pipeline (including the basic), if any
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        if (current instanceof Lifecycle)
            ((Lifecycle) current).start();
        current = current.getNext();
    }

    setState(LifecycleState.STARTING);
}
项目:tomcat7    文件:StandardPipeline.java   
/**
 * Return the set of Valves in the pipeline associated with this
 * Container, including the basic Valve (if any).  If there are no
 * such Valves, a zero-length array is returned.
 */
@Override
public Valve[] getValves() {

    ArrayList<Valve> valveList = new ArrayList<Valve>();
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        valveList.add(current);
        current = current.getNext();
    }

    return valveList.toArray(new Valve[0]);

}
项目:tomcat7    文件:StandardPipeline.java   
public ObjectName[] getValveObjectNames() {

        ArrayList<ObjectName> valveList = new ArrayList<ObjectName>();
        Valve current = first;
        if (current == null) {
            current = basic;
        }
        while (current != null) {
            if (current instanceof ValveBase) {
                valveList.add(((ValveBase) current).getObjectName());
            }
            current = current.getNext();
        }

        return valveList.toArray(new ObjectName[0]);

    }
项目:lazycat    文件:StandardPipeline.java   
/**
 * Stop {@link Valve}s) in this pipeline and implement the requirements of
 * {@link LifecycleBase#stopInternal()}.
 *
 * @exception LifecycleException
 *                if this component detects a fatal error that prevents this
 *                component from being used
 */
@Override
protected synchronized void stopInternal() throws LifecycleException {

    setState(LifecycleState.STOPPING);

    // Stop the Valves in our pipeline (including the basic), if any
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        if (current instanceof Lifecycle)
            ((Lifecycle) current).stop();
        current = current.getNext();
    }
}
项目:lazycat    文件:StandardContext.java   
@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;
}
项目:tomcat7    文件:ContainerBase.java   
@Override
public AccessLog getAccessLog() {

    if (accessLogScanComplete) {
        return accessLog;
    }

    AccessLogAdapter adapter = null;
    Valve valves[] = getPipeline().getValves();
    for (Valve valve : valves) {
        if (valve instanceof AccessLog) {
            if (adapter == null) {
                adapter = new AccessLogAdapter((AccessLog) valve);
            } else {
                adapter.add((AccessLog) valve);
            }
        }
    }
    if (adapter != null) {
        accessLog = adapter;
    }
    accessLogScanComplete = true;
    return accessLog;
}
项目:lams    文件:MBeanUtils.java   
/**
 * Deregister the MBean for this
 * <code>Valve</code> object.
 *
 * @param valve The Valve to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 */
static void destroyMBean(Valve valve, Container container)
    throws Exception {

    ((Contained)valve).setContainer(container);
    String mname = createManagedName(valve);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        return;
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, valve);
    try {
        ((Contained)valve).setContainer(null);
    } catch (Throwable t) {
    ;
    }
    if( mserver.isRegistered(oname) ) {
        mserver.unregisterMBean(oname);
    }

}
项目:lams    文件:StandardPipeline.java   
/**
 * Return the set of Valves in the pipeline associated with this
 * Container, including the basic Valve (if any).  If there are no
 * such Valves, a zero-length array is returned.
 */
public Valve[] getValves() {

    ArrayList valveList = new ArrayList();
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        valveList.add(current);
        current = current.getNext();
    }

    return ((Valve[]) valveList.toArray(new Valve[0]));

}
项目:lams    文件:StandardPipeline.java   
public ObjectName[] getValveObjectNames() {

        ArrayList valveList = new ArrayList();
        Valve current = first;
        if (current == null) {
            current = basic;
        }
        while (current != null) {
            if (current instanceof ValveBase) {
                valveList.add(((ValveBase) current).getObjectName());
            }
            current = current.getNext();
        }

        return ((ObjectName[]) valveList.toArray(new ObjectName[0]));

    }
项目:lazycat    文件:MBeanUtils.java   
/**
 * Deregister the MBean for this <code>Valve</code> object.
 *
 * @param valve
 *            The Valve to be managed
 *
 * @exception Exception
 *                if an MBean cannot be deregistered
 * @deprecated Unused. Will be removed in Tomcat 8.0.x
 */
@Deprecated
static void destroyMBean(Valve valve, Container container) throws Exception {

    ((Contained) valve).setContainer(container);
    String mname = createManagedName(valve);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        return;
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, valve);
    try {
        ((Contained) valve).setContainer(null);
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
    }
    if (mserver.isRegistered(oname)) {
        mserver.unregisterMBean(oname);
    }

}
项目:jerrydog    文件:StandardHostMBean.java   
/**
 * Return the MBean Names of the Valves assoicated with this Host
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String [] getValves()
    throws Exception {

    Registry registry = MBeanUtils.createRegistry();
    StandardHost host = (StandardHost) this.resource;
    String mname = MBeanUtils.createManagedName(host);
    ManagedBean managed = registry.findManagedBean(mname);
    String domain = null;
    if (managed != null) {
        domain = managed.getDomain();
    }
    if (domain == null)
        domain = mserver.getDefaultDomain();
    Valve [] valves = host.getValves();
    String [] mbeanNames = new String[valves.length];
    for (int i = 0; i < valves.length; i++) {
        mbeanNames[i] =
            MBeanUtils.createObjectName(domain, valves[i]).toString();
    }

    return mbeanNames;

}
项目:jerrydog    文件:ServerLifecycleListener.java   
/**
 * Handle a <code>ContainerEvent</code> from one of the Containers we are
 * interested in.
 *
 * @param event The event that has occurred
 */
public void containerEvent(ContainerEvent event) {

    try {
        String type = event.getType();
        if (Container.ADD_CHILD_EVENT.equals(type)) {
            processContainerAddChild(event.getContainer(),
                                     (Container) event.getData());
        } else if (Container.ADD_VALVE_EVENT.equals(type)) {
            processContainerAddValve(event.getContainer(),
                                     (Valve) event.getData());
        } else if (Container.REMOVE_CHILD_EVENT.equals(type)) {
            processContainerRemoveChild(event.getContainer(),
                                        (Container) event.getData());
        } else if (Container.REMOVE_VALVE_EVENT.equals(type)) {
            processContainerRemoveValve(event.getContainer(),
                                        (Valve) event.getData());
        }
    } catch (Exception e) {
        log("Exception processing event " + event, e);
    }

}
项目:jerrydog    文件:MBeanUtils.java   
/**
 * Create, register, and return an MBean for this
 * <code>Valve</code> object.
 *
 * @param valve The Valve to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public static ModelMBean createMBean(Valve valve)
    throws Exception {

    String mname = createManagedName(valve);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ModelMBean mbean = managed.createMBean(valve);
    ObjectName oname = createObjectName(domain, valve);
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
项目:apache-tomcat-7.0.73-with-comment    文件:StandardContext.java   
@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;
}
项目:apache-tomcat-7.0.73-with-comment    文件:MBeanFactory.java   
/**
 * Create a new Valve and associate it with a {@link Container}.
 *
 * @param className The fully qualified class name of the {@link Valve} to
 *                  create
 * @param parent    The MBean name of the associated parent
 *                  {@link Container}.
 *
 * @return  The MBean name of the {@link Valve} that was created or
 *          <code>null</code> if the {@link Valve} does not implement
 *          {@link LifecycleMBeanBase}.
 */
public String createValve(String className, String parent)
        throws Exception {

    // Look for the parent
    ObjectName parentName = new ObjectName(parent);
    Container container = getParentContainerFromParent(parentName);

    if (container == null) {
        // TODO
        throw new IllegalArgumentException();
    }

    Valve valve = (Valve) Class.forName(className).newInstance();

    container.getPipeline().addValve(valve);

    if (valve instanceof LifecycleMBeanBase) {
        return ((LifecycleMBeanBase) valve).getObjectName().toString();
    } else {
        return null;
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:MBeanUtils.java   
/**
 * Deregister the MBean for this
 * <code>Valve</code> object.
 *
 * @param valve The Valve to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 * @deprecated  Unused. Will be removed in Tomcat 8.0.x
 */
@Deprecated
static void destroyMBean(Valve valve, Container container)
    throws Exception {

    ((Contained)valve).setContainer(container);
    String mname = createManagedName(valve);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        return;
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, valve);
    try {
        ((Contained)valve).setContainer(null);
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
    }
    if( mserver.isRegistered(oname) ) {
        mserver.unregisterMBean(oname);
    }

}
项目:apache-tomcat-7.0.73-with-comment    文件:StandardPipeline.java   
/**
 * Start {@link Valve}s) in this pipeline and implement the requirements
 * of {@link LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void startInternal() throws LifecycleException {

    // Start the Valves in our pipeline (including the basic), if any
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        if (current instanceof Lifecycle)
            ((Lifecycle) current).start();
        current = current.getNext();
    }

    setState(LifecycleState.STARTING);
}
项目:apache-tomcat-7.0.73-with-comment    文件:StandardPipeline.java   
/**
 * Stop {@link Valve}s) in this pipeline and implement the requirements
 * of {@link LifecycleBase#stopInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void stopInternal() throws LifecycleException {

    setState(LifecycleState.STOPPING);

    // Stop the Valves in our pipeline (including the basic), if any
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        if (current instanceof Lifecycle)
            ((Lifecycle) current).stop();
        current = current.getNext();
    }
}
项目:tomcat7    文件:SimpleTcpCluster.java   
/**
 * register all cluster valve to host or engine
 */
protected void registerClusterValve() {
    if(container != null ) {
        for (Iterator<Valve> iter = valves.iterator(); iter.hasNext();) {
            ClusterValve valve = (ClusterValve) iter.next();
            if (log.isDebugEnabled())
                log.debug("Invoking addValve on " + getContainer()
                        + " with class=" + valve.getClass().getName());
            if (valve != null) {
                container.getPipeline().addValve(valve);
                valve.setCluster(this);
            }
        }
    }
}
项目:tomcat7    文件:SimpleTcpCluster.java   
/**
 * unregister all cluster valve to host or engine
 */
protected void unregisterClusterValve() {
    for (Iterator<Valve> iter = valves.iterator(); iter.hasNext();) {
        ClusterValve valve = (ClusterValve) iter.next();
        if (log.isDebugEnabled())
            log.debug("Invoking removeValve on " + getContainer()
                    + " with class=" + valve.getClass().getName());
        if (valve != null) {
            container.getPipeline().removeValve(valve);
            valve.setCluster(null);
        }
    }
}
项目:tomcat7    文件:MBeanFactory.java   
/**
 * Remove an existing Valve.
 *
 * @param name MBean Name of the component to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeValve(String name) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    ContainerBase container = getParentContainerFromChild(oname);
    Valve[] valves = container.getPipeline().getValves();
    for (int i = 0; i < valves.length; i++) {
        ObjectName voname = ((ValveBase) valves[i]).getObjectName();
        if (voname.equals(oname)) {
            container.getPipeline().removeValve(valves[i]);
        }
    }
}
项目:tomcat7    文件:AuthenticatorBase.java   
/**
 * Start this component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void startInternal() throws LifecycleException {

    // Look up the SingleSignOn implementation in our request processing
    // path, if there is one
    Container parent = context.getParent();
    while ((sso == null) && (parent != null)) {
        Valve valves[] = parent.getPipeline().getValves();
        for (int i = 0; i < valves.length; i++) {
            if (valves[i] instanceof SingleSignOn) {
                sso = (SingleSignOn) valves[i];
                break;
            }
        }
        if (sso == null)
            parent = parent.getParent();
    }
    if (log.isDebugEnabled()) {
        if (sso != null)
            log.debug("Found SingleSignOn Valve at " + sso);
        else
            log.debug("No SingleSignOn Valve is present");
    }

    sessionIdGenerator = new StandardSessionIdGenerator();
    sessionIdGenerator.setSecureRandomAlgorithm(getSecureRandomAlgorithm());
    sessionIdGenerator.setSecureRandomClass(getSecureRandomClass());
    sessionIdGenerator.setSecureRandomProvider(getSecureRandomProvider());

    super.startInternal();
}
项目:tomcat7    文件:StandardPipeline.java   
@Override
public boolean isAsyncSupported() {
    Valve valve = (first!=null)?first:basic;
    boolean supported = true;
    while (supported && valve!=null) {
        supported = supported & valve.isAsyncSupported();
        valve = valve.getNext();
    }
    return supported; 
}
项目:apache-tomcat-7.0.73-with-comment    文件:StandardPipeline.java   
@Override
protected void destroyInternal() {
    Valve[] valves = getValves();
    for (Valve valve : valves) {
        removeValve(valve);
    }
}
项目:tomcat7    文件:StandardPipeline.java   
/**
 * <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(Valve valve) {

    // Validate that we can add this Valve
    if (valve instanceof Contained)
        ((Contained) valve).setContainer(this.container);

    // Start the new component if necessary
    if (getState().isAvailable()) {
        if (valve instanceof Lifecycle) {
            try {
                ((Lifecycle) valve).start();
            } catch (LifecycleException e) {
                log.error("StandardPipeline.addValve: start: ", e);
            }
        }
    }

    // Add this Valve to the set associated with this Pipeline
    if (first == null) {
        first = valve;
        valve.setNext(basic);
    } else {
        Valve current = first;
        while (current != null) {
            if (current.getNext() == basic) {
                current.setNext(valve);
                valve.setNext(basic);
                break;
            }
            current = current.getNext();
        }
    }

    container.fireContainerEvent(Container.ADD_VALVE_EVENT, valve);
}
项目:tomcat7    文件:StandardPipeline.java   
@Override
public Valve getFirst() {
    if (first != null) {
        return first;
    }

    return basic;
}
项目:tomcat7    文件:StandardHost.java   
/**
  * Return the MBean Names of the Valves associated with this Host
  *
  * @exception Exception if an MBean cannot be created or registered
  */
 public String [] getValveNames()
     throws Exception
{
     Valve [] valves = this.getPipeline().getValves();
     String [] mbeanNames = new String[valves.length];
     for (int i = 0; i < valves.length; i++) {
         if( valves[i] == null ) continue;
         if( ((ValveBase)valves[i]).getObjectName() == null ) continue;
         mbeanNames[i] = ((ValveBase)valves[i]).getObjectName().toString();
     }

     return mbeanNames;

 }
项目:tomcat7    文件:TestFormAuthenticator.java   
private FormAuthClient(boolean clientShouldUseCookies,
        boolean serverShouldUseCookies,
        boolean serverShouldChangeSessid) throws Exception {

    Tomcat tomcat = getTomcatInstance();
    File appDir = new File(getBuildDirectory(), "webapps/examples");
    Context ctx = tomcat.addWebapp(null, "/examples",
            appDir.getAbsolutePath());
    setUseCookies(clientShouldUseCookies);
    ctx.setCookies(serverShouldUseCookies);

    MapRealm realm = new MapRealm();
    realm.addUser("tomcat", "tomcat");
    realm.addUserRole("tomcat", "tomcat");
    ctx.setRealm(realm);

    tomcat.start();

    // perhaps this does not work until tomcat has started?
    ctx.setSessionTimeout(TIMEOUT_MINS);

    // Valve pipeline is only established after tomcat starts
    Valve[] valves = ctx.getPipeline().getValves();
    for (Valve valve : valves) {
        if (valve instanceof AuthenticatorBase) {
            ((AuthenticatorBase)valve)
                    .setChangeSessionIdOnAuthentication(
                                        serverShouldChangeSessid);
            break;
        }
    }

    // Port only known after Tomcat starts
    setPort(getPort());
}
项目:lazycat    文件:StandardPipeline.java   
@Override
public Valve getFirst() {
    if (first != null) {
        return first;
    }

    return basic;
}
项目:lazycat    文件:StandardHost.java   
/**
 * Return the MBean Names of the Valves associated with this Host
 *
 * @exception Exception
 *                if an MBean cannot be created or registered
 */
public String[] getValveNames() throws Exception {
    Valve[] valves = this.getPipeline().getValves();
    String[] mbeanNames = new String[valves.length];
    for (int i = 0; i < valves.length; i++) {
        if (valves[i] == null)
            continue;
        if (((ValveBase) valves[i]).getObjectName() == null)
            continue;
        mbeanNames[i] = ((ValveBase) valves[i]).getObjectName().toString();
    }

    return mbeanNames;

}
项目:lams    文件:MBeanFactory.java   
/**
 * Remove an existing Valve.
 *
 * @param name MBean Name of the comonent to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeValve(String name) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    ContainerBase container = getParentContainerFromChild(oname);
    String sequence = oname.getKeyProperty("seq");
    Valve[] valves = (Valve[])container.getValves();
    for (int i = 0; i < valves.length; i++) {
        ObjectName voname = ((ValveBase) valves[i]).getObjectName();
        if (voname.equals(oname)) {
            container.removeValve(valves[i]);
        }
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestFormAuthenticator.java   
private FormAuthClient(boolean clientShouldUseCookies,
        boolean serverShouldUseCookies,
        boolean serverShouldChangeSessid) throws Exception {

    Tomcat tomcat = getTomcatInstance();
    File appDir = new File(getBuildDirectory(), "webapps/examples");
    Context ctx = tomcat.addWebapp(null, "/examples",
            appDir.getAbsolutePath());
    setUseCookies(clientShouldUseCookies);
    ctx.setCookies(serverShouldUseCookies);

    MapRealm realm = new MapRealm();
    realm.addUser("tomcat", "tomcat");
    realm.addUserRole("tomcat", "tomcat");
    ctx.setRealm(realm);

    tomcat.start();

    // perhaps this does not work until tomcat has started?
    ctx.setSessionTimeout(TIMEOUT_MINS);

    // Valve pipeline is only established after tomcat starts
    Valve[] valves = ctx.getPipeline().getValves();
    for (Valve valve : valves) {
        if (valve instanceof AuthenticatorBase) {
            ((AuthenticatorBase)valve)
                    .setChangeSessionIdOnAuthentication(
                                        serverShouldChangeSessid);
            break;
        }
    }

    // Port only known after Tomcat starts
    setPort(getPort());
}
项目:lams    文件:AuthenticatorBase.java   
/**
 * 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
 */
public void start() throws LifecycleException {

    // Validate and update our current component state
    if (started)
        throw new LifecycleException
            (sm.getString("authenticator.alreadyStarted"));
    lifecycle.fireLifecycleEvent(START_EVENT, null);
    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;
        }
        Valve valves[] = ((Pipeline) parent).getValves();
        for (int i = 0; i < valves.length; i++) {
            if (valves[i] instanceof SingleSignOn) {
                sso = (SingleSignOn) valves[i];
                break;
            }
        }
        if (sso == null)
            parent = parent.getParent();
    }
    if (log.isDebugEnabled()) {
        if (sso != null)
            log.debug("Found SingleSignOn Valve at " + sso);
        else
            log.debug("No SingleSignOn Valve is present");
    }

}
项目:lams    文件:StandardPipeline.java   
/**
 * Prepare for active use of the public methods of this Component.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents it from being started
 */
public synchronized void start() throws LifecycleException {

    // Validate and update our current component state
    if (started) {
        if(log.isDebugEnabled())
            log.debug(sm.getString("standardPipeline.alreadyStarted"));
        return;
    }

    // Notify our interested LifecycleListeners
    lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null);

    started = true;

    // Start the Valves in our pipeline (including the basic), if any
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        if (current instanceof Lifecycle)
            ((Lifecycle) current).start();
        registerValve(current);
        current = current.getNext();
    }

    // Notify our interested LifecycleListeners
    lifecycle.fireLifecycleEvent(START_EVENT, null);

    // Notify our interested LifecycleListeners
    lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null);

}
项目:lams    文件:StandardPipeline.java   
/**
 * Gracefully shut down active use of the public methods of this Component.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that needs to be reported
 */
public synchronized void stop() throws LifecycleException {

    // Validate and update our current component state
    if (!started) {
        if(log.isDebugEnabled())
            log.debug(sm.getString("standardPipeline.notStarted"));
        return;
    }

    // Notify our interested LifecycleListeners
    lifecycle.fireLifecycleEvent(BEFORE_STOP_EVENT, null);

    // Notify our interested LifecycleListeners
    lifecycle.fireLifecycleEvent(STOP_EVENT, null);
    started = false;

    // Stop the Valves in our pipeline (including the basic), if any
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        if (current instanceof Lifecycle)
            ((Lifecycle) current).stop();
        unregisterValve(current);
        current = current.getNext();
    }

    // Notify our interested LifecycleListeners
    lifecycle.fireLifecycleEvent(AFTER_STOP_EVENT, null);
}
项目:apache-tomcat-7.0.73-with-comment    文件:StandardPipeline.java   
@Override
public Valve getFirst() {
    if (first != null) {
        return first;
    }

    return basic;
}