use of org.springframework.webflow.test.MockRequestContext 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.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class RegisteredServiceAuthenticationPolicySingleSignOnParticipationStrategyTests method verifySsoWithHandlers.
@Test
public void verifySsoWithHandlers() throws Exception {
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val svc = RegisteredServiceTestUtils.getRegisteredService("serviceid1", Map.of());
val policy = new DefaultRegisteredServiceAuthenticationPolicy();
policy.setRequiredAuthenticationHandlers(Set.of(SimpleTestUsernamePasswordAuthenticationHandler.class.getSimpleName()));
svc.setAuthenticationPolicy(policy);
val ticketRegistry = new DefaultTicketRegistry();
val strategy = getSingleSignOnStrategy(svc, ticketRegistry);
WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService("serviceid1"));
val tgt = new MockTicketGrantingTicket("casuser");
ticketRegistry.addTicket(tgt);
WebUtils.putTicketGrantingTicketInScopes(context, tgt);
val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(request).requestContext(context).build();
assertTrue(strategy.supports(ssoRequest));
assertTrue(strategy.isParticipating(ssoRequest));
}
use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class RegisteredServiceAuthenticationPolicySingleSignOnParticipationStrategyTests method verifySsoWithExcludedHandlers.
@Test
public void verifySsoWithExcludedHandlers() throws Exception {
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val svc = RegisteredServiceTestUtils.getRegisteredService("serviceid1", Map.of());
val policy = new DefaultRegisteredServiceAuthenticationPolicy();
policy.setCriteria(new ExcludedAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria());
policy.setExcludedAuthenticationHandlers(Set.of(SimpleTestUsernamePasswordAuthenticationHandler.class.getName()));
svc.setAuthenticationPolicy(policy);
val ticketRegistry = new DefaultTicketRegistry();
val strategy = getSingleSignOnStrategy(svc, ticketRegistry);
WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService("serviceid1"));
val tgt = new MockTicketGrantingTicket("casuser");
ticketRegistry.addTicket(tgt);
WebUtils.putTicketGrantingTicketInScopes(context, tgt);
val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(request).requestContext(context).build();
assertTrue(strategy.supports(ssoRequest));
assertFalse(strategy.isParticipating(ssoRequest));
}
use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class RegisteredServiceAuthenticationPolicySingleSignOnParticipationStrategyTests method verifyNoServiceOrPolicy.
@Test
public void verifyNoServiceOrPolicy() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val svc = RegisteredServiceTestUtils.getRegisteredService("serviceid1", Map.of());
val policy = new DefaultRegisteredServiceAuthenticationPolicy();
policy.setCriteria(null);
svc.setAuthenticationPolicy(policy);
val ticketRegistry = new DefaultTicketRegistry();
val strategy = getSingleSignOnStrategy(svc, ticketRegistry);
val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(request).requestContext(context).build();
assertTrue(strategy.isParticipating(ssoRequest));
WebUtils.putRegisteredService(context, svc);
assertEquals(0, strategy.getOrder());
assertFalse(strategy.supports(ssoRequest));
svc.setAuthenticationPolicy(null);
assertTrue(strategy.isParticipating(ssoRequest));
}
use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class RegisteredServiceAuthenticationPolicySingleSignOnParticipationStrategyTests method verifySsoWithMismatchedHandlers.
@Test
public void verifySsoWithMismatchedHandlers() throws Exception {
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val svc = RegisteredServiceTestUtils.getRegisteredService("serviceid1", Map.of());
val policy = new DefaultRegisteredServiceAuthenticationPolicy();
policy.setRequiredAuthenticationHandlers(Set.of("SomeOtherHandler"));
policy.setCriteria(new AllowedAuthenticationHandlersRegisteredServiceAuthenticationPolicyCriteria());
svc.setAuthenticationPolicy(policy);
val ticketRegistry = new DefaultTicketRegistry();
val strategy = getSingleSignOnStrategy(svc, ticketRegistry);
WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService("serviceid1"));
val tgt = new MockTicketGrantingTicket("casuser");
ticketRegistry.addTicket(tgt);
WebUtils.putTicketGrantingTicketInScopes(context, tgt);
val ssoRequest = SingleSignOnParticipationRequest.builder().httpServletRequest(request).requestContext(context).build();
assertTrue(strategy.supports(ssoRequest));
assertFalse(strategy.isParticipating(ssoRequest));
}
Aggregations