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));
}
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());
}
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());
}
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());
}
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()));
}
Aggregations