use of org.apereo.cas.authentication.principal.WebApplicationServiceResponseBuilder in project cas by apereo.
the class RedirectToServiceActionTests method verifyAction.
@Test
public void verifyAction() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(), context);
WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
val locator = mock(ResponseBuilderLocator.class);
when(locator.locate(any(WebApplicationService.class))).thenReturn(new WebApplicationServiceResponseBuilder(this.servicesManager, this.urlValidator));
val redirectToServiceAction = new RedirectToServiceAction(locator);
val event = redirectToServiceAction.execute(context);
assertEquals(CasWebflowConstants.TRANSITION_ID_REDIRECT, event.getId());
}
use of org.apereo.cas.authentication.principal.WebApplicationServiceResponseBuilder in project cas by apereo.
the class InjectResponseHeadersActionTests method verifyAction.
@Test
public void verifyAction() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(), context);
WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
val locator = mock(ResponseBuilderLocator.class);
when(locator.locate(any(WebApplicationService.class))).thenReturn(new WebApplicationServiceResponseBuilder(this.servicesManager, this.urlValidator));
val redirectToServiceAction = new InjectResponseHeadersAction(locator);
val event = redirectToServiceAction.execute(context);
assertEquals(CasWebflowConstants.STATE_ID_SUCCESS, event.getId());
assertNotNull(response.getHeader(CasProtocolConstants.PARAMETER_SERVICE));
}
use of org.apereo.cas.authentication.principal.WebApplicationServiceResponseBuilder in project cas by apereo.
the class WebApplicationServiceResponseBuilderTests method verifyServiceUrlRedirectOverride.
@Test
public void verifyServiceUrlRedirectOverride() {
val registeredService = mock(RegisteredService.class);
when(registeredService.getId()).thenReturn(1L);
when(registeredService.getServiceId()).thenReturn("https://www.google.com/.+");
when(registeredService.getRedirectUrl()).thenReturn("https://example.org");
val service = mock(WebApplicationService.class);
when(service.getId()).thenReturn("https://www.google.org");
when(service.getOriginalUrl()).thenReturn("https://www.google.org");
val servicesManager = mock(ServicesManager.class);
when(servicesManager.findServiceBy(any(Service.class))).thenReturn(registeredService);
val builder = new WebApplicationServiceResponseBuilder(servicesManager, SimpleUrlValidator.getInstance());
val response = builder.build(service, "SERVICE_TICKET_ID", mock(Authentication.class));
assertNotNull(response);
assertEquals("https://example.org?ticket=SERVICE_TICKET_ID", response.getUrl());
}
Aggregations