use of org.apereo.cas.ticket.TicketGrantingTicket 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.apereo.cas.ticket.TicketGrantingTicket 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.apereo.cas.ticket.TicketGrantingTicket 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.apereo.cas.ticket.TicketGrantingTicket in project cas by apereo.
the class GenerateServiceTicketActionTests method verifyTicketGrantingTicketNoTgt.
@Test
public void verifyTicketGrantingTicketNoTgt() 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);
final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
when(tgt.getId()).thenReturn("bleh");
WebUtils.putTicketGrantingTicketInScopes(context, tgt);
assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, this.action.execute(context).getId());
}
use of org.apereo.cas.ticket.TicketGrantingTicket in project cas by apereo.
the class RegisteredServiceResourceTests method configureCasMockToCreateValidTGT.
private void configureCasMockToCreateValidTGT() throws Exception {
final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
when(tgt.getId()).thenReturn("TGT-1");
when(tgt.getAuthentication()).thenReturn(CoreAuthenticationTestUtils.getAuthentication(CoreAuthenticationTestUtils.getPrincipal("casuser", new HashMap<>(RegisteredServiceTestUtils.getTestAttributes()))));
final Class<TicketGrantingTicket> clazz = TicketGrantingTicket.class;
when(this.casMock.getTicket(anyString(), any(clazz.getClass()))).thenReturn(tgt);
when(this.servicesManager.save(any(RegisteredService.class))).thenReturn(RegisteredServiceTestUtils.getRegisteredService("TEST"));
}
Aggregations