Search in sources :

Example 1 with DistributedJEESessionStore

use of org.apereo.cas.pac4j.DistributedJEESessionStore in project cas by apereo.

the class DistributedJEESessionStoreTests method verifyTracking.

@Test
public void verifyTracking() {
    val cookie = casProperties.getSessionReplication().getCookie();
    val cookieGenerator = CookieUtils.buildCookieRetrievingGenerator(cookie);
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val store = new DistributedJEESessionStore(centralAuthenticationService, ticketFactory, cookieGenerator);
    val context = new JEEContext(request, response);
    assertNotNull(request.getSession());
    assertFalse(store.renewSession(context));
    assertTrue(store.buildFromTrackableSession(context, "trackable-session").isPresent());
    assertTrue(store.getTrackableSession(context).isPresent());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JEEContext(org.pac4j.core.context.JEEContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) DistributedJEESessionStore(org.apereo.cas.pac4j.DistributedJEESessionStore) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with DistributedJEESessionStore

use of org.apereo.cas.pac4j.DistributedJEESessionStore in project cas by apereo.

the class DistributedJEESessionStoreTests method verifySetGet.

@Test
public void verifySetGet() {
    val cookie = casProperties.getSessionReplication().getCookie();
    val cookieGenerator = CookieUtils.buildCookieRetrievingGenerator(cookie);
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val store = new DistributedJEESessionStore(centralAuthenticationService, ticketFactory, cookieGenerator);
    val context = new JEEContext(request, response);
    assertTrue(store.getSessionId(context, false).isEmpty());
    store.set(context, "attribute", "test");
    assertTrue(store.getSessionId(context, false).isPresent());
    var value = store.get(context, "attribute");
    assertTrue(value.isPresent());
    assertEquals("test", value.get());
    store.set(context, "attribute", "test2");
    value = store.get(context, "attribute");
    assertTrue(value.isPresent());
    assertEquals("test2", value.get());
    store.set(context, "attribute", null);
    store.set(context, "attribute2", "test3");
    assertFalse(store.get(context, "attribute").isPresent());
    value = store.get(context, "attribute2");
    assertTrue(value.isPresent());
    assertEquals("test3", value.get());
    assertDoesNotThrow(new Executable() {

        @Override
        public void execute() throws Throwable {
            store.set(context, "not-serializable", new NoSerializable());
        }
    });
    store.destroySession(context);
    value = store.get(context, "attribute");
    assertTrue(value.isEmpty());
    assertTrue(store.getSessionId(context, false).isPresent());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JEEContext(org.pac4j.core.context.JEEContext) Executable(org.junit.jupiter.api.function.Executable) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) DistributedJEESessionStore(org.apereo.cas.pac4j.DistributedJEESessionStore) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

lombok.val (lombok.val)2 DistributedJEESessionStore (org.apereo.cas.pac4j.DistributedJEESessionStore)2 Test (org.junit.jupiter.api.Test)2 JEEContext (org.pac4j.core.context.JEEContext)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 Executable (org.junit.jupiter.api.function.Executable)1