@Override public AuthenticationContext build() { return build(null); }
@Override public AuthenticationContext build(final Service service) { final Authentication authentication = buildAuthentication(); if (authentication == null) { LOGGER.info("Authentication context cannot be produced because no authentication is recorded into in the chain. Returning " + "null"); return null; } LOGGER.debug("Building an authentication context for authentication {} and service {}", authentication, service); final DefaultAuthenticationContext ctx = new DefaultAuthenticationContext(authentication, service); ctx.setCredentialProvided(this.providedCredential != null); return ctx; }
private Authentication buildAuthentication() { if (isEmpty()) { LOGGER.warn("No authentication event has been recorded; CAS cannot finalize the authentication context"); return null; } final Map<String, Object> authenticationAttributes = new HashMap<>(); final Map<String, Object> principalAttributes = new HashMap<>(); final AuthenticationBuilder authenticationBuilder = DefaultAuthenticationBuilder.newInstance(); buildAuthenticationHistory(this.authentications, authenticationAttributes, principalAttributes, authenticationBuilder); final Principal primaryPrincipal = getPrimaryPrincipal(this.authentications, principalAttributes); authenticationBuilder.setPrincipal(primaryPrincipal); LOGGER.debug("Determined primary authentication principal to be [{}]", primaryPrincipal); authenticationBuilder.setAttributes(authenticationAttributes); LOGGER.debug("Collected authentication attributes for this context are [{}]", authenticationAttributes); final DateTime dt = DateTime.now(); authenticationBuilder.setAuthenticationDate(dt); LOGGER.debug("Authentication context commenced at [{}]", dt); return authenticationBuilder.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); } }
final Collection<Object> listOfValues = convertValueToCollection(oldValue); listOfValues.add(authn.getAttributes().get(attrName)); authenticationAttributes.put(attrName, listOfValues);
final AuthenticationContextBuilder builder = new DefaultAuthenticationContextBuilder( this.authenticationSystemSupport.getPrincipalElectionStrategy()); final AuthenticationTransaction transaction =
@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(); }
final AuthenticationContextBuilder builder = new DefaultAuthenticationContextBuilder( this.authenticationSystemSupport.getPrincipalElectionStrategy()); final AuthenticationTransaction transaction =
final AuthenticationContextBuilder builder = new DefaultAuthenticationContextBuilder( this.authenticationSystemSupport.getPrincipalElectionStrategy()); final AuthenticationTransaction transaction = AuthenticationTransaction.wrap(credential); final AuthenticationContextBuilder builder = new DefaultAuthenticationContextBuilder( this.authenticationSystemSupport.getPrincipalElectionStrategy()); final AuthenticationTransaction transaction =