@Override public AuthenticationTransactionManager handle(final AuthenticationTransaction authenticationTransaction, final AuthenticationContextBuilder authenticationContext) throws AuthenticationException { if (!authenticationTransaction.getCredentials().isEmpty()) { final Authentication authentication = this.authenticationManager.authenticate(authenticationTransaction); LOGGER.debug("Successful authentication; Collecting authentication result [{}]", authentication); authenticationContext.collect(authentication); } LOGGER.debug("Transaction ignored since there are no credentials to authenticate"); return this; }
/** * 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 */ @RequestMapping(value = "/v1/tickets/{tgtId:.+}", method = RequestMethod.POST, consumes = MediaType .APPLICATION_FORM_URLENCODED_VALUE) public final ResponseEntity<String> createServiceTicket(@RequestBody final MultiValueMap<String, String> requestBody, @PathVariable("tgtId") final String tgtId) { try { final String serviceId = requestBody.getFirst(CasProtocolConstants.PARAMETER_SERVICE); final AuthenticationContextBuilder builder = new DefaultAuthenticationContextBuilder( this.authenticationSystemSupport.getPrincipalElectionStrategy()); final Service service = this.webApplicationServiceFactory.createService(serviceId); final AuthenticationContext authenticationContext = builder.collect(this.ticketRegistrySupport.getAuthenticationFrom(tgtId)).build(service); final ServiceTicket serviceTicketId = this.centralAuthenticationService.grantServiceTicket(tgtId, service, authenticationContext); 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); } }