use of org.apereo.cas.authentication.principal.Response in project cas by apereo.
the class GoogleAccountsServiceTests method verifyResponse.
@Test
public void verifyResponse() {
final Response resp = googleAccountsServiceResponseBuilder.build(googleAccountsService, "SAMPLE_TICKET", CoreAuthenticationTestUtils.getAuthentication());
assertEquals(DefaultResponse.ResponseType.POST, resp.getResponseType());
final String response = resp.getAttributes().get(SamlProtocolConstants.PARAMETER_SAML_RESPONSE);
assertNotNull(response);
assertTrue(response.contains("NotOnOrAfter"));
final Pattern pattern = Pattern.compile("NotOnOrAfter\\s*=\\s*\"(.+Z)\"");
final Matcher matcher = pattern.matcher(response);
final ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
while (matcher.find()) {
final String onOrAfter = matcher.group(1);
final ZonedDateTime dt = ZonedDateTime.parse(onOrAfter);
assertTrue(dt.isAfter(now));
}
assertTrue(resp.getAttributes().containsKey(SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE));
}
use of org.apereo.cas.authentication.principal.Response in project cas by apereo.
the class RedirectToServiceAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
final WebApplicationService service = WebUtils.getService(requestContext);
LOGGER.debug("Located service [{}] from the context", service);
final Authentication auth = WebUtils.getAuthentication(requestContext);
LOGGER.debug("Located authentication [{}] from the context", auth);
final String serviceTicketId = WebUtils.getServiceTicketFromRequestScope(requestContext);
LOGGER.debug("Located service ticket [{}] from the context", serviceTicketId);
final ResponseBuilder builder = responseBuilderLocator.locate(service);
LOGGER.debug("Located service response builder [{}] for [{}]", builder, service);
final Response response = builder.build(service, serviceTicketId, auth);
LOGGER.debug("Built response [{}] for [{}]", response, service);
return finalizeResponseEvent(requestContext, service, response);
}
use of org.apereo.cas.authentication.principal.Response in project cas by apereo.
the class SamlServiceTests method verifyResponse.
@Test
public void verifyResponse() {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setParameter(SamlProtocolConstants.CONST_PARAM_TARGET, "service");
final SamlService impl = new SamlServiceFactory().createService(request);
final Response response = new SamlServiceResponseBuilder(new DefaultServicesManager(mock(ServiceRegistry.class), mock(ApplicationEventPublisher.class))).build(impl, "ticketId", CoreAuthenticationTestUtils.getAuthentication());
assertNotNull(response);
assertEquals(Response.ResponseType.REDIRECT, response.getResponseType());
assertTrue(response.getUrl().contains(SamlProtocolConstants.CONST_PARAM_ARTIFACT.concat("=")));
}
use of org.apereo.cas.authentication.principal.Response in project cas by apereo.
the class OpenIdServiceTests method verifyExpiredAssociationGetResponse.
@Test
public void verifyExpiredAssociationGetResponse() {
try {
request.removeParameter(OpenIdProtocolConstants.OPENID_ASSOCHANDLE);
request.addParameter(OpenIdProtocolConstants.OPENID_ASSOCHANDLE, association.getHandle());
openIdService = openIdServiceFactory.createService(request);
final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), openIdService);
final String tgt = centralAuthenticationService.createTicketGrantingTicket(ctx).getId();
final String st = centralAuthenticationService.grantServiceTicket(tgt, openIdService, ctx).getId();
centralAuthenticationService.validateServiceTicket(st, openIdService);
synchronized (this) {
try {
this.wait(3000);
} catch (final InterruptedException e) {
throw new AssertionError("Could not wait long enough to check association expiry date");
}
}
final Response response = new OpenIdServiceResponseBuilder(OPEN_ID_PREFIX_URL, serverManager, centralAuthenticationService, new DefaultServicesManager(mock(ServiceRegistry.class), mock(ApplicationEventPublisher.class))).build(openIdService, st, CoreAuthenticationTestUtils.getAuthentication());
assertNotNull(response);
assertEquals(2, response.getAttributes().size());
assertEquals("cancel", response.getAttributes().get(OpenIdProtocolConstants.OPENID_MODE));
} catch (final Exception e) {
LOGGER.debug("Exception during verification of service ticket", e);
}
}
use of org.apereo.cas.authentication.principal.Response in project cas by apereo.
the class RedirectToServiceAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
final WebApplicationService service = WebUtils.getService(requestContext);
final String serviceTicketId = WebUtils.getServiceTicketFromRequestScope(requestContext);
final Response response = responseBuilderLocator.locate(service).build(service, serviceTicketId);
WebUtils.putServiceResponseIntoRequestScope(requestContext, response);
WebUtils.putServiceOriginalUrlIntoRequestScope(requestContext, service);
return new EventFactorySupport().event(this, response.getResponseType().name().toLowerCase());
}
Aggregations