@Override
    protected WebApplicationService buildInternal(final WebApplicationService service, final Map<String, String> parameters) {
        val registeredService = servicesManager.findServiceBy(service);
        RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(service, registeredService);
        val tokenAsResponse = RegisteredServiceProperty.RegisteredServiceProperties.TOKEN_AS_SERVICE_TICKET.isAssignedTo(registeredService);
        val ticketIdAvailable = isTicketIdAvailable(parameters);

        if (!tokenAsResponse || !ticketIdAvailable) {
            if (ticketIdAvailable) {
                LOGGER.debug("""
                        Registered service [{}] is not configured to issue JWTs for service tickets.
                        Make sure the service property [{}] is defined and set to true
                        """.stripIndent(),
                    registeredService,
                    RegisteredServiceProperties.TOKEN_AS_SERVICE_TICKET.getPropertyName());
            }
            return super.buildInternal(service, parameters);
        }

        val jwt = generateToken(service, parameters);
        val jwtService = new TokenWebApplicationService(service.getId(), service.getOriginalUrl(), service.getArtifactId());
        jwtService.setFormat(service.getFormat());
        jwtService.setLoggedOutAlready(service.isLoggedOutAlready());

        parameters.put(CasProtocolConstants.PARAMETER_TICKET, jwt);
        parameters.put(Response.ResponseType.REDIRECT.name().toLowerCase(Locale.ENGLISH), Boolean.TRUE.toString());

        return jwtService;
    }
This is {@link TokenWebApplicationServiceResponseBuilder}.

@author Misagh Moayyed
@since 5.1.0
support/cas-server-support-token-tickets/src/main/java/org/apereo/cas/token/authentication/principal/TokenWebApplicationServiceResponseBuilder.java