Search in sources :

Example 1 with DefaultAuthenticationResultBuilder

use of org.apereo.cas.authentication.DefaultAuthenticationResultBuilder in project cas by apereo.

the class TicketsResource method createServiceTicket.

/**
     * Create new service ticket.
     *
     * @param requestBody service application/x-www-form-urlencoded value
     * @param tgtId       ticket granting ticket id URI path param
     * @return {@link ResponseEntity} representing RESTful response
     */
@PostMapping(value = "/v1/tickets/{tgtId:.+}", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<String> createServiceTicket(@RequestBody final MultiValueMap<String, String> requestBody, @PathVariable("tgtId") final String tgtId) {
    try {
        final String serviceId = requestBody.getFirst(CasProtocolConstants.PARAMETER_SERVICE);
        final AuthenticationResultBuilder builder = new DefaultAuthenticationResultBuilder(this.authenticationSystemSupport.getPrincipalElectionStrategy());
        final Service service = this.webApplicationServiceFactory.createService(serviceId);
        final AuthenticationResult authenticationResult = builder.collect(this.ticketRegistrySupport.getAuthenticationFrom(tgtId)).build(service);
        final ServiceTicket serviceTicketId = this.centralAuthenticationService.grantServiceTicket(tgtId, service, authenticationResult);
        return new ResponseEntity<>(serviceTicketId.getId(), HttpStatus.OK);
    } catch (final InvalidTicketException e) {
        return new ResponseEntity<>("TicketGrantingTicket could not be found", HttpStatus.NOT_FOUND);
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Service(org.apereo.cas.authentication.principal.Service) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) DefaultAuthenticationResultBuilder(org.apereo.cas.authentication.DefaultAuthenticationResultBuilder) AuthenticationResultBuilder(org.apereo.cas.authentication.AuthenticationResultBuilder) DefaultAuthenticationResultBuilder(org.apereo.cas.authentication.DefaultAuthenticationResultBuilder) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)1 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)1 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)1 AuthenticationResultBuilder (org.apereo.cas.authentication.AuthenticationResultBuilder)1 DefaultAuthenticationResultBuilder (org.apereo.cas.authentication.DefaultAuthenticationResultBuilder)1 Service (org.apereo.cas.authentication.principal.Service)1 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)1 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1