当前位置: 首页>>代码示例>>Java>>正文


Java Context.setCookies方法代码示例

本文整理汇总了Java中org.apache.catalina.Context.setCookies方法的典型用法代码示例。如果您正苦于以下问题:Java Context.setCookies方法的具体用法?Java Context.setCookies怎么用?Java Context.setCookies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.catalina.Context的用法示例。


在下文中一共展示了Context.setCookies方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: FormAuthClient

import org.apache.catalina.Context; //导入方法依赖的package包/类
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());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:36,代码来源:TestFormAuthenticator.java

示例2: FormAuthClientSelectedMethods

import org.apache.catalina.Context; //导入方法依赖的package包/类
private FormAuthClientSelectedMethods(boolean clientShouldUseCookies,
        boolean serverShouldUseCookies,
        boolean serverShouldChangeSessid) throws Exception {

    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    Tomcat.addServlet(ctx, "SelectedMethods",
            new SelectedMethodsServlet());
    ctx.addServletMapping("/test", "SelectedMethods");
    // Login servlet just needs to respond "OK". Client will handle
    // creating a valid response. No need for a form.
    Tomcat.addServlet(ctx, "Login",
            new TesterServlet());
    ctx.addServletMapping("/login", "Login");

    // Configure the security constraints
    SecurityConstraint constraint = new SecurityConstraint();
    SecurityCollection collection = new SecurityCollection();
    collection.setName("Protect PUT");
    collection.addMethod("PUT");
    collection.addPattern("/test");
    constraint.addCollection(collection);
    constraint.addAuthRole("tomcat");
    ctx.addConstraint(constraint);

    // Configure authentication
    LoginConfig lc = new LoginConfig();
    lc.setAuthMethod("FORM");
    lc.setLoginPage("/login");
    ctx.setLoginConfig(lc);
    ctx.getPipeline().addValve(new FormAuthenticator());

    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());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:62,代码来源:TestFormAuthenticator.java

示例3: importDefaultContext

import org.apache.catalina.Context; //导入方法依赖的package包/类
/**
 * Import the configuration from the DefaultContext into
 * current Context.
 *
 * @param context current web application context
 */
public void importDefaultContext(Context context) {

    if (context instanceof StandardContext) {
        ((StandardContext)context).setUseNaming(isUseNaming());
        ((StandardContext)context).setSwallowOutput(getSwallowOutput());
        if (!contexts.containsKey(context)) {
            ((StandardContext) context).addLifecycleListener(this);
        }
    }

    context.setCookies(getCookies());
    context.setCrossContext(getCrossContext());
    context.setReloadable(getReloadable());

    String [] listeners = findApplicationListeners();
    for( int i = 0; i < listeners.length; i++ ) {
        context.addApplicationListener(listeners[i]);
    }
    listeners = findInstanceListeners();
    for( int i = 0; i < listeners.length; i++ ) {
        context.addInstanceListener(listeners[i]);
    }
    String [] wrapper = findWrapperListeners();
    for( int i = 0; i < wrapper.length; i++ ) {
        context.addWrapperListener(wrapper[i]);
    }
    wrapper = findWrapperLifecycles();
    for( int i = 0; i < wrapper.length; i++ ) {
        context.addWrapperLifecycle(wrapper[i]);
    }
    String [] parameters = findParameters();
    for( int i = 0; i < parameters.length; i++ ) {
        context.addParameter(parameters[i],findParameter(parameters[i]));
    }
    ApplicationParameter [] appParam = findApplicationParameters();
    for( int i = 0; i < appParam.length; i++ ) {
        context.addApplicationParameter(appParam[i]);
    }

    if (!(context instanceof StandardContext)) {
        ContextEjb [] contextEjb = findEjbs();
        for( int i = 0; i < contextEjb.length; i++ ) {
            context.addEjb(contextEjb[i]);
        }
        ContextEnvironment [] contextEnv = findEnvironments();
        for( int i = 0; i < contextEnv.length; i++ ) {
            context.addEnvironment(contextEnv[i]);
        }
        /*
        if (context instanceof StandardContext) {
            ResourceParams [] resourceParams = findResourceParams();
            for( int i = 0; i < resourceParams.length; i++ ) {
                ((StandardContext)context).addResourceParams
                    (resourceParams[i]);
            }
        }
        */
        ContextResource [] resources = findResources();
        for( int i = 0; i < resources.length; i++ ) {
            context.addResource(resources[i]);
        }
        String [] envRefs = findResourceEnvRefs();
        for( int i = 0; i < envRefs.length; i++ ) {
            context.addResourceEnvRef
                (envRefs[i],findResourceEnvRef(envRefs[i]));
        }
    }

}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:76,代码来源:StandardDefaultContext.java


注:本文中的org.apache.catalina.Context.setCookies方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。