Search in sources :

Example 1 with TicketGrantingTicketAwareTicket

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())));
}
Also used : lombok.val(lombok.val) AuthenticationAwareTicket(org.apereo.cas.ticket.AuthenticationAwareTicket) TicketGrantingTicketAwareTicket(org.apereo.cas.ticket.TicketGrantingTicketAwareTicket) Ticket(org.apereo.cas.ticket.Ticket) Authentication(org.apereo.cas.authentication.Authentication) TicketGrantingTicketAwareTicket(org.apereo.cas.ticket.TicketGrantingTicketAwareTicket) AuthenticationAwareTicket(org.apereo.cas.ticket.AuthenticationAwareTicket) SneakyThrows(lombok.SneakyThrows)

Example 2 with TicketGrantingTicketAwareTicket

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;
}
Also used : lombok.val(lombok.val) Ordered(org.springframework.core.Ordered) Setter(lombok.Setter) Getter(lombok.Getter) lombok.val(lombok.val) AuthenticationServiceSelectionPlan(org.apereo.cas.authentication.AuthenticationServiceSelectionPlan) TicketRegistrySupport(org.apereo.cas.ticket.registry.TicketRegistrySupport) AuthenticationAwareTicket(org.apereo.cas.ticket.AuthenticationAwareTicket) AuthenticationCredentialsThreadLocalBinder(org.apereo.cas.authentication.AuthenticationCredentialsThreadLocalBinder) Slf4j(lombok.extern.slf4j.Slf4j) TicketGrantingTicketAwareTicket(org.apereo.cas.ticket.TicketGrantingTicketAwareTicket) TriStateBoolean(org.apereo.cas.util.model.TriStateBoolean) SingleSignOnProperties(org.apereo.cas.configuration.model.core.sso.SingleSignOnProperties) ServicesManager(org.apereo.cas.services.ServicesManager) TicketGrantingTicketAwareTicket(org.apereo.cas.ticket.TicketGrantingTicketAwareTicket)

Aggregations

lombok.val (lombok.val)2 AuthenticationAwareTicket (org.apereo.cas.ticket.AuthenticationAwareTicket)2 TicketGrantingTicketAwareTicket (org.apereo.cas.ticket.TicketGrantingTicketAwareTicket)2 Getter (lombok.Getter)1 Setter (lombok.Setter)1 SneakyThrows (lombok.SneakyThrows)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Authentication (org.apereo.cas.authentication.Authentication)1 AuthenticationCredentialsThreadLocalBinder (org.apereo.cas.authentication.AuthenticationCredentialsThreadLocalBinder)1 AuthenticationServiceSelectionPlan (org.apereo.cas.authentication.AuthenticationServiceSelectionPlan)1 SingleSignOnProperties (org.apereo.cas.configuration.model.core.sso.SingleSignOnProperties)1 ServicesManager (org.apereo.cas.services.ServicesManager)1 Ticket (org.apereo.cas.ticket.Ticket)1 TicketRegistrySupport (org.apereo.cas.ticket.registry.TicketRegistrySupport)1 TriStateBoolean (org.apereo.cas.util.model.TriStateBoolean)1 Ordered (org.springframework.core.Ordered)1