/**
   * Endpoint for destroying SSO Sessions.
   *
   * @param type the type
   * @return result map
   */
  @RequestMapping(value = "/destroySsoSessions", method = RequestMethod.POST)
  @ResponseBody
  public Map<String, Object> destroySsoSessions(
      @RequestParam(defaultValue = "ALL") final String type) {
    final Map<String, Object> sessionsMap = new HashMap<>();
    final Map<String, String> failedTickets = new HashMap<>();

    final SsoSessionReportOptions option = SsoSessionReportOptions.valueOf(type);
    final Collection<Map<String, Object>> collection = getActiveSsoSessions(option);
    for (final Map<String, Object> sso : collection) {
      final String ticketGrantingTicket =
          sso.get(SsoSessionAttributeKeys.TICKET_GRANTING_TICKET.toString()).toString();
      try {
        this.centralAuthenticationService.destroyTicketGrantingTicket(ticketGrantingTicket);
      } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        failedTickets.put(ticketGrantingTicket, e.getMessage());
      }
    }

    if (failedTickets.isEmpty()) {
      sessionsMap.put("status", HttpServletResponse.SC_OK);
    } else {
      sessionsMap.put("status", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      sessionsMap.put("failedTicketGrantingTickets", failedTickets);
    }
    return sessionsMap;
  }
  /**
   * Endpoint for getting SSO Sessions in JSON format.
   *
   * @param type the type
   * @return the sso sessions
   */
  @RequestMapping(value = "/getSsoSessions", method = RequestMethod.GET)
  @ResponseBody
  public Map<String, Object> getSsoSessions(@RequestParam(defaultValue = "ALL") final String type) {
    final Map<String, Object> sessionsMap = new HashMap<>(1);
    final SsoSessionReportOptions option = SsoSessionReportOptions.valueOf(type);

    final Collection<Map<String, Object>> activeSsoSessions = getActiveSsoSessions(option);
    sessionsMap.put("activeSsoSessions", activeSsoSessions);

    long totalTicketGrantingTickets = 0;
    long totalProxyGrantingTickets = 0;
    long totalUsageCount = 0;

    final Set<String> uniquePrincipals = new HashSet<>();

    for (final Map<String, Object> activeSsoSession : activeSsoSessions) {

      if (activeSsoSession.containsKey(SsoSessionAttributeKeys.IS_PROXIED.toString())) {
        final Boolean isProxied =
            Boolean.valueOf(
                activeSsoSession.get(SsoSessionAttributeKeys.IS_PROXIED.toString()).toString());
        if (isProxied) {
          totalProxyGrantingTickets++;
        } else {
          totalTicketGrantingTickets++;
          final String principal =
              activeSsoSession
                  .get(SsoSessionAttributeKeys.AUTHENTICATED_PRINCIPAL.toString())
                  .toString();
          uniquePrincipals.add(principal);
        }
      } else {
        totalTicketGrantingTickets++;
        final String principal =
            activeSsoSession
                .get(SsoSessionAttributeKeys.AUTHENTICATED_PRINCIPAL.toString())
                .toString();
        uniquePrincipals.add(principal);
      }
      totalUsageCount +=
          Long.parseLong(
              activeSsoSession.get(SsoSessionAttributeKeys.NUMBER_OF_USES.toString()).toString());
    }

    sessionsMap.put("totalProxyGrantingTickets", totalProxyGrantingTickets);
    sessionsMap.put("totalTicketGrantingTickets", totalTicketGrantingTickets);
    sessionsMap.put("totalTickets", totalTicketGrantingTickets + totalProxyGrantingTickets);
    sessionsMap.put("totalPrincipals", uniquePrincipals.size());
    sessionsMap.put("totalUsageCount", totalUsageCount);
    return sessionsMap;
  }