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