private CasAuthenticationToken authenticateNow(final Authentication authentication) throws AuthenticationException { try { final Assertion assertion = this.ticketValidator.validate(authentication .getCredentials().toString(), getServiceUrl(authentication)); final UserDetails userDetails = loadUserByAssertion(assertion); userDetailsChecker.check(userDetails); return new CasAuthenticationToken(this.key, userDetails, authentication.getCredentials(), authoritiesMapper.mapAuthorities(userDetails.getAuthorities()), userDetails, assertion); } catch (final TicketValidationException e) { throw new BadCredentialsException(e.getMessage(), e); } }
@Test public void authenticateAllNullService() throws Exception { String serviceUrl = "https://service/context"; ServiceAuthenticationDetails details = mock(ServiceAuthenticationDetails.class); when(details.getServiceUrl()).thenReturn(serviceUrl); TicketValidator validator = mock(TicketValidator.class); when(validator.validate(any(String.class), any(String.class))).thenReturn( new AssertionImpl("rod")); ServiceProperties serviceProperties = makeServiceProperties(); serviceProperties.setAuthenticateAllArtifacts(true); CasAuthenticationProvider cap = new CasAuthenticationProvider(); cap.setAuthenticationUserDetailsService(new MockAuthoritiesPopulator()); cap.setKey("qwerty"); cap.setTicketValidator(validator); cap.setServiceProperties(serviceProperties); cap.afterPropertiesSet(); String ticket = "ST-456"; UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( CasAuthenticationFilter.CAS_STATELESS_IDENTIFIER, ticket); Authentication result = cap.authenticate(token); }
Assertion casAssertion = ticketValidator.validate(ticket, getCasService());
when(details.getServiceUrl()).thenReturn(serviceUrl); TicketValidator validator = mock(TicketValidator.class); when(validator.validate(any(String.class), any(String.class))).thenReturn( new AssertionImpl("rod")); verify(validator).validate(ticket, serviceProperties.getService()); verify(validator, times(2)).validate(ticket, serviceProperties.getService()); verify(validator).validate(ticket, serviceUrl); cap.afterPropertiesSet(); result = cap.authenticate(token); verify(validator, times(2)).validate(ticket, serviceUrl);
@Controller public class MyController { @Autowired private TicketValidator ticketValidator; @RequestMapping(value="/{companyId}/{userId}/ticket", method=POST) public void createTicket(@RequestBody Ticket newTicket, @PathVariable Long companyId, @PathVariable Long userId) { ticketValidator.validate(newTicket, companyId, userId); // do whatever } }
log.debug("Attempting ticket validation with service=" + service + " and ticket=" + ticket); this.assertion = this.ticketValidator.validate(this.ticket.getTicket(), service);
logger.debug("Attempting ticket validation with service={} and ticket={}", service, this.ticket); this.assertion = this.ticketValidator.validate(this.ticket.getName(), service);
final Assertion assertion = this.ticketValidator.validate(ticket, constructServiceUrl(request, response));
final Assertion assertion = this.ticketValidator.validate(ticket, constructServiceUrl(request, response));
final Assertion assertion = this.ticketValidator.validate(ticket, constructServiceUrl(request, response));
assertion = this.ticketValidator.validate(token, service); logger.debug("CAS authentication succeeded."); if (session == null) {
assertion = this.ticketValidator.validate(token, service); logger.debug("CAS authentication succeeded."); if (session == null) {
@Override @SneakyThrows public String build(final String serviceTicketId, final Service service) { val assertion = this.ticketValidator.validate(serviceTicketId, service.getId()); val attributes = new HashMap<String, Object>(assertion.getAttributes()); attributes.putAll(assertion.getPrincipal().getAttributes()); val validUntilDate = FunctionUtils.doIf( assertion.getValidUntilDate() != null, assertion::getValidUntilDate, () -> { val dt = ZonedDateTime.now().plusSeconds(expirationPolicy.getTimeToLive()); return DateTimeUtils.dateOf(dt); }) .get(); return buildJwt(serviceTicketId, service.getId(), assertion.getAuthenticationDate(), assertion.getPrincipal().getName(), validUntilDate, attributes); }
private CasAuthenticationToken authenticateNow(final Authentication authentication) throws AuthenticationException { try { final Assertion assertion = this.ticketValidator.validate(authentication .getCredentials().toString(), getServiceUrl(authentication)); final UserDetails userDetails = loadUserByAssertion(assertion); userDetailsChecker.check(userDetails); return new CasAuthenticationToken(this.key, userDetails, authentication.getCredentials(), authoritiesMapper.mapAuthorities(userDetails.getAuthorities()), userDetails, assertion); } catch (final TicketValidationException e) { throw new BadCredentialsException(e.getMessage(), e); } }
private CasAuthenticationToken authenticateNow(final Authentication authentication) throws AuthenticationException { try { final Assertion assertion = this.ticketValidator.validate(authentication .getCredentials().toString(), getServiceUrl(authentication)); final UserDetails userDetails = loadUserByAssertion(assertion); userDetailsChecker.check(userDetails); return new CasAuthenticationToken(this.key, userDetails, authentication.getCredentials(), authoritiesMapper.mapAuthorities(userDetails.getAuthorities()), userDetails, assertion); } catch (final TicketValidationException e) { throw new BadCredentialsException(e.getMessage(), e); } }
@Override public Authentication validateRequest( final ServletRequest servletRequest, final ServletResponse servletResponse, final boolean mandatory) throws ServerAuthException { final HttpServletRequest request = (HttpServletRequest) servletRequest; final HttpServletResponse response = (HttpServletResponse) servletResponse; CasAuthentication authentication = fetchCachedAuthentication(request); if (authentication != null) { return authentication; } final String ticket = request.getParameter(protocol.getArtifactParameterName()); if (ticket != null && mandatory) { try { logger.debug("Attempting to validate {}", ticket); final Assertion assertion = ticketValidator.validate(ticket, serviceUrl(request, response)); logger.info("Successfully authenticated {}", assertion.getPrincipal()); authentication = new CasAuthentication(this, ticket, assertion); cacheAuthentication(request, authentication); } catch (Exception e) { throw new ServerAuthException("CAS ticket validation failed", e); } } if (authentication != null) { return authentication; } else if (mandatory) { redirectToCas(request, response); return Authentication.SEND_CONTINUE; } return Authentication.UNAUTHENTICATED; }
log.info("avant validation cas"); final Assertion assertion = this.getTicketValidator().validate(ticket, constructServiceUrl(request, response));
Assertion casAssertion = ticketValidator.validate(ticket, getCasService());