Search in sources :

Example 1 with Response

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));
}
Also used : DefaultResponse(org.apereo.cas.authentication.principal.DefaultResponse) Response(org.apereo.cas.authentication.principal.Response) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.Test)

Example 2 with Response

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);
}
Also used : Response(org.apereo.cas.authentication.principal.Response) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) Authentication(org.apereo.cas.authentication.Authentication) ResponseBuilder(org.apereo.cas.authentication.principal.ResponseBuilder)

Example 3 with 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("=")));
}
Also used : Response(org.apereo.cas.authentication.principal.Response) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) ServiceRegistry(org.apereo.cas.services.ServiceRegistry) DefaultServicesManager(org.apereo.cas.services.DefaultServicesManager) Test(org.junit.Test)

Example 4 with Response

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);
    }
}
Also used : Response(org.apereo.cas.authentication.principal.Response) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) ServiceRegistry(org.apereo.cas.services.ServiceRegistry) DefaultServicesManager(org.apereo.cas.services.DefaultServicesManager) IOException(java.io.IOException) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Example 5 with Response

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());
}
Also used : Response(org.apereo.cas.authentication.principal.Response) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Aggregations

Response (org.apereo.cas.authentication.principal.Response)8 Test (org.junit.Test)6 DefaultServicesManager (org.apereo.cas.services.DefaultServicesManager)4 ServiceRegistry (org.apereo.cas.services.ServiceRegistry)4 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 IOException (java.io.IOException)2 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)2 WebApplicationService (org.apereo.cas.authentication.principal.WebApplicationService)2 ZonedDateTime (java.time.ZonedDateTime)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Authentication (org.apereo.cas.authentication.Authentication)1 DefaultResponse (org.apereo.cas.authentication.principal.DefaultResponse)1 ResponseBuilder (org.apereo.cas.authentication.principal.ResponseBuilder)1 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)1