use of org.apereo.cas.ticket.TicketGrantingTicketAwareTicket in project cas by apereo.
the class JpaTicketEntityFactory method fromTicket.
/**
* From.
*
* @param ticket the ticket
* @return the jpa ticket entity
*/
@SneakyThrows
public BaseTicketEntity fromTicket(final Ticket ticket) {
val jsonBody = getTicketSerializationManager().serializeTicket(ticket);
val authentication = ticket instanceof AuthenticationAwareTicket ? ((AuthenticationAwareTicket) ticket).getAuthentication() : null;
val parentTicket = ticket instanceof TicketGrantingTicketAwareTicket ? ((TicketGrantingTicketAwareTicket) ticket).getTicketGrantingTicket() : null;
val entity = getEntityClass().getDeclaredConstructor().newInstance();
return entity.setId(ticket.getId()).setParentId(Optional.ofNullable(parentTicket).map(Ticket::getId).orElse(null)).setBody(jsonBody).setType(ticket.getClass().getName()).setPrincipalId(Optional.ofNullable(authentication).map(Authentication::getPrincipal).map(Principal::getId).orElse(null)).setCreationTime(ObjectUtils.defaultIfNull(ticket.getCreationTime(), ZonedDateTime.now(Clock.systemUTC())));
}
use of org.apereo.cas.ticket.TicketGrantingTicketAwareTicket in project cas by apereo.
the class DefaultSingleSignOnParticipationStrategy method isParticipating.
@Override
public boolean isParticipating(final SingleSignOnParticipationRequest ssoRequest) {
if (properties.isRenewAuthnEnabled() && ssoRequest.isRequestingRenewAuthentication()) {
LOGGER.debug("The authentication session is considered renewed.");
return false;
}
val registeredService = getRegisteredService(ssoRequest);
if (registeredService == null) {
return properties.isSsoEnabled();
}
val authentication = getAuthenticationFrom(ssoRequest);
val ca = AuthenticationCredentialsThreadLocalBinder.getCurrentAuthentication();
try {
AuthenticationCredentialsThreadLocalBinder.bindCurrent(authentication);
val isAllowedForSso = registeredService.getAccessStrategy().isServiceAccessAllowedForSso();
LOGGER.trace("Located [{}] in registry. Service access to participate in SSO is set to [{}]", registeredService.getServiceId(), isAllowedForSso);
if (!isAllowedForSso) {
LOGGER.debug("Service [{}] is not authorized to participate in SSO", registeredService.getServiceId());
return false;
}
val ssoPolicy = registeredService.getSingleSignOnParticipationPolicy();
if (ssoPolicy != null) {
val ticketState = getTicketState(ssoRequest);
if (ticketState.isPresent()) {
return ssoPolicy.shouldParticipateInSso(registeredService, (AuthenticationAwareTicket) ticketState.get());
}
}
val tgtPolicy = registeredService.getTicketGrantingTicketExpirationPolicy();
if (tgtPolicy != null) {
val ticketState = getTicketState(ssoRequest);
return tgtPolicy.toExpirationPolicy().map(policy -> !policy.isExpired((TicketGrantingTicketAwareTicket) ticketState.get())).orElse(Boolean.TRUE);
}
} finally {
AuthenticationCredentialsThreadLocalBinder.bindCurrent(ca);
}
return true;
}
Aggregations