protected <T extends Ticket> T produceTicket(final TicketGrantingTicket ticketGrantingTicket,
                                                 final Service service,
                                                 final boolean credentialProvided,
                                                 final String ticketId,
                                                 final Class<T> clazz) {
        val expirationPolicyToUse = determineExpirationPolicyForService(service);
        val result = ticketGrantingTicket.grantServiceTicket(
            ticketId,
            service,
            expirationPolicyToUse,
            credentialProvided,
            serviceTicketSessionTrackingPolicy);
        if (!clazz.isAssignableFrom(result.getClass())) {
            throw new ClassCastException("Result [%s] is of type %s when we were expecting %s".formatted(result, result.getClass(), clazz));
        }
        return (T) result;
    }
The {@link DefaultServiceTicketFactory} is responsible for
creating {@link ServiceTicket} objects.

@author Misagh Moayyed
@since 4.2
core/cas-server-core-tickets-api/src/main/java/org/apereo/cas/ticket/factory/DefaultServiceTicketFactory.java