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


Java SessionCookieConfig.getDomain方法代码示例

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


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

示例1: createSessionCookie

import javax.servlet.SessionCookieConfig; //导入方法依赖的package包/类
/**
 * Creates a new session cookie for the given session ID
 *
 * @param context     The Context for the web application
 * @param sessionId   The ID of the session for which the cookie will be
 *                    created
 * @param secure      Should session cookie be configured as secure
 */
public static Cookie createSessionCookie(Context context,
        String sessionId, boolean secure) {

    SessionCookieConfig scc =
        context.getServletContext().getSessionCookieConfig();

    // NOTE: The priority order for session cookie configuration is:
    //       1. Context level configuration
    //       2. Values from SessionCookieConfig
    //       3. Defaults

    Cookie cookie = new Cookie(
            SessionConfig.getSessionCookieName(context), sessionId);
   
    // Just apply the defaults.
    cookie.setMaxAge(scc.getMaxAge());
    cookie.setComment(scc.getComment());
   
    if (context.getSessionCookieDomain() == null) {
        // Avoid possible NPE
        if (scc.getDomain() != null) {
            cookie.setDomain(scc.getDomain());
        }
    } else {
        cookie.setDomain(context.getSessionCookieDomain());
    }

    // Always set secure if the request is secure
    if (scc.isSecure() || secure) {
        cookie.setSecure(true);
    }

    // Always set httpOnly if the context is configured for that
    if (scc.isHttpOnly() || context.getUseHttpOnly()) {
        cookie.setHttpOnly(true);
    }
   
    String contextPath = context.getSessionCookiePath();
    if (contextPath == null || contextPath.length() == 0) {
        contextPath = scc.getPath();
    }
    if (contextPath == null || contextPath.length() == 0) {
        contextPath = context.getEncodedPath();
    }
    if (context.getSessionCookiePathUsesTrailingSlash()) {
        // Handle special case of ROOT context where cookies require a path of
        // '/' but the servlet spec uses an empty string
        // Also ensure the cookies for a context with a path of /foo don't get
        // sent for requests with a path of /foobar
        if (!contextPath.endsWith("/")) {
            contextPath = contextPath + "/";
        }
    } else {
        // Only handle special case of ROOT context where cookies require a
        // path of '/' but the servlet spec uses an empty string
        if (contextPath.length() == 0) {
            contextPath = "/";
        }
    }
    cookie.setPath(contextPath);

    return cookie;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:72,代码来源:ApplicationSessionCookieConfig.java

示例2: createDefaultCookieSerializer

import javax.servlet.SessionCookieConfig; //导入方法依赖的package包/类
private CookieSerializer createDefaultCookieSerializer() {
	DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
	if (this.servletContext != null) {
		SessionCookieConfig sessionCookieConfig = null;
		try {
			sessionCookieConfig = this.servletContext.getSessionCookieConfig();
		}
		catch (UnsupportedOperationException e) {
			this.logger
					.warn("Unable to obtain SessionCookieConfig: " + e.getMessage());
		}
		if (sessionCookieConfig != null) {
			if (sessionCookieConfig.getName() != null) {
				cookieSerializer.setCookieName(sessionCookieConfig.getName());
			}
			if (sessionCookieConfig.getDomain() != null) {
				cookieSerializer.setDomainName(sessionCookieConfig.getDomain());
			}
			if (sessionCookieConfig.getPath() != null) {
				cookieSerializer.setCookiePath(sessionCookieConfig.getPath());
			}
			if (sessionCookieConfig.getMaxAge() != -1) {
				cookieSerializer.setCookieMaxAge(sessionCookieConfig.getMaxAge());
			}
		}
	}
	if (this.usesSpringSessionRememberMeServices) {
		cookieSerializer.setRememberMeRequestAttribute(
				SpringSessionRememberMeServices.REMEMBER_ME_LOGIN_ATTR);
	}
	return cookieSerializer;
}
 
开发者ID:spring-projects,项目名称:spring-session,代码行数:33,代码来源:SpringHttpSessionConfiguration.java

示例3: createSessionCookie

import javax.servlet.SessionCookieConfig; //导入方法依赖的package包/类
/**
 * Creates a new session cookie for the given session ID
 *
 * @param context
 *            The Context for the web application
 * @param sessionId
 *            The ID of the session for which the cookie will be created
 * @param secure
 *            Should session cookie be configured as secure
 */
public static Cookie createSessionCookie(Context context, String sessionId, boolean secure) {

	SessionCookieConfig scc = context.getServletContext().getSessionCookieConfig();

	// NOTE: The priority order for session cookie configuration is:
	// 1. Context level configuration
	// 2. Values from SessionCookieConfig
	// 3. Defaults

	Cookie cookie = new Cookie(SessionConfig.getSessionCookieName(context), sessionId);

	// Just apply the defaults.
	cookie.setMaxAge(scc.getMaxAge());
	cookie.setComment(scc.getComment());

	if (context.getSessionCookieDomain() == null) {
		// Avoid possible NPE
		if (scc.getDomain() != null) {
			cookie.setDomain(scc.getDomain());
		}
	} else {
		cookie.setDomain(context.getSessionCookieDomain());
	}

	// Always set secure if the request is secure
	if (scc.isSecure() || secure) {
		cookie.setSecure(true);
	}

	// Always set httpOnly if the context is configured for that
	if (scc.isHttpOnly() || context.getUseHttpOnly()) {
		cookie.setHttpOnly(true);
	}

	String contextPath = context.getSessionCookiePath();
	if (contextPath == null || contextPath.length() == 0) {
		contextPath = scc.getPath();
	}
	if (contextPath == null || contextPath.length() == 0) {
		contextPath = context.getEncodedPath();
	}
	if (context.getSessionCookiePathUsesTrailingSlash()) {
		// Handle special case of ROOT context where cookies require a path
		// of
		// '/' but the servlet spec uses an empty string
		// Also ensure the cookies for a context with a path of /foo don't
		// get
		// sent for requests with a path of /foobar
		if (!contextPath.endsWith("/")) {
			contextPath = contextPath + "/";
		}
	} else {
		// Only handle special case of ROOT context where cookies require a
		// path of '/' but the servlet spec uses an empty string
		if (contextPath.length() == 0) {
			contextPath = "/";
		}
	}
	cookie.setPath(contextPath);

	return cookie;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:73,代码来源:ApplicationSessionCookieConfig.java

示例4: createSessionCookie

import javax.servlet.SessionCookieConfig; //导入方法依赖的package包/类
/**
 * Creates a new session cookie for the given session ID
 *
 * @param context     The Context for the web application
 * @param sessionId   The ID of the session for which the cookie will be
 *                    created
 * @param secure      Should session cookie be configured as secure
 */
public static Cookie createSessionCookie(Context context,
        String sessionId, boolean secure) {

    SessionCookieConfig scc =
        context.getServletContext().getSessionCookieConfig();

    // NOTE: The priority order for session cookie configuration is:
    //       1. Context level configuration
    //       2. Values from SessionCookieConfig
    //       3. Defaults

    Cookie cookie = new Cookie(getSessionCookieName(context), sessionId);
   
    // Just apply the defaults.
    cookie.setMaxAge(scc.getMaxAge());
    cookie.setComment(scc.getComment());
   
    if (context.getSessionCookieDomain() == null) {
        // Avoid possible NPE
        if (scc.getDomain() != null) {
            cookie.setDomain(scc.getDomain());
        }
    } else {
        cookie.setDomain(context.getSessionCookieDomain());
    }

    // Always set secure if the request is secure
    if (scc.isSecure() || secure) {
        cookie.setSecure(true);
    }

    // Always set httpOnly if the context is configured for that
    if (scc.isHttpOnly() || context.getUseHttpOnly()) {
        cookie.setHttpOnly(true);
    }
   
    String contextPath = context.getSessionCookiePath();
    if (contextPath == null || contextPath.length() == 0) {
        contextPath = scc.getPath();
    }
    if (contextPath == null || contextPath.length() == 0) {
        contextPath = context.getEncodedPath();
    }
    if (context.getSessionCookiePathUsesTrailingSlash()) {
        // Handle special case of ROOT context where cookies require a path of
        // '/' but the servlet spec uses an empty string
        // Also ensure the cookies for a context with a path of /foo don't get
        // sent for requests with a path of /foobar
        if (!contextPath.endsWith("/")) {
            contextPath = contextPath + "/";
        }
    } else {
        // Only handle special case of ROOT context where cookies require a
        // path of '/' but the servlet spec uses an empty string
        if (contextPath.length() == 0) {
            contextPath = "/";
        }
    }
    cookie.setPath(contextPath);

    return cookie;
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:71,代码来源:ApplicationSessionCookieConfig.java


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