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();
}
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;
}
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());
}
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));
}
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());
}
Aggregations