Search in sources :

Example 1 with TransientSessionTicketFactory

use of org.apereo.cas.ticket.TransientSessionTicketFactory in project cas by apereo.

the class DelegatedClientWebflowManager method store.

/**
 * Store.
 *
 * @param webContext the web context
 * @param client     the client
 * @return the ticket
 */
public Ticket store(final WebContext webContext, final BaseClient client) {
    final Map<String, Serializable> properties = new LinkedHashMap<>();
    final Service service = determineService(webContext);
    properties.put(CasProtocolConstants.PARAMETER_SERVICE, service);
    properties.put(this.themeParamName, StringUtils.defaultString(webContext.getRequestParameter(this.themeParamName)));
    properties.put(this.localParamName, StringUtils.defaultString(webContext.getRequestParameter(this.localParamName)));
    properties.put(CasProtocolConstants.PARAMETER_METHOD, StringUtils.defaultString(webContext.getRequestParameter(CasProtocolConstants.PARAMETER_METHOD)));
    final TransientSessionTicketFactory transientFactory = (TransientSessionTicketFactory) this.ticketFactory.get(TransientSessionTicket.class);
    final TransientSessionTicket ticket = transientFactory.create(service, properties);
    LOGGER.debug("Storing delegated authentication request ticket [{}] for service [{}] with properties [{}]", ticket.getId(), ticket.getService(), ticket.getProperties());
    this.ticketRegistry.addTicket(ticket);
    webContext.setRequestAttribute(PARAMETER_CLIENT_ID, ticket.getId());
    if (client instanceof SAML2Client) {
        webContext.getSessionStore().set(webContext, SAML2Client.SAML_RELAY_STATE_ATTRIBUTE, ticket.getId());
    }
    if (client instanceof OAuth20Client) {
        final OAuth20Client oauthClient = (OAuth20Client) client;
        oauthClient.getConfiguration().setWithState(true);
        oauthClient.getConfiguration().setStateData(ticket.getId());
    }
    if (client instanceof OidcClient) {
        final OidcClient oidcClient = (OidcClient) client;
        oidcClient.getConfiguration().setCustomParams(CollectionUtils.wrap(PARAMETER_CLIENT_ID, ticket.getId()));
        oidcClient.getConfiguration().setWithState(true);
        oidcClient.getConfiguration().setStateData(ticket.getId());
    }
    if (client instanceof CasClient) {
        final CasClient casClient = (CasClient) client;
        casClient.getConfiguration().addCustomParam(DelegatedClientWebflowManager.PARAMETER_CLIENT_ID, ticket.getId());
    }
    return ticket;
}
Also used : TransientSessionTicket(org.apereo.cas.ticket.TransientSessionTicket) OAuth20Client(org.pac4j.oauth.client.OAuth20Client) Serializable(java.io.Serializable) OidcClient(org.pac4j.oidc.client.OidcClient) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) Service(org.apereo.cas.authentication.principal.Service) SAML2Client(org.pac4j.saml.client.SAML2Client) TransientSessionTicketFactory(org.apereo.cas.ticket.TransientSessionTicketFactory) LinkedHashMap(java.util.LinkedHashMap) CasClient(org.pac4j.cas.client.CasClient)

Example 2 with TransientSessionTicketFactory

use of org.apereo.cas.ticket.TransientSessionTicketFactory in project cas by apereo.

the class DefaultTransientSessionTicketFactoryTests method verifyByServiceById.

@Test
public void verifyByServiceById() {
    val factory = (TransientSessionTicketFactory) this.ticketFactory.get(TransientSessionTicket.class);
    val ticket = factory.create(UUID.randomUUID().toString(), RegisteredServiceTestUtils.getService("example"), Map.of("key", "value"));
    assertNotNull(ticket);
    assertNotNull(ticket.getService());
}
Also used : lombok.val(lombok.val) TransientSessionTicket(org.apereo.cas.ticket.TransientSessionTicket) TransientSessionTicketFactory(org.apereo.cas.ticket.TransientSessionTicketFactory) Test(org.junit.jupiter.api.Test)

Example 3 with TransientSessionTicketFactory

use of org.apereo.cas.ticket.TransientSessionTicketFactory in project cas by apereo.

the class DefaultTransientSessionTicketFactoryTests method verifyById.

@Test
public void verifyById() {
    val factory = (TransientSessionTicketFactory) this.ticketFactory.get(TransientSessionTicket.class);
    val ticket = factory.create(UUID.randomUUID().toString(), Map.of());
    assertNotNull(ticket);
    assertNull(ticket.getService());
}
Also used : lombok.val(lombok.val) TransientSessionTicket(org.apereo.cas.ticket.TransientSessionTicket) TransientSessionTicketFactory(org.apereo.cas.ticket.TransientSessionTicketFactory) Test(org.junit.jupiter.api.Test)

Example 4 with TransientSessionTicketFactory

use of org.apereo.cas.ticket.TransientSessionTicketFactory in project cas by apereo.

the class DefaultTransientSessionTicketFactoryTests method verifyExpirationPolicy.

@Test
public void verifyExpirationPolicy() {
    val factory = (TransientSessionTicketFactory) this.ticketFactory.get(TransientSessionTicket.class);
    val ticket = factory.create(RegisteredServiceTestUtils.getService("example"), new HashMap<>(0));
    assertNotNull(ticket);
    assertEquals(20, ticket.getExpirationPolicy().getTimeToLive());
}
Also used : lombok.val(lombok.val) TransientSessionTicket(org.apereo.cas.ticket.TransientSessionTicket) TransientSessionTicketFactory(org.apereo.cas.ticket.TransientSessionTicketFactory) Test(org.junit.jupiter.api.Test)

Example 5 with TransientSessionTicketFactory

use of org.apereo.cas.ticket.TransientSessionTicketFactory in project cas by apereo.

the class DistributedJEESessionStore method set.

@Override
public void set(final WebContext context, final String key, final Object value) {
    LOGGER.trace("Setting key: [{}]", key);
    val sessionId = getSessionId(context, true).get();
    val properties = new HashMap<String, Serializable>();
    if (value instanceof Serializable) {
        properties.put(key, (Serializable) value);
    } else if (value != null) {
        LOGGER.warn("Object value [{}] assigned to [{}] is not serializable and may not be part of the ticket [{}]", value, key, sessionId);
    }
    val ticket = getTransientSessionTicketForSession(context);
    if (value == null && ticket != null) {
        ticket.getProperties().remove(key);
        FunctionUtils.doUnchecked(s -> this.centralAuthenticationService.updateTicket(ticket));
    } else if (ticket == null) {
        val transientFactory = (TransientSessionTicketFactory) this.ticketFactory.get(TransientSessionTicket.class);
        val created = transientFactory.create(sessionId, properties);
        FunctionUtils.doUnchecked(s -> this.centralAuthenticationService.addTicket(created));
    } else {
        ticket.getProperties().putAll(properties);
        FunctionUtils.doUnchecked(s -> this.centralAuthenticationService.updateTicket(ticket));
    }
}
Also used : lombok.val(lombok.val) TransientSessionTicket(org.apereo.cas.ticket.TransientSessionTicket) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) HashMap(java.util.HashMap) UUID(java.util.UUID) StringUtils(org.apache.commons.lang3.StringUtils) SessionStore(org.pac4j.core.context.session.SessionStore) Serializable(java.io.Serializable) WebContext(org.pac4j.core.context.WebContext) FunctionUtils(org.apereo.cas.util.function.FunctionUtils) Slf4j(lombok.extern.slf4j.Slf4j) TransientSessionTicketFactory(org.apereo.cas.ticket.TransientSessionTicketFactory) CasCookieBuilder(org.apereo.cas.web.cookie.CasCookieBuilder) Optional(java.util.Optional) TicketFactory(org.apereo.cas.ticket.TicketFactory) JEEContext(org.pac4j.core.context.JEEContext) Transactional(org.springframework.transaction.annotation.Transactional) Serializable(java.io.Serializable) HashMap(java.util.HashMap)

Aggregations

TransientSessionTicket (org.apereo.cas.ticket.TransientSessionTicket)12 TransientSessionTicketFactory (org.apereo.cas.ticket.TransientSessionTicketFactory)12 lombok.val (lombok.val)11 Serializable (java.io.Serializable)6 Test (org.junit.jupiter.api.Test)6 Optional (java.util.Optional)3 RequiredArgsConstructor (lombok.RequiredArgsConstructor)3 Slf4j (lombok.extern.slf4j.Slf4j)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Service (org.apereo.cas.authentication.principal.Service)2 TicketFactory (org.apereo.cas.ticket.TicketFactory)2 WebUtils (org.apereo.cas.web.support.WebUtils)2 CasClient (org.pac4j.cas.client.CasClient)2 JEEContext (org.pac4j.core.context.JEEContext)2 WebContext (org.pac4j.core.context.WebContext)2 OAuth20Client (org.pac4j.oauth.client.OAuth20Client)2 OidcClient (org.pac4j.oidc.client.OidcClient)2 SAML2Client (org.pac4j.saml.client.SAML2Client)2