Search in sources :

Example 1 with BrowserSessionStorage

use of org.apereo.cas.web.BrowserSessionStorage in project cas by apereo.

the class BrowserWebStorageSessionStoreTests method verifyOperation.

@Test
public void verifyOperation() {
    val store = new BrowserWebStorageSessionStore(webflowCipherExecutor);
    val request = new MockHttpServletRequest();
    val ctx = new JEEContext(request, new MockHttpServletResponse());
    store.set(ctx, "key1", "value1");
    store.set(ctx, "key2", List.of("HelloWorld"));
    store.set(ctx, "key3", 1234567);
    store.set(ctx, "dummy", new Dummy());
    var session = store.getTrackableSession(ctx);
    assertTrue(session.isPresent());
    store.renewSession(ctx);
    val trackableSession = (BrowserSessionStorage) session.get();
    store.buildFromTrackableSession(ctx, trackableSession.getPayload());
    assertTrue(store.get(ctx, "key1").isPresent());
    assertTrue(store.get(ctx, "key2").isPresent());
    assertTrue(store.get(ctx, "key3").isPresent());
    assertTrue(store.get(ctx, "dummy").isPresent());
}
Also used : lombok.val(lombok.val) BrowserWebStorageSessionStore(org.apereo.cas.pac4j.BrowserWebStorageSessionStore) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) BrowserSessionStorage(org.apereo.cas.web.BrowserSessionStorage) JEEContext(org.pac4j.core.context.JEEContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with BrowserSessionStorage

use of org.apereo.cas.web.BrowserSessionStorage in project cas by apereo.

the class SSOSamlIdPProfileCallbackHandlerControllerWithBrowserStorageTests method verifyResumeFromStorage.

@Test
public void verifyResumeFromStorage() throws Exception {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val authn = getAuthnRequest();
    authn.setProtocolBinding(SAMLConstants.SAML2_POST_BINDING_URI);
    val xml = SamlUtils.transformSamlObject(openSamlConfigBean, getAuthnRequest()).toString();
    request.getSession().setAttribute(SamlProtocolConstants.PARAMETER_SAML_REQUEST, EncodingUtils.encodeBase64(xml));
    request.getSession().setAttribute(SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE, UUID.randomUUID().toString());
    val context = new MessageContext();
    context.setMessage(getAuthnRequest());
    request.getSession().setAttribute(MessageContext.class.getName(), SamlIdPAuthenticationContext.from(context).encode());
    request.addParameter(CasProtocolConstants.PARAMETER_TICKET, "ST-1234567890");
    val payload = samlIdPDistributedSessionStore.getTrackableSession(new JEEContext(request, response)).map(BrowserSessionStorage.class::cast).map(BrowserSessionStorage::getPayload).orElseThrow();
    request.addParameter(BrowserSessionStorage.KEY_SESSION_STORAGE, payload);
    val mv = controller.handleCallbackProfileRequestPost(response, request);
    assertNull(mv);
    assertEquals(HttpStatus.SC_OK, response.getStatus());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) BrowserSessionStorage(org.apereo.cas.web.BrowserSessionStorage) JEEContext(org.pac4j.core.context.JEEContext) MessageContext(org.opensaml.messaging.context.MessageContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)2 BrowserSessionStorage (org.apereo.cas.web.BrowserSessionStorage)2 Test (org.junit.jupiter.api.Test)2 JEEContext (org.pac4j.core.context.JEEContext)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 BrowserWebStorageSessionStore (org.apereo.cas.pac4j.BrowserWebStorageSessionStore)1 MessageContext (org.opensaml.messaging.context.MessageContext)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1