Search in sources :

Example 6 with TransientSessionTicketFactory

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

the class SubmitAccountRegistrationAction method createAccountRegistrationActivationUrl.

/**
 * Create account registration activation url.
 *
 * @param registrationRequest the registration request
 * @return the string
 * @throws Exception the exception
 */
protected String createAccountRegistrationActivationUrl(final AccountRegistrationRequest registrationRequest) throws Exception {
    val token = accountRegistrationService.createToken(registrationRequest);
    val transientFactory = (TransientSessionTicketFactory) ticketFactory.get(TransientSessionTicket.class);
    val properties = CollectionUtils.<String, Serializable>wrap(AccountRegistrationUtils.PROPERTY_ACCOUNT_REGISTRATION_ACTIVATION_TOKEN, token);
    val ticket = transientFactory.create((Service) null, properties);
    ticketRegistry.addTicket(ticket);
    return new URIBuilder(casProperties.getServer().getLoginUrl()).addParameter(AccountRegistrationUtils.REQUEST_PARAMETER_ACCOUNT_REGISTRATION_ACTIVATION_TOKEN, ticket.getId()).build().toURL().toExternalForm();
}
Also used : lombok.val(lombok.val) TransientSessionTicket(org.apereo.cas.ticket.TransientSessionTicket) Serializable(java.io.Serializable) TransientSessionTicketFactory(org.apereo.cas.ticket.TransientSessionTicketFactory) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 7 with TransientSessionTicketFactory

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

the class DefaultDelegatedClientAuthenticationWebflowManager method storeDelegatedClientAuthenticationRequest.

/**
 * Store delegated client authentication request.
 *
 * @param webContext the web context
 * @return the transient session ticket
 * @throws Exception the exception
 */
protected TransientSessionTicket storeDelegatedClientAuthenticationRequest(final JEEContext webContext) throws Exception {
    val properties = buildTicketProperties(webContext);
    val originalService = configContext.getArgumentExtractor().extractService(webContext.getNativeRequest());
    val service = configContext.getAuthenticationRequestServiceSelectionStrategies().resolveService(originalService);
    properties.put(CasProtocolConstants.PARAMETER_SERVICE, originalService);
    properties.put(CasProtocolConstants.PARAMETER_TARGET_SERVICE, service);
    val registeredService = configContext.getServicesManager().findServiceBy(service);
    webContext.getRequestParameter(RedirectionActionBuilder.ATTRIBUTE_FORCE_AUTHN).or(() -> Optional.of(Boolean.toString(RegisteredServiceProperties.DELEGATED_AUTHN_FORCE_AUTHN.isAssignedTo(registeredService)))).filter(value -> StringUtils.equalsIgnoreCase(value, "true")).ifPresent(attr -> properties.put(RedirectionActionBuilder.ATTRIBUTE_FORCE_AUTHN, true));
    webContext.getRequestParameter(RedirectionActionBuilder.ATTRIBUTE_PASSIVE).or(() -> Optional.of(Boolean.toString(RegisteredServiceProperties.DELEGATED_AUTHN_PASSIVE_AUTHN.isAssignedTo(registeredService)))).filter(value -> StringUtils.equalsIgnoreCase(value, "true")).ifPresent(attr -> properties.put(RedirectionActionBuilder.ATTRIBUTE_PASSIVE, true));
    val transientFactory = (TransientSessionTicketFactory) configContext.getTicketFactory().get(TransientSessionTicket.class);
    val ticket = transientFactory.create(originalService, properties);
    LOGGER.debug("Storing delegated authentication request ticket [{}] for service [{}] with properties [{}]", ticket.getId(), ticket.getService(), ticket.getProperties());
    configContext.getCentralAuthenticationService().addTicket(ticket);
    webContext.setRequestAttribute(PARAMETER_CLIENT_ID, ticket.getId());
    if (properties.containsKey(RedirectionActionBuilder.ATTRIBUTE_FORCE_AUTHN)) {
        webContext.setRequestAttribute(RedirectionActionBuilder.ATTRIBUTE_FORCE_AUTHN, true);
    }
    if (properties.containsKey(RedirectionActionBuilder.ATTRIBUTE_PASSIVE)) {
        webContext.setRequestAttribute(RedirectionActionBuilder.ATTRIBUTE_PASSIVE, true);
    }
    return ticket;
}
Also used : lombok.val(lombok.val) CasClient(org.pac4j.cas.client.CasClient) Getter(lombok.Getter) RegisteredServiceProperties(org.apereo.cas.services.RegisteredServiceProperty.RegisteredServiceProperties) RequiredArgsConstructor(lombok.RequiredArgsConstructor) SAML2Client(org.pac4j.saml.client.SAML2Client) HashMap(java.util.HashMap) DelegatedClientAuthenticationWebflowManager(org.apereo.cas.web.flow.DelegatedClientAuthenticationWebflowManager) StringUtils(org.apache.commons.lang3.StringUtils) RequestContext(org.springframework.webflow.execution.RequestContext) SAML2StateGenerator(org.pac4j.saml.state.SAML2StateGenerator) WebContext(org.pac4j.core.context.WebContext) TransientSessionTicketFactory(org.apereo.cas.ticket.TransientSessionTicketFactory) OidcClient(org.pac4j.oidc.client.OidcClient) Client(org.pac4j.core.client.Client) Map(java.util.Map) JEEContext(org.pac4j.core.context.JEEContext) RedirectionActionBuilder(org.pac4j.core.redirect.RedirectionActionBuilder) CasProtocolConstants(org.apereo.cas.CasProtocolConstants) TransientSessionTicket(org.apereo.cas.ticket.TransientSessionTicket) UnauthorizedServiceException(org.apereo.cas.services.UnauthorizedServiceException) lombok.val(lombok.val) Serializable(java.io.Serializable) SamlProtocolConstants(org.apereo.cas.support.saml.SamlProtocolConstants) Slf4j(lombok.extern.slf4j.Slf4j) OAuth10Client(org.pac4j.oauth.client.OAuth10Client) Service(org.apereo.cas.authentication.principal.Service) DelegatedClientAuthenticationConfigurationContext(org.apereo.cas.web.flow.DelegatedClientAuthenticationConfigurationContext) Optional(java.util.Optional) WebUtils(org.apereo.cas.web.support.WebUtils) OAuth20Client(org.pac4j.oauth.client.OAuth20Client) Transactional(org.springframework.transaction.annotation.Transactional) TransientSessionTicket(org.apereo.cas.ticket.TransientSessionTicket) TransientSessionTicketFactory(org.apereo.cas.ticket.TransientSessionTicketFactory)

Example 8 with TransientSessionTicketFactory

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

the class JpaTicketRegistryCleanerTests method verifyTransientTicketCleaning.

@Test
@Order(10)
public void verifyTransientTicketCleaning() throws Exception {
    val tgtFactory = (TicketGrantingTicketFactory) ticketFactory.get(TicketGrantingTicket.class);
    val tgt = tgtFactory.create(RegisteredServiceTestUtils.getAuthentication(), RegisteredServiceTestUtils.getService(), TicketGrantingTicket.class);
    ticketRegistry.addTicket(tgt);
    val transientFactory = (TransientSessionTicketFactory) ticketFactory.get(TransientSessionTicket.class);
    val transientTicket = transientFactory.create(RegisteredServiceTestUtils.getService());
    ticketRegistry.addTicket(transientTicket);
    ticketRegistry.updateTicket(tgt);
    transientTicket.markTicketExpired();
    tgt.markTicketExpired();
    ticketRegistry.updateTicket(transientTicket);
    ticketRegistry.updateTicket(tgt);
    assertEquals(2, ticketRegistry.getTickets().size());
    assertEquals(2, ticketRegistryCleaner.clean());
    assertTrue(ticketRegistry.getTickets().isEmpty());
}
Also used : lombok.val(lombok.val) TransientSessionTicket(org.apereo.cas.ticket.TransientSessionTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) TransientSessionTicketFactory(org.apereo.cas.ticket.TransientSessionTicketFactory) TicketGrantingTicketFactory(org.apereo.cas.ticket.TicketGrantingTicketFactory) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with TransientSessionTicketFactory

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

the class PasswordManagementSingleSignOnParticipationStrategyTests method verifyStrategyWithAValidPmRequest.

@Test
public void verifyStrategyWithAValidPmRequest() throws Exception {
    val ctx = new MockRequestContext();
    val token = passwordManagementService.createToken(PasswordManagementQuery.builder().username("casuser").build());
    val transientFactory = (TransientSessionTicketFactory) ticketFactory.get(TransientSessionTicket.class);
    val serverPrefix = casProperties.getServer().getPrefix();
    val service = webApplicationServiceFactory.createService(serverPrefix);
    val properties = CollectionUtils.<String, Serializable>wrap(PasswordManagementWebflowUtils.FLOWSCOPE_PARAMETER_NAME_TOKEN, token);
    val ticket = transientFactory.create(service, properties);
    ticketRegistry.addTicket(ticket);
    ctx.putRequestParameter(PasswordManagementWebflowUtils.REQUEST_PARAMETER_NAME_PASSWORD_RESET_TOKEN, ticket.getId());
    val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(new MockHttpServletRequest()).requestContext(ctx).build();
    assertFalse(strategy.isParticipating(ssoRequest));
}
Also used : lombok.val(lombok.val) TransientSessionTicket(org.apereo.cas.ticket.TransientSessionTicket) Serializable(java.io.Serializable) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) TransientSessionTicketFactory(org.apereo.cas.ticket.TransientSessionTicketFactory) MockRequestContext(org.springframework.webflow.test.MockRequestContext) Test(org.junit.jupiter.api.Test)

Example 10 with TransientSessionTicketFactory

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

the class DefaultTransientSessionTicketFactoryTests method verifyCustomExpirationPolicy.

@Test
public void verifyCustomExpirationPolicy() {
    val factory = (TransientSessionTicketFactory) this.ticketFactory.get(TransientSessionTicket.class);
    val ticket = factory.create(RegisteredServiceTestUtils.getService("example"), CollectionUtils.wrap(ExpirationPolicy.class.getName(), HardTimeoutExpirationPolicy.builder().timeToKillInSeconds(60).build()));
    assertNotNull(ticket);
    assertEquals(60, 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)

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