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


Java SessionCookieConfig类代码示例

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


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

示例1: getConfiguredSessionCookieName

import javax.servlet.SessionCookieConfig; //导入依赖的package包/类
private static String getConfiguredSessionCookieName(Context context) {

        // Priority is:
        // 1. Cookie name defined in context
        // 2. Cookie name configured for app
        // 3. Default defined by spec
        if (context != null) {
            String cookieName = context.getSessionCookieName();
            if (cookieName != null && cookieName.length() > 0) {
                return cookieName;
            }

            SessionCookieConfig scc =
                context.getServletContext().getSessionCookieConfig();
            cookieName = scc.getName();
            if (cookieName != null && cookieName.length() > 0) {
                return cookieName;
            }
        }

        return null;
    }
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:23,代码来源:SessionConfig.java

示例2: getConfiguredSessionCookieName

import javax.servlet.SessionCookieConfig; //导入依赖的package包/类
private static String getConfiguredSessionCookieName(Context context) {

		// Priority is:
		// 1. Cookie name defined in context
		// 2. Cookie name configured for app
		// 3. Default defined by spec
		if (context != null) {
			String cookieName = context.getSessionCookieName();
			if (cookieName != null && cookieName.length() > 0) {
				return cookieName;
			}

			SessionCookieConfig scc = context.getServletContext().getSessionCookieConfig();
			cookieName = scc.getName();
			if (cookieName != null && cookieName.length() > 0) {
				return cookieName;
			}
		}

		return null;
	}
 
开发者ID:how2j,项目名称:lazycat,代码行数:22,代码来源:SessionConfig.java

示例3: configureSessionCookie

import javax.servlet.SessionCookieConfig; //导入依赖的package包/类
private void configureSessionCookie(SessionCookieConfig config) {
	Cookie cookie = this.session.getCookie();
	if (cookie.getName() != null) {
		config.setName(cookie.getName());
	}
	if (cookie.getDomain() != null) {
		config.setDomain(cookie.getDomain());
	}
	if (cookie.getPath() != null) {
		config.setPath(cookie.getPath());
	}
	if (cookie.getComment() != null) {
		config.setComment(cookie.getComment());
	}
	if (cookie.getHttpOnly() != null) {
		config.setHttpOnly(cookie.getHttpOnly());
	}
	if (cookie.getSecure() != null) {
		config.setSecure(cookie.getSecure());
	}
	if (cookie.getMaxAge() != null) {
		config.setMaxAge(cookie.getMaxAge());
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:25,代码来源:ServerProperties.java

示例4: shouldSetSessionCookieConfig

import javax.servlet.SessionCookieConfig; //导入依赖的package包/类
@Test
public void shouldSetSessionCookieConfig() throws Exception {
    when(systemEnvironment.isSessionCookieSecure()).thenReturn(true);
    jetty9Server.configure();
    jetty9Server.setSessionConfig();

    WebAppContext webAppContext = getWebAppContext(jetty9Server);
    SessionCookieConfig sessionCookieConfig = webAppContext.getSessionHandler().getSessionManager().getSessionCookieConfig();
    assertThat(sessionCookieConfig.isHttpOnly(), is(true));
    assertThat(sessionCookieConfig.isSecure(), is(true));
    assertThat(sessionCookieConfig.getMaxAge(), is(5678));

    when(systemEnvironment.isSessionCookieSecure()).thenReturn(false);
    jetty9Server.setSessionConfig();
    assertThat(sessionCookieConfig.isSecure(), is(false));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:17,代码来源:Jetty9ServerTest.java

示例5: getConfiguredSessionCookieName

import javax.servlet.SessionCookieConfig; //导入依赖的package包/类
private static String getConfiguredSessionCookieName(Context context) {
    
    // Priority is:
    // 1. Cookie name defined in context
    // 2. Cookie name configured for app
    // 3. Default defined by spec
    if (context != null) {
        String cookieName = context.getSessionCookieName();
        if (cookieName != null && cookieName.length() > 0) {
            return cookieName;
        }
        
        SessionCookieConfig scc =
            context.getServletContext().getSessionCookieConfig();
        cookieName = scc.getName();
        if (cookieName != null && cookieName.length() > 0) {
            return cookieName;
        }
    }

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

示例6: getSessionCookieConfig

import javax.servlet.SessionCookieConfig; //导入依赖的package包/类
@Override
public SessionCookieConfig getSessionCookieConfig() {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (SessionCookieConfig)
            doPrivileged("getSessionCookieConfig", null);
    } else {
        return context.getSessionCookieConfig();
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:10,代码来源:ApplicationContextFacade.java

示例7: 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

示例8: configure

import javax.servlet.SessionCookieConfig; //导入依赖的package包/类
/**
 * Configures the cookies 🍪
 *
 * @param config cookie configuration
 * @param cookieName the name of the cookies
 * @see SessionCookieConfig#setName(String)
 * @see SessionCookieConfig#setMaxAge(int)
 */
public static void configure(SessionCookieConfig config, String cookieName) {

	// Change the name of the cookie
	config.setName(cookieName);

	// Change the lifetime of the cookie session: it should not be greater than the lifetime of the JWT tokens
	String expiration = QfsProperties.loadProperties("jwt.properties").getProperty(JwtConfig.EXPIRATION_PROPERTY);

	int maxAge = null != expiration ? Integer.parseInt(expiration): JwtConfig.DEFAULT_EXPIRATION;
	config.setMaxAge(maxAge);
}
 
开发者ID:activeviam,项目名称:autopivot,代码行数:20,代码来源:CookieUtil.java

示例9: getSessionCookieConfig

import javax.servlet.SessionCookieConfig; //导入依赖的package包/类
@Override
public SessionCookieConfig getSessionCookieConfig()
{
    if (!_enabled)
        throw new UnsupportedOperationException();

    if (_sessionHandler!=null)
        return _sessionHandler.getSessionManager().getSessionCookieConfig();
    return null;
}
 
开发者ID:xiaomin0322,项目名称:marathon-auth-plugin,代码行数:11,代码来源:ServletContextHandler.java

示例10: getSessionCookieConfig

import javax.servlet.SessionCookieConfig; //导入依赖的package包/类
@Override
public SessionCookieConfig getSessionCookieConfig() {
	if (SecurityUtil.isPackageProtectionEnabled()) {
		return (SessionCookieConfig) doPrivileged("getSessionCookieConfig", null);
	} else {
		return context.getSessionCookieConfig();
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:9,代码来源:ApplicationContextFacade.java

示例11: customizeSessionProperties

import javax.servlet.SessionCookieConfig; //导入依赖的package包/类
@Test
public void customizeSessionProperties() throws Exception {
	Map<String, String> map = new HashMap<String, String>();
	map.put("server.session.timeout", "123");
	map.put("server.session.tracking-modes", "cookie,url");
	map.put("server.session.cookie.name", "testname");
	map.put("server.session.cookie.domain", "testdomain");
	map.put("server.session.cookie.path", "/testpath");
	map.put("server.session.cookie.comment", "testcomment");
	map.put("server.session.cookie.http-only", "true");
	map.put("server.session.cookie.secure", "true");
	map.put("server.session.cookie.max-age", "60");
	bindProperties(map);
	ConfigurableEmbeddedServletContainer factory = mock(
			ConfigurableEmbeddedServletContainer.class);
	ServletContext servletContext = mock(ServletContext.class);
	SessionCookieConfig sessionCookieConfig = mock(SessionCookieConfig.class);
	given(servletContext.getSessionCookieConfig()).willReturn(sessionCookieConfig);
	this.properties.customize(factory);
	triggerInitializers(factory, servletContext);
	verify(factory).setSessionTimeout(123);
	verify(servletContext).setSessionTrackingModes(
			EnumSet.of(SessionTrackingMode.COOKIE, SessionTrackingMode.URL));
	verify(sessionCookieConfig).setName("testname");
	verify(sessionCookieConfig).setDomain("testdomain");
	verify(sessionCookieConfig).setPath("/testpath");
	verify(sessionCookieConfig).setComment("testcomment");
	verify(sessionCookieConfig).setHttpOnly(true);
	verify(sessionCookieConfig).setSecure(true);
	verify(sessionCookieConfig).setMaxAge(60);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:32,代码来源:ServerPropertiesTests.java

示例12: servletContextInitializer

import javax.servlet.SessionCookieConfig; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Bean
public ServletContextInitializer servletContextInitializer() {
	return new ServletContextInitializer() {
		@Override
		public void onStartup(ServletContext servletContext) throws ServletException {
			servletContext.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE));
			SessionCookieConfig sessionCookieConfig = servletContext.getSessionCookieConfig();
			sessionCookieConfig.setHttpOnly(true);
		}
	};

}
 
开发者ID:rafaelrpinto,项目名称:VulnerableJavaWebApplication,代码行数:14,代码来源:AppLauncher.java

示例13: contextInitialized

import javax.servlet.SessionCookieConfig; //导入依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent e) {
    System.setProperty(ApplicationConstants.CLIENT_DEFAULT_IMPL, ExtendedLinkedInApiClient.class.getName());

    DateTimeZone.setDefault(DateTimeZone.UTC);
    Locale.setDefault(Locale.ENGLISH);
    SessionCookieConfig sessionCookieConfig = e.getServletContext().getSessionCookieConfig();
    sessionCookieConfig.setHttpOnly(true);
    try {
        LogManager.getLogManager().readConfiguration(e.getServletContext().getResourceAsStream("/WEB-INF/classes/logging.properties"));
    } catch (IOException ex) {
        throw new IllegalStateException("Failed to initialize java.util.logging", ex);
    }
    ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(e.getServletContext());
    Map<String, VideoExtractor> videoExtractors = ctx.getBeansOfType(VideoExtractor.class);
    WebUtils.videoExtractors.addAll(videoExtractors.values());

    Map<String, PictureProvider> pictureProviders = ctx.getBeansOfType(PictureProvider.class);
    WebUtils.pictureProviders.addAll(pictureProviders.values());

    Map<String, UrlShorteningService> urlShorteners = ctx.getBeansOfType(UrlShorteningService.class);
    WebUtils.urlShorteners.addAll(urlShorteners.values());

    initializeSocialNetworks(e.getServletContext());

    logger.info("Welshare startup successful");
}
 
开发者ID:Glamdring,项目名称:welshare,代码行数:28,代码来源:StartupListener.java

示例14: checkHttps

import javax.servlet.SessionCookieConfig; //导入依赖的package包/类
@Test
public void checkHttps() {
	ServletContext sc = mock(ServletContext.class);
	when(req.getServletContext()).thenReturn(sc);

	SessionCookieConfig scc = mock(SessionCookieConfig.class);
	when(sc.getSessionCookieConfig()).thenReturn(scc);

	applConfCtrl.checkHttpsConfiguration(req);
}
 
开发者ID:digitalfondue,项目名称:lavagna,代码行数:11,代码来源:ApplicationConfigurationControllerTest.java

示例15: setSecureCookie

import javax.servlet.SessionCookieConfig; //导入依赖的package包/类
@PostConstruct
public void setSecureCookie() {
    SessionCookieConfig sessionCookieConfig = servletContext.getSessionCookieConfig();

    // servletContext is mocked in integrationTests so it will return null.
    if (sessionCookieConfig != null) {
        sessionCookieConfig.setSecure(!disableSecureCookie());
    }

}
 
开发者ID:solita,项目名称:kansalaisaloite,代码行数:11,代码来源:AppConfiguration.java


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