/** * Update service and track session. * * @param id the id * @param service the service * @param onlyTrackMostRecentSession the only track most recent session */ protected void updateServiceAndTrackSession(final String id, final Service service, final boolean onlyTrackMostRecentSession) { updateState(); final List<Authentication> authentications = getChainedAuthentications(); service.setPrincipal(authentications.get(authentications.size()-1).getPrincipal()); if (onlyTrackMostRecentSession) { final String path = normalizePath(service); final Collection<Service> existingServices = services.values(); // loop on existing services for (final Service existingService : existingServices) { final String existingPath = normalizePath(existingService); // if an existing service has the same normalized path, remove it // and its service ticket to keep the latest one if (StringUtils.equals(path, existingPath)) { existingServices.remove(existingService); LOGGER.trace("Removed previous tickets for service: {}", existingService); break; } } } this.services.put(id, service); }