本文整理匯總了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;
}
示例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;
}
示例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));
}
示例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;
}
示例6: getSessionCookieConfig
import javax.servlet.SessionCookieConfig; //導入依賴的package包/類
@Override
public SessionCookieConfig getSessionCookieConfig() {
if (SecurityUtil.isPackageProtectionEnabled()) {
return (SessionCookieConfig)
doPrivileged("getSessionCookieConfig", null);
} else {
return context.getSessionCookieConfig();
}
}
示例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;
}
示例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);
}
示例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;
}
示例10: getSessionCookieConfig
import javax.servlet.SessionCookieConfig; //導入依賴的package包/類
@Override
public SessionCookieConfig getSessionCookieConfig() {
if (SecurityUtil.isPackageProtectionEnabled()) {
return (SessionCookieConfig) doPrivileged("getSessionCookieConfig", null);
} else {
return context.getSessionCookieConfig();
}
}
示例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);
}
};
}
示例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");
}
示例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);
}
示例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());
}
}