Example usage for javax.servlet SessionCookieConfig getMaxAge

List of usage examples for javax.servlet SessionCookieConfig getMaxAge

Introduction

In this page you can find the example usage for javax.servlet SessionCookieConfig getMaxAge.

Prototype

public int getMaxAge();

Source Link

Document

Gets the lifetime (in seconds) of the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

Usage

From source file:com.thoughtworks.go.server.Jetty9ServerTest.java

@Test
public void shouldSetSessionCookieConfig() throws Exception {
    when(systemEnvironment.isSessionCookieSecure()).thenReturn(true);
    jetty9Server.configure();// w ww .  j  a v a 2  s.com
    jetty9Server.setSessionConfig();
    jetty9Server.startHandlers();

    WebAppContext webAppContext = (WebAppContext) getLoadedHandlers().get(WebAppContext.class);
    SessionCookieConfig sessionCookieConfig = webAppContext.getSessionHandler().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));
}

From source file:org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration.java

private CookieSerializer createDefaultCookieSerializer() {
    DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
    if (this.servletContext != null) {
        SessionCookieConfig sessionCookieConfig = null;
        try {//from  w w  w .j a v  a 2 s. c om
            sessionCookieConfig = this.servletContext.getSessionCookieConfig();
        } catch (UnsupportedOperationException ex) {
            this.logger.warn("Unable to obtain SessionCookieConfig: " + ex.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;
}