use of org.apereo.cas.ticket.proxy.ProxyTicket in project cas by apereo.
the class JpaTicketRegistryTests method verifyTicketCreationAndDeletion.
@Test
public void verifyTicketCreationAndDeletion() {
// TGT
final TicketGrantingTicket newTgt = newTGT();
addTicketInTransaction(newTgt);
TicketGrantingTicket tgtFromDb = (TicketGrantingTicket) getTicketInTransaction(newTgt.getId());
assertNotNull(tgtFromDb);
assertEquals(newTgt.getId(), tgtFromDb.getId());
// ST
final ServiceTicket newSt = grantServiceTicketInTransaction(tgtFromDb);
final ServiceTicket stFromDb = (ServiceTicket) getTicketInTransaction(newSt.getId());
assertNotNull(stFromDb);
assertEquals(newSt.getId(), stFromDb.getId());
// PGT
final ProxyGrantingTicket newPgt = grantProxyGrantingTicketInTransaction(stFromDb);
updateTicketInTransaction(stFromDb.getTicketGrantingTicket());
final ProxyGrantingTicket pgtFromDb = (ProxyGrantingTicket) getTicketInTransaction(newPgt.getId());
assertNotNull(pgtFromDb);
assertEquals(newPgt.getId(), pgtFromDb.getId());
tgtFromDb = (TicketGrantingTicket) getTicketInTransaction(newTgt.getId());
assertNotNull(tgtFromDb);
assertEquals(1, tgtFromDb.getProxyGrantingTickets().size());
// PT
final ProxyTicket newPt = grantProxyTicketInTransaction(pgtFromDb);
final ProxyTicket ptFromDb = (ProxyTicket) getTicketInTransaction(newPt.getId());
assertNotNull(ptFromDb);
assertEquals(newPt.getId(), ptFromDb.getId());
// ST 2
final ServiceTicket newSt2 = grantServiceTicketInTransaction(tgtFromDb);
final ServiceTicket st2FromDb = (ServiceTicket) getTicketInTransaction(newSt2.getId());
assertNotNull(st2FromDb);
assertEquals(newSt2.getId(), st2FromDb.getId());
// PGT 2
final ProxyGrantingTicket newPgt2 = grantProxyGrantingTicketInTransaction(st2FromDb);
updateTicketInTransaction(st2FromDb.getTicketGrantingTicket());
final ProxyGrantingTicket pgt2FromDb = (ProxyGrantingTicket) getTicketInTransaction(newPgt2.getId());
assertNotNull(pgt2FromDb);
assertEquals(newPgt2.getId(), pgt2FromDb.getId());
tgtFromDb = (TicketGrantingTicket) getTicketInTransaction(newTgt.getId());
assertNotNull(tgtFromDb);
assertEquals(2, tgtFromDb.getProxyGrantingTickets().size());
// delete PGT 2
deleteTicketInTransaction(pgt2FromDb.getId());
assertNull(getTicketInTransaction(newPgt2.getId()));
tgtFromDb = (TicketGrantingTicket) getTicketInTransaction(newTgt.getId());
assertNotNull(tgtFromDb);
assertEquals(1, tgtFromDb.getProxyGrantingTickets().size());
// delete ticket hierarchy
tgtFromDb = (TicketGrantingTicket) getTicketInTransaction(newTgt.getId());
assertNotNull(tgtFromDb);
deleteTicketInTransaction(tgtFromDb.getId());
assertNull(getTicketInTransaction(newTgt.getId()));
assertNull(getTicketInTransaction(newSt.getId()));
assertNull(getTicketInTransaction(newPgt.getId()));
assertNull(getTicketInTransaction(newPt.getId()));
}
use of org.apereo.cas.ticket.proxy.ProxyTicket in project cas by apereo.
the class ProxyController method handleRequestInternal.
/**
* Handle request internal.
*
* @param request the request
* @param response the response
* @return ModelAndView containing a view name of either
* {@code casProxyFailureView} or {@code casProxySuccessView}
*/
@Override
@GetMapping(path = "/proxy")
protected ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) {
final String proxyGrantingTicket = request.getParameter(CasProtocolConstants.PARAMETER_PROXY_GRANTING_TICKET);
final Service targetService = getTargetService(request);
if (!StringUtils.hasText(proxyGrantingTicket) || targetService == null) {
return generateErrorView(CasProtocolConstants.ERROR_CODE_INVALID_REQUEST_PROXY, null, request);
}
try {
final ProxyTicket proxyTicket = this.centralAuthenticationService.grantProxyTicket(proxyGrantingTicket, targetService);
final Map model = CollectionUtils.wrap(CasProtocolConstants.PARAMETER_TICKET, proxyTicket);
return new ModelAndView(this.successView, model);
} catch (final AbstractTicketException e) {
return generateErrorView(e.getCode(), new Object[] { proxyGrantingTicket }, request);
} catch (final UnauthorizedServiceException e) {
return generateErrorView(CasProtocolConstants.ERROR_CODE_UNAUTHORIZED_SERVICE_PROXY, new Object[] { targetService }, request);
}
}
Aggregations