Search in sources :

Example 41 with ServletExternalContext

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

the class SendTicketGrantingTicketActionTests method verifyTgtToSetRemovingOldTgt.

@Test
public void verifyTgtToSetRemovingOldTgt() 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);
    request.setCookies(new Cookie("TGT", "test5"));
    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 : Cookie(javax.servlet.http.Cookie) 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)

Example 42 with ServletExternalContext

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

the class AuthenticationViaFormActionTests method verifyRenewWithServiceAndDifferentCredentials.

@Test
public void verifyRenewWithServiceAndDifferentCredentials() throws Exception {
    final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), RegisteredServiceTestUtils.getService(TEST), c);
    final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockRequestContext context = new MockRequestContext();
    WebUtils.putTicketGrantingTicketInScopes(context, ticketGrantingTicket);
    request.addParameter(CasProtocolConstants.PARAMETER_RENEW, "true");
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, RegisteredServiceTestUtils.getService(TEST).getId());
    final Credential c2 = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    putCredentialInRequestScope(context, c2);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, this.action.execute(context).getId());
}
Also used : Credential(org.apereo.cas.authentication.Credential) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) 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) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Example 43 with ServletExternalContext

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

the class AuthenticationViaFormActionTests method verifyRenewWithServiceAndBadCredentials.

@Test
public void verifyRenewWithServiceAndBadCredentials() throws Exception {
    final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    final Service service = RegisteredServiceTestUtils.getService(TEST);
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), service, c);
    final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockRequestContext context = new MockRequestContext();
    WebUtils.putTicketGrantingTicketInScopes(context, ticketGrantingTicket);
    request.addParameter(CasProtocolConstants.PARAMETER_RENEW, "true");
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, service.getId());
    final Credential c2 = CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    putCredentialInRequestScope(context, c2);
    assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, this.action.execute(context).getId());
}
Also used : Credential(org.apereo.cas.authentication.Credential) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Service(org.apereo.cas.authentication.principal.Service) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Example 44 with ServletExternalContext

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

the class AuthenticationViaFormActionTests method verifySuccessfulAuthenticationWithNoService.

@Test
public void verifySuccessfulAuthenticationWithNoService() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockRequestContext context = new MockRequestContext();
    request.addParameter(USERNAME_PARAM, TEST);
    request.addParameter(PASSWORD_PARAM, TEST);
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    putCredentialInRequestScope(context, c);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, 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) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 45 with ServletExternalContext

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

the class AuthenticationViaFormActionTests method verifySuccessfulAuthenticationWithNoServiceAndWarn.

@Test
public void verifySuccessfulAuthenticationWithNoServiceAndWarn() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockRequestContext context = new MockRequestContext();
    request.addParameter(USERNAME_PARAM, TEST);
    request.addParameter(PASSWORD_PARAM, TEST);
    request.addParameter("warn", "true");
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    putCredentialInRequestScope(context, c);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, this.action.execute(context).getId());
    assertNotNull(WebUtils.getTicketGrantingTicketId(context));
    assertNotNull(response.getCookie(this.warnCookieGenerator.getCookieName()));
}
Also used : Credential(org.apereo.cas.authentication.Credential) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

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