use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.
the class AbstractServiceValidateControllerTests method verifyValidServiceTicketWithDifferentEncodingAndIgnoringCase.
@Test
public void verifyValidServiceTicketWithDifferentEncodingAndIgnoringCase() throws Exception {
final String origSvc = "http://www.jasig.org?param=hello+world";
final Service svc = RegisteredServiceTestUtils.getService(origSvc);
final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), svc);
final TicketGrantingTicket tId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
final ServiceTicket sId = getCentralAuthenticationService().grantServiceTicket(tId.getId(), svc, ctx);
final String reqSvc = "http://WWW.JASIG.ORG?PARAM=hello%20world";
final MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, RegisteredServiceTestUtils.getService(reqSvc).getId());
request.addParameter(CasProtocolConstants.PARAMETER_TICKET, sId.getId());
this.serviceValidateController.setProxyHandler(new Cas10ProxyHandler());
assertTrue(this.serviceValidateController.handleRequestInternal(request, new MockHttpServletResponse()).getView().toString().contains(SUCCESS));
}
use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.
the class AbstractServiceValidateControllerTests method verifyValidServiceTicketWithInvalidPgt.
@Test
public void verifyValidServiceTicketWithInvalidPgt() throws Exception {
final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), SERVICE);
final TicketGrantingTicket tId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
final ServiceTicket sId = getCentralAuthenticationService().grantServiceTicket(tId.getId(), SERVICE, ctx);
final MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, SERVICE.getId());
request.addParameter(CasProtocolConstants.PARAMETER_TICKET, sId.getId());
request.addParameter(CasProtocolConstants.PARAMETER_PROXY_GRANTING_TICKET_URL, "duh");
this.serviceValidateController.setProxyHandler(new Cas10ProxyHandler());
final ModelAndView modelAndView = this.serviceValidateController.handleRequestInternal(request, new MockHttpServletResponse());
assertTrue(modelAndView.getView().toString().contains(SUCCESS));
assertNull(modelAndView.getModel().get(CasProtocolConstants.PARAMETER_PROXY_GRANTING_TICKET_IOU));
}
use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.
the class AbstractServiceValidateControllerTests method verifyValidServiceTicketWithValidPgtAndProxyHandlerFailing.
@Test
public void verifyValidServiceTicketWithValidPgtAndProxyHandlerFailing() throws Exception {
final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), SERVICE);
final TicketGrantingTicket tId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
final ServiceTicket sId = getCentralAuthenticationService().grantServiceTicket(tId.getId(), SERVICE, ctx);
final MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, SERVICE.getId());
request.addParameter(CasProtocolConstants.PARAMETER_TICKET, sId.getId());
request.addParameter(CasProtocolConstants.PARAMETER_PROXY_GRANTING_TICKET_URL, SERVICE.getId());
this.serviceValidateController.setProxyHandler((credential, proxyGrantingTicketId) -> null);
final ModelAndView modelAndView = this.serviceValidateController.handleRequestInternal(request, new MockHttpServletResponse());
assertFalse(modelAndView.getView().toString().contains(SUCCESS));
assertNull(modelAndView.getModel().get(CasProtocolConstants.PARAMETER_PROXY_GRANTING_TICKET_IOU));
}
use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.
the class DefaultTicketRegistryCleaner method cleanInternal.
/**
* Clean tickets.
*/
protected void cleanInternal() {
final Collection<Ticket> ticketsToRemove = ticketRegistry.getTickets().stream().filter(Ticket::isExpired).collect(Collectors.toSet());
LOGGER.debug("[{}] expired tickets found.", ticketsToRemove.size());
int count = 0;
for (final Ticket ticket : ticketsToRemove) {
if (ticket instanceof TicketGrantingTicket) {
LOGGER.debug("Cleaning up expired ticket-granting ticket [{}]", ticket.getId());
logoutManager.performLogout((TicketGrantingTicket) ticket);
count += ticketRegistry.deleteTicket(ticket.getId());
} else if (ticket instanceof ServiceTicket) {
LOGGER.debug("Cleaning up expired service ticket [{}]", ticket.getId());
count += ticketRegistry.deleteTicket(ticket.getId());
} else {
LOGGER.warn("Unknown ticket type [{}] found to clean", ticket.getClass().getSimpleName());
}
}
LOGGER.info("[{}] expired tickets removed.", count);
}
use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.
the class DistributedTicketRegistryTests method verifyUpdateOfRegistry.
@Test
public void verifyUpdateOfRegistry() throws AbstractTicketException {
final TicketGrantingTicket t = new TicketGrantingTicketImpl(TGT_ID, CoreAuthenticationTestUtils.getAuthentication(), new NeverExpiresExpirationPolicy());
this.ticketRegistry.addTicket(t);
final TicketGrantingTicket returned = (TicketGrantingTicket) this.ticketRegistry.getTicket(TGT_ID);
final ServiceTicket s = returned.grantServiceTicket("test2", RegisteredServiceTestUtils.getService(), new NeverExpiresExpirationPolicy(), false, true);
this.ticketRegistry.addTicket(s);
final ServiceTicket s2 = (ServiceTicket) this.ticketRegistry.getTicket("test2");
assertNotNull(s2.grantProxyGrantingTicket("ff", CoreAuthenticationTestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()));
assertTrue(s2.isValidFor(RegisteredServiceTestUtils.getService()));
assertTrue(this.wasTicketUpdated);
returned.markTicketExpired();
assertTrue(t.isExpired());
}
Aggregations