Example usage for javax.servlet SessionCookieConfig isSecure

List of usage examples for javax.servlet SessionCookieConfig isSecure

Introduction

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

Prototype

public boolean isSecure();

Source Link

Document

Checks if the session tracking cookies created on behalf of the application represented by the <tt>ServletContext</tt> from which this <tt>SessionCookieConfig</tt> was acquired will be marked as <i>secure</i> even if the request that initiated the corresponding session is using plain HTTP instead of HTTPS.

Usage

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

@Test
public void shouldSetSessionCookieConfig() throws Exception {
    when(systemEnvironment.isSessionCookieSecure()).thenReturn(true);
    jetty9Server.configure();//ww  w. j a  va 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));
}