Search in sources :

Example 6 with ServletExternalContext

use of org.springframework.webflow.context.servlet.ServletExternalContext in project cas by apereo.

the class AuthenticationViaFormActionTests method verifyFailedAuthenticationWithNoService.

@Test
public void verifyFailedAuthenticationWithNoService() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockRequestContext context = new MockRequestContext();
    request.addParameter(USERNAME_PARAM, TEST);
    request.addParameter(PASSWORD_PARAM, "test2");
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    final Credential c = CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword();
    putCredentialInRequestScope(context, c);
    context.getRequestScope().put("org.springframework.validation.BindException.credentials", new BindException(c, "credential"));
    assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, this.action.execute(context).getId());
}
Also used : Credential(org.apereo.cas.authentication.Credential) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) BindException(org.springframework.validation.BindException) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 7 with ServletExternalContext

use of org.springframework.webflow.context.servlet.ServletExternalContext in project cas by apereo.

the class FrontChannelLogoutActionTests method onSetUp.

@Before
public void onSetUp() throws Exception {
    final DefaultSingleLogoutServiceMessageHandler handler = new DefaultSingleLogoutServiceMessageHandler(new SimpleHttpClientFactoryBean().getObject(), new SamlCompliantLogoutMessageCreator(), servicesManager, new DefaultSingleLogoutServiceLogoutUrlBuilder(), false, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
    final LogoutManagerImpl logoutManager = new LogoutManagerImpl(new SamlCompliantLogoutMessageCreator(), handler, false);
    this.frontChannelLogoutAction = new FrontChannelLogoutAction(logoutManager);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    this.requestContext = mock(RequestContext.class);
    final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
    when(this.requestContext.getExternalContext()).thenReturn(servletExternalContext);
    when(servletExternalContext.getNativeRequest()).thenReturn(request);
    when(servletExternalContext.getNativeResponse()).thenReturn(response);
    final LocalAttributeMap flowScope = new LocalAttributeMap();
    when(this.requestContext.getFlowScope()).thenReturn(flowScope);
    final MockFlowExecutionKey mockFlowExecutionKey = new MockFlowExecutionKey(FLOW_EXECUTION_KEY);
    final MockFlowExecutionContext mockFlowExecutionContext = new MockFlowExecutionContext();
    mockFlowExecutionContext.setKey(mockFlowExecutionKey);
    when(this.requestContext.getFlowExecutionContext()).thenReturn(mockFlowExecutionContext);
}
Also used : DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) LocalAttributeMap(org.springframework.webflow.core.collection.LocalAttributeMap) MockFlowExecutionKey(org.springframework.webflow.test.MockFlowExecutionKey) DefaultSingleLogoutServiceMessageHandler(org.apereo.cas.logout.DefaultSingleLogoutServiceMessageHandler) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DefaultSingleLogoutServiceLogoutUrlBuilder(org.apereo.cas.logout.DefaultSingleLogoutServiceLogoutUrlBuilder) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) SimpleHttpClientFactoryBean(org.apereo.cas.util.http.SimpleHttpClientFactoryBean) MockFlowExecutionContext(org.springframework.webflow.test.MockFlowExecutionContext) SamlCompliantLogoutMessageCreator(org.apereo.cas.logout.SamlCompliantLogoutMessageCreator) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) RequestContext(org.springframework.webflow.execution.RequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) LogoutManagerImpl(org.apereo.cas.logout.LogoutManagerImpl) Before(org.junit.Before)

Example 8 with ServletExternalContext

use of org.springframework.webflow.context.servlet.ServletExternalContext in project cas by apereo.

the class GenerateServiceTicketActionTests method verifyTicketGrantingTicketNotTgtButGateway.

@Test
public void verifyTicketGrantingTicketNotTgtButGateway() throws Exception {
    final MockRequestContext context = new MockRequestContext();
    context.getFlowScope().put(SERVICE_PARAM, RegisteredServiceTestUtils.getService());
    final MockHttpServletRequest request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, SERVICE_PARAM);
    request.addParameter(CasProtocolConstants.PARAMETER_GATEWAY, "true");
    final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
    when(tgt.getId()).thenReturn("bleh");
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    assertEquals(CasWebflowConstants.STATE_ID_GATEWAY, this.action.execute(context).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 9 with ServletExternalContext

use of org.springframework.webflow.context.servlet.ServletExternalContext in project cas by apereo.

the class GenerateServiceTicketActionTests method verifyTicketGrantingTicketExpiredTgt.

@Test
public void verifyTicketGrantingTicketExpiredTgt() throws Exception {
    final MockRequestContext context = new MockRequestContext();
    context.getFlowScope().put(SERVICE_PARAM, RegisteredServiceTestUtils.getService());
    final MockHttpServletRequest request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, SERVICE_PARAM);
    WebUtils.putTicketGrantingTicketInScopes(context, this.ticketGrantingTicket);
    this.ticketGrantingTicket.markTicketExpired();
    assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, this.action.execute(context).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 10 with ServletExternalContext

use of org.springframework.webflow.context.servlet.ServletExternalContext in project cas by apereo.

the class SendTicketGrantingTicketActionTests method verifyTgtToSet.

@Test
public void verifyTgtToSet() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr(LOCALHOST_IP);
    request.setLocalAddr(LOCALHOST_IP);
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    final MockHttpServletResponse response = new MockHttpServletResponse();
    request.addHeader("User-Agent", "Test");
    final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
    when(tgt.getId()).thenReturn(TEST_STRING);
    WebUtils.putTicketGrantingTicketInScopes(this.context, tgt);
    this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    assertEquals(SUCCESS, this.action.execute(this.context).getId());
    request.setCookies(response.getCookies());
    assertEquals(tgt.getId(), this.ticketGrantingTicketCookieGenerator.retrieveCookieValue(request));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Aggregations

ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)48 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)47 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)47 Test (org.junit.Test)44 MockServletContext (org.springframework.mock.web.MockServletContext)43 MockRequestContext (org.springframework.webflow.test.MockRequestContext)40 Event (org.springframework.webflow.execution.Event)13 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)11 Credential (org.apereo.cas.authentication.Credential)7 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)7 Cookie (javax.servlet.http.Cookie)4 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Service (org.apereo.cas.authentication.principal.Service)3 SamlMetadataUIInfo (org.apereo.cas.support.saml.mdui.SamlMetadataUIInfo)3 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)2 Authentication (org.apereo.cas.authentication.Authentication)2 OpenIdService (org.apereo.cas.support.openid.authentication.principal.OpenIdService)2 OpenIdServiceFactory (org.apereo.cas.support.openid.authentication.principal.OpenIdServiceFactory)2 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)2