Example usage for java.net CookieManager setCookiePolicy

List of usage examples for java.net CookieManager setCookiePolicy

Introduction

In this page you can find the example usage for java.net CookieManager setCookiePolicy.

Prototype

public void setCookiePolicy(CookiePolicy cookiePolicy) 

Source Link

Document

To set the cookie policy of this cookie manager.

Usage

From source file:test.be.fedict.eid.applet.ControllerTest.java

@Test
public void controllerIdentificationWithAddressAndPhoto() throws Exception {
    // setup//from ww  w .j a  v a  2s .  c om
    Messages messages = new Messages(Locale.getDefault());
    Runtime runtime = new TestRuntime();
    View view = new TestView();
    Controller controller = new Controller(view, runtime, messages);

    // make sure that the session cookies are passed during conversations
    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);

    this.servletHolder.setInitParameter("IncludeAddress", "true");
    this.servletHolder.setInitParameter("IncludePhoto", "true");

    // operate
    controller.run();

    // verify
    LOG.debug("verify...");
    SessionHandler sessionHandler = this.servletTester.getContext().getSessionHandler();
    SessionManager sessionManager = sessionHandler.getSessionManager();
    LOG.debug("session manager type: " + sessionManager.getClass().getName());
    HashSessionManager hashSessionManager = (HashSessionManager) sessionManager;
    LOG.debug("# sessions: " + hashSessionManager.getSessions());
    assertEquals(1, hashSessionManager.getSessions());
    Map<String, HttpSession> sessionMap = hashSessionManager.getSessionMap();
    LOG.debug("session map: " + sessionMap);
    Entry<String, HttpSession> sessionEntry = sessionMap.entrySet().iterator().next();
    HttpSession httpSession = sessionEntry.getValue();
    assertNotNull(httpSession.getAttribute("eid"));
    Identity identity = (Identity) httpSession.getAttribute("eid.identity");
    assertNotNull(identity);
    assertNotNull(identity.name);
    LOG.debug("name: " + identity.name);
    LOG.debug("nationality: " + identity.getNationality());
    LOG.debug("national number: " + identity.getNationalNumber());
    assertNull(httpSession.getAttribute("eid.identifier"));
    assertNotNull(httpSession.getAttribute("eid.address"));
    assertNotNull(httpSession.getAttribute("eid.photo"));
}

From source file:test.be.fedict.eid.applet.ControllerTest.java

@Test
public void controllerKioskMode() throws Exception {
    // setup/*w  w w  .j  a va  2  s  . com*/
    Messages messages = new Messages(Locale.getDefault());
    Runtime runtime = new TestRuntime();
    View view = new TestView();
    Controller controller = new Controller(view, runtime, messages);

    // make sure that the session cookies are passed during conversations
    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);

    this.servletHolder.setInitParameter("Kiosk", "true");

    // operate
    controller.run();

    // verify
    LOG.debug("verify...");
}

From source file:test.be.fedict.eid.applet.ControllerTest.java

@Test
public void controllerAuthentication() throws Exception {
    // setup/*from   w w w  . j  a v a  2  s  .  c  o m*/
    Messages messages = new Messages(Locale.getDefault());
    Runtime runtime = new TestRuntime();
    View view = new TestView();
    Controller controller = new Controller(view, runtime, messages);

    // make sure that the session cookies are passed during conversations
    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);

    this.servletHolder.setInitParameter("AuthenticationServiceClass",
            TestAuthenticationService.class.getName());
    this.servletHolder.setInitParameter("Logoff", "true");

    // operate
    controller.run();

    // verify
    LOG.debug("verify...");
    SessionHandler sessionHandler = this.servletTester.getContext().getSessionHandler();
    SessionManager sessionManager = sessionHandler.getSessionManager();
    LOG.debug("session manager type: " + sessionManager.getClass().getName());
    HashSessionManager hashSessionManager = (HashSessionManager) sessionManager;
    LOG.debug("# sessions: " + hashSessionManager.getSessions());
    assertEquals(1, hashSessionManager.getSessions());
    Map<String, HttpSession> sessionMap = hashSessionManager.getSessionMap();
    LOG.debug("session map: " + sessionMap);
    Entry<String, HttpSession> sessionEntry = sessionMap.entrySet().iterator().next();
    HttpSession httpSession = sessionEntry.getValue();
    assertNotNull(httpSession.getAttribute("eid"));
    assertNull(httpSession.getAttribute("eid.identity"));
    assertNull(httpSession.getAttribute("eid.address"));
    assertNull(httpSession.getAttribute("eid.photo"));
    String identifier = (String) httpSession.getAttribute("eid.identifier");
    assertNotNull(identifier);
    LOG.debug("identifier: " + identifier);
    assertTrue(TestAuthenticationService.called);
}

From source file:test.be.fedict.eid.applet.ControllerTest.java

@Test
public void testAuthnSessionIdChannelBinding() throws Exception {
    // setup/*  ww w. j  a  v a  2 s. c o  m*/
    Messages messages = new Messages(Locale.getDefault());
    Runtime runtime = new TestRuntime();
    View view = new TestView();
    Controller controller = new Controller(view, runtime, messages);

    // make sure that the session cookies are passed during conversations
    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);

    this.servletHolder.setInitParameter("AuthenticationServiceClass",
            TestAuthenticationService.class.getName());
    this.servletHolder.setInitParameter("Logoff", "true");
    this.servletHolder.setInitParameter("SessionIdChannelBinding", "true");

    // operate
    controller.run();

    // verify
    LOG.debug("verify...");
    SessionHandler sessionHandler = this.servletTester.getContext().getSessionHandler();
    SessionManager sessionManager = sessionHandler.getSessionManager();
    LOG.debug("session manager type: " + sessionManager.getClass().getName());
    HashSessionManager hashSessionManager = (HashSessionManager) sessionManager;
    LOG.debug("# sessions: " + hashSessionManager.getSessions());
    assertEquals(1, hashSessionManager.getSessions());
    Map<String, HttpSession> sessionMap = hashSessionManager.getSessionMap();
    LOG.debug("session map: " + sessionMap);
    Entry<String, HttpSession> sessionEntry = sessionMap.entrySet().iterator().next();
    HttpSession httpSession = sessionEntry.getValue();
    assertNotNull(httpSession.getAttribute("eid"));
    assertNull(httpSession.getAttribute("eid.identity"));
    assertNull(httpSession.getAttribute("eid.address"));
    assertNull(httpSession.getAttribute("eid.photo"));
    String identifier = (String) httpSession.getAttribute("eid.identifier");
    assertNotNull(identifier);
    LOG.debug("identifier: " + identifier);
    assertTrue(TestAuthenticationService.called);
}

From source file:test.be.fedict.eid.applet.ControllerTest.java

@Test
public void testAuthnServerCertificateChannelBinding() throws Exception {
    // setup//from   w w w  . jav  a  2  s  .  com
    Messages messages = new Messages(Locale.getDefault());
    Runtime runtime = new TestRuntime();
    View view = new TestView();
    Controller controller = new Controller(view, runtime, messages);

    // make sure that the session cookies are passed during conversations
    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);

    this.servletHolder.setInitParameter("AuthenticationServiceClass",
            TestAuthenticationService.class.getName());
    this.servletHolder.setInitParameter("Logoff", "true");
    File tmpCertFile = File.createTempFile("ssl-server-cert-", ".crt");
    FileUtils.writeByteArrayToFile(tmpCertFile, this.certificate.getEncoded());
    this.servletHolder.setInitParameter("ChannelBindingServerCertificate", tmpCertFile.toString());

    // operate
    controller.run();

    // verify
    LOG.debug("verify...");
    SessionHandler sessionHandler = this.servletTester.getContext().getSessionHandler();
    SessionManager sessionManager = sessionHandler.getSessionManager();
    LOG.debug("session manager type: " + sessionManager.getClass().getName());
    HashSessionManager hashSessionManager = (HashSessionManager) sessionManager;
    LOG.debug("# sessions: " + hashSessionManager.getSessions());
    assertEquals(1, hashSessionManager.getSessions());
    Map<String, HttpSession> sessionMap = hashSessionManager.getSessionMap();
    LOG.debug("session map: " + sessionMap);
    Entry<String, HttpSession> sessionEntry = sessionMap.entrySet().iterator().next();
    HttpSession httpSession = sessionEntry.getValue();
    assertNotNull(httpSession.getAttribute("eid"));
    assertNull(httpSession.getAttribute("eid.identity"));
    assertNull(httpSession.getAttribute("eid.address"));
    assertNull(httpSession.getAttribute("eid.photo"));
    String identifier = (String) httpSession.getAttribute("eid.identifier");
    assertNotNull(identifier);
    LOG.debug("identifier: " + identifier);
    assertTrue(TestAuthenticationService.called);
}

From source file:test.be.fedict.eid.applet.ControllerTest.java

@Test
public void testAuthnHybridChannelBinding() throws Exception {
    // setup// w  w  w  .j a  v  a 2 s. c o m
    Messages messages = new Messages(Locale.getDefault());
    Runtime runtime = new TestRuntime();
    View view = new TestView();
    Controller controller = new Controller(view, runtime, messages);

    // make sure that the session cookies are passed during conversations
    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);

    this.servletHolder.setInitParameter("AuthenticationServiceClass",
            TestAuthenticationService.class.getName());
    this.servletHolder.setInitParameter("Logoff", "true");
    File tmpCertFile = File.createTempFile("ssl-server-cert-", ".crt");
    FileUtils.writeByteArrayToFile(tmpCertFile, this.certificate.getEncoded());
    this.servletHolder.setInitParameter("ChannelBindingServerCertificate", tmpCertFile.toString());
    this.servletHolder.setInitParameter("SessionIdChannelBinding", "true");

    // operate
    controller.run();

    // verify
    LOG.debug("verify...");
    SessionHandler sessionHandler = this.servletTester.getContext().getSessionHandler();
    SessionManager sessionManager = sessionHandler.getSessionManager();
    LOG.debug("session manager type: " + sessionManager.getClass().getName());
    HashSessionManager hashSessionManager = (HashSessionManager) sessionManager;
    LOG.debug("# sessions: " + hashSessionManager.getSessions());
    assertEquals(1, hashSessionManager.getSessions());
    Map<String, HttpSession> sessionMap = hashSessionManager.getSessionMap();
    LOG.debug("session map: " + sessionMap);
    Entry<String, HttpSession> sessionEntry = sessionMap.entrySet().iterator().next();
    HttpSession httpSession = sessionEntry.getValue();
    assertNotNull(httpSession.getAttribute("eid"));
    assertNull(httpSession.getAttribute("eid.identity"));
    assertNull(httpSession.getAttribute("eid.address"));
    assertNull(httpSession.getAttribute("eid.photo"));
    String identifier = (String) httpSession.getAttribute("eid.identifier");
    assertNotNull(identifier);
    LOG.debug("identifier: " + identifier);
    assertTrue(TestAuthenticationService.called);
}