support/cas-server-support-actions/src/main/java/org/apereo/cas/web/flow/GenerateServiceTicketAction.java
/**
     * {@inheritDoc}
     * <p>
     * In the initial primary authentication flow, credentials are cached and available.
     * Since they are authenticated as part of submission first, there is no need to doubly
     * authenticate and verify credentials.
     * <p>
     * In subsequent authentication flows where a TGT is available and only an ST needs to be
     * created, there are no cached copies of the credential, since we do have a TGT available.
     * So we will simply grab the available authentication and produce the final result based on that.
     */

In the initial primary authentication flow, credentials are cached and available.
Since they are authenticated as part of submission first, there is no need to doubly
authenticate and verify credentials.

In subsequent authentication flows where a TGT is available and only an ST needs to be
created, there are no cached copies of the credential, since we do have a TGT available.
So we will simply grab the available authentication and produce the final result based on that.
In the initial primary authentication flow credentials are cached and available . Since they are authenticated as part of submission first there is no need to doubly authenticate and verify credentials . In subsequent authentication flows where a TGT is available and only an ST needs to be created there are no cached copies of the credential since we do have a TGT available . So we will simply grab the available authentication and produce the final result based on that .
@Override
    protected Event doExecute(final RequestContext context) {
        final Service service = WebUtils.getService(context);
        final String ticketGrantingTicket = WebUtils.getTicketGrantingTicketId(context);
        try {
            final Authentication authentication = this.ticketRegistrySupport.getAuthenticationFrom(ticketGrantingTicket);
            if (authentication == null) {
                throw new InvalidTicketException(
                        new AuthenticationException("No authentication found for ticket " + ticketGrantingTicket), ticketGrantingTicket);
            }
            final RegisteredService registeredService = servicesManager.findServiceBy(service);
            WebUtils.putRegisteredService(context, registeredService);
            WebUtils.putService(context, service);
            WebUtils.putUnauthorizedRedirectUrlIntoFlowScope(context,
                    registeredService.getAccessStrategy().getUnauthorizedRedirectUrl());
            if (WebUtils.getWarningCookie(context)) {
                return result(CasWebflowConstants.STATE_ID_WARN);
            }
            final AuthenticationResultBuilder authenticationResultBuilder = this.authenticationSystemSupport
                    .establishAuthenticationContextFromInitial(authentication);
            final AuthenticationResult authenticationResult = authenticationResultBuilder.build(service);
            final ServiceTicket serviceTicketId = this.centralAuthenticationService
                    .grantServiceTicket(ticketGrantingTicket, service, authenticationResult);
            WebUtils.putServiceTicketInRequestScope(context, serviceTicketId);
            return success();
        } catch (final AbstractTicketException e) {
            if (e instanceof InvalidTicketException) {
                this.centralAuthenticationService.destroyTicketGrantingTicket(ticketGrantingTicket);
            }
            if (isGatewayPresent(context)) {
                return result(CasWebflowConstants.STATE_ID_GATEWAY);
            }
            return newEvent(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, e);
        }
    }
@ Override protected Event doExecute ( final RequestContext context ) { final Service service = WebUtils . getService ( context ) ; final String ticketGrantingTicket = WebUtils . getTicketGrantingTicketId ( context ) ; try { final Authentication authentication = this . ticketRegistrySupport . getAuthenticationFrom ( ticketGrantingTicket ) ; if ( authentication == null ) { throw new InvalidTicketException ( new AuthenticationException ( "No authentication found for ticket " + ticketGrantingTicket ) , ticketGrantingTicket ) ; } final RegisteredService registeredService = servicesManager . findServiceBy ( service ) ; WebUtils . putRegisteredService ( context , registeredService ) ; WebUtils . putService ( context , service ) ; WebUtils . putUnauthorizedRedirectUrlIntoFlowScope ( context , registeredService . getAccessStrategy ( ) . getUnauthorizedRedirectUrl ( ) ) ; if ( WebUtils . getWarningCookie ( context ) ) { return result ( CasWebflowConstants . STATE_ID_WARN ) ; } final AuthenticationResultBuilder authenticationResultBuilder = this . authenticationSystemSupport . establishAuthenticationContextFromInitial ( authentication ) ; final AuthenticationResult authenticationResult = authenticationResultBuilder . build ( service ) ; final ServiceTicket serviceTicketId = this . centralAuthenticationService . grantServiceTicket ( ticketGrantingTicket , service , authenticationResult ) ; WebUtils . putServiceTicketInRequestScope ( context , serviceTicketId ) ; return success ( ) ; } catch ( final AbstractTicketException e ) { if ( e instanceof InvalidTicketException ) { this . centralAuthenticationService . destroyTicketGrantingTicket ( ticketGrantingTicket ) ; } if ( isGatewayPresent ( context ) ) { return result ( CasWebflowConstants . STATE_ID_GATEWAY ) ; } return newEvent ( CasWebflowConstants . TRANSITION_ID_AUTHENTICATION_FAILURE , e ) ; } }
{@inheritDoc}
 <p>
 In the initial primary authentication flow, credentials are cached and available.
{ @inheritDoc } <p > In the initial primary authentication flow credentials are cached and available .