@Override public int deleteTicket(final String ticketId) { int count = 0; if (ticketId == null) { return count; } final Ticket ticket = getTicket(ticketId); if (ticket == null) { return count; } if (ticket instanceof TicketGrantingTicket) { if (ticket instanceof ProxyGrantingTicket) { logger.debug("Removing proxy-granting ticket [{}]", ticketId); } logger.debug("Removing children of ticket [{}] from the registry.", ticket.getId()); final TicketGrantingTicket tgt = (TicketGrantingTicket) ticket; count += deleteChildren(tgt); final Collection<ProxyGrantingTicket> proxyGrantingTickets = tgt.getProxyGrantingTickets(); final Iterator<ProxyGrantingTicket> it = proxyGrantingTickets.iterator(); while(it.hasNext()) { final ProxyGrantingTicket pgt = it.next(); count += deleteTicket(pgt.getId()); } } logger.debug("Removing ticket [{}] from the registry.", ticket); if (deleteSingleTicket(ticketId)) { count++; } return count; }