AuthenticationTransaction.wrap(credential); this.authenticationSystemSupport.getAuthenticationTransactionManager().handle(transaction, builder); final AuthenticationContext authenticationContext = builder.build();
/** * 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); } }
@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; }
@Override protected Event doExecute(final RequestContext context) throws Exception { final HttpServletRequest request = WebUtils.getHttpServletRequest(context); final String authTokenValue = request.getParameter(TokenConstants.PARAMETER_NAME_TOKEN); final Service service = WebUtils.getService(context); if (StringUtils.isNotBlank(authTokenValue) && service != null) { try { final Credential credential = new TokenCredential(authTokenValue, service); LOGGER.debug("Received token authentication request {} ", credential); final AuthenticationContextBuilder builder = new DefaultAuthenticationContextBuilder( this.authenticationSystemSupport.getPrincipalElectionStrategy()); final AuthenticationTransaction transaction = AuthenticationTransaction.wrap(credential); this.authenticationSystemSupport.getAuthenticationTransactionManager().handle(transaction, builder); final AuthenticationContext authenticationContext = builder.build(service); final TicketGrantingTicket tgt = this.centralAuthenticationService.createTicketGrantingTicket(authenticationContext); WebUtils.putTicketGrantingTicketInScopes(context, tgt); return success(); } catch (final Exception e) { LOGGER.warn(e.getMessage(), e); } } return error(); }
this.authenticationSystemSupport.getAuthenticationTransactionManager() .handle(transaction, builder); final AuthenticationContext authenticationContext = builder.build(service);