Search in sources :

Example 51 with ServletExternalContext

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

the class InitialFlowSetupActionCookieTests method verifyResettingContextPath.

@Test
public void verifyResettingContextPath() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContextPath(CONST_CONTEXT_PATH);
    final MockRequestContext context = new MockRequestContext();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    this.action.doExecute(context);
    assertEquals(CONST_CONTEXT_PATH + '/', this.warnCookieGenerator.getCookiePath());
    assertEquals(CONST_CONTEXT_PATH + '/', this.tgtCookieGenerator.getCookiePath());
    request.setContextPath(CONST_CONTEXT_PATH_2);
    this.action.doExecute(context);
    assertNotSame(CONST_CONTEXT_PATH_2 + '/', this.warnCookieGenerator.getCookiePath());
    assertNotSame(CONST_CONTEXT_PATH_2 + '/', this.tgtCookieGenerator.getCookiePath());
    assertEquals(CONST_CONTEXT_PATH + '/', this.warnCookieGenerator.getCookiePath());
    assertEquals(CONST_CONTEXT_PATH + '/', this.tgtCookieGenerator.getCookiePath());
}
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 52 with ServletExternalContext

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

the class LogoutActionTests method onSetUp.

@Before
public void onSetUp() {
    this.request = new MockHttpServletRequest();
    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(new MockHttpServletResponse());
    when(this.requestContext.getFlowScope()).thenReturn(new LocalAttributeMap());
    this.serviceManager = new DefaultServicesManager(new InMemoryServiceRegistry(), mock(ApplicationEventPublisher.class));
    this.serviceManager.load();
}
Also used : LocalAttributeMap(org.springframework.webflow.core.collection.LocalAttributeMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) RequestContext(org.springframework.webflow.execution.RequestContext) DefaultServicesManager(org.apereo.cas.services.DefaultServicesManager) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) InMemoryServiceRegistry(org.apereo.cas.services.InMemoryServiceRegistry) Before(org.junit.Before)

Example 53 with ServletExternalContext

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

the class SendTicketGrantingTicketActionSsoTests method verifySsoSessionCookieOnServiceSsoDisallowed.

@Test
public void verifySsoSessionCookieOnServiceSsoDisallowed() throws Exception {
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final WebApplicationService svc = mock(WebApplicationService.class);
    when(svc.getId()).thenReturn("TestSsoFalse");
    final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
    when(tgt.getId()).thenReturn(TEST_STRING);
    request.setCookies(new Cookie("TGT", "test5"));
    WebUtils.putTicketGrantingTicketInScopes(this.context, tgt);
    this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    this.context.getFlowScope().put(CasProtocolConstants.PARAMETER_SERVICE, svc);
    assertEquals(SUCCESS, action.execute(this.context).getId());
    assertEquals(0, response.getCookies().length);
}
Also used : Cookie(javax.servlet.http.Cookie) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Example 54 with ServletExternalContext

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

the class OpenIdSingleSignOnActionTests method verifyBadUsername.

@Test
public void verifyBadUsername() throws Exception {
    final MockRequestContext context = new MockRequestContext();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter(OpenIdProtocolConstants.OPENID_IDENTITY, "fablah");
    request.setParameter(OpenIdProtocolConstants.OPENID_RETURNTO, "http://www.cnn.com");
    final OpenIdServiceFactory factory = new OpenIdServiceFactory("");
    final OpenIdService service = factory.createService(request);
    context.getFlowScope().put("service", service);
    context.getFlowScope().put(WebUtils.PARAMETER_TICKET_GRANTING_TICKET_ID, "tgtId");
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    assertEquals("error", this.action.execute(context).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) OpenIdService(org.apereo.cas.support.openid.authentication.principal.OpenIdService) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) OpenIdServiceFactory(org.apereo.cas.support.openid.authentication.principal.OpenIdServiceFactory) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 55 with ServletExternalContext

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

the class ClientAuthenticationHandlerTests method setUp.

@Before
public void setUp() {
    this.fbClient = new FacebookClient();
    final Clients clients = new Clients(CALLBACK_URL, fbClient);
    this.handler = new ClientAuthenticationHandler("", mock(ServicesManager.class), null, clients);
    this.handler.setTypedIdUsed(true);
    final Credentials credentials = new OAuth20Credentials(null);
    this.clientCredential = new ClientCredential(credentials, fbClient.getName());
    final ServletExternalContext mock = new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse());
    ExternalContextHolder.setExternalContext(mock);
}
Also used : ClientCredential(org.apereo.cas.authentication.principal.ClientCredential) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) FacebookClient(org.pac4j.oauth.client.FacebookClient) OAuth20Credentials(org.pac4j.oauth.credentials.OAuth20Credentials) Clients(org.pac4j.core.client.Clients) OAuth20Credentials(org.pac4j.oauth.credentials.OAuth20Credentials) Credentials(org.pac4j.core.credentials.Credentials) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Before(org.junit.Before)

Aggregations

ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)61 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)60 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)60 Test (org.junit.Test)55 MockServletContext (org.springframework.mock.web.MockServletContext)54 MockRequestContext (org.springframework.webflow.test.MockRequestContext)50 Event (org.springframework.webflow.execution.Event)22 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)15 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)14 Credential (org.apereo.cas.authentication.Credential)7 Cookie (javax.servlet.http.Cookie)6 Service (org.apereo.cas.authentication.principal.Service)5 Clients (org.pac4j.core.client.Clients)5 FacebookClient (org.pac4j.oauth.client.FacebookClient)5 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)4 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)4 MutableAttributeMap (org.springframework.webflow.core.collection.MutableAttributeMap)4 Authentication (org.apereo.cas.authentication.Authentication)3 DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)3 DefaultAuthenticationServiceSelectionStrategy (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy)3