@Override
  public void closeSessions(String principalName, String principalClassName) throws Exception {
    if ((principalName == null)
        || (principalName.trim().length() == 0)
        || (principalClassName == null)
        || (principalClassName.trim().length() == 0)) {
      return;
    }

    principalName = principalName.trim();
    principalClassName = principalClassName.trim();

    Map<Long, Map<String, String>> sessionPrincipalMap =
        serviceManagementBean.getLoggedInSessions();

    for (Map.Entry<Long, Map<String, String>> entry : sessionPrincipalMap.entrySet()) {
      long sessionId = entry.getKey();
      Map<String, String> userPrincipals = entry.getValue();

      for (Map.Entry<String, String> principal : userPrincipals.entrySet()) {
        String key = principal.getKey();
        String value = principal.getValue();

        // Case sensitive for both name and class-name.
        if (key.equals(principalName) && (value.equals(principalClassName))) {
          SessionMXBean sessionBean = managementServiceHandler.getSessionMXBean(sessionId);
          sessionBean.close();
          serviceManagementBean.removeSessionManagementBean(sessionId);
          break;
        }
      }
    }
  }
  /**
   * Return a map of session mbean names to the user principals for those sessions. The
   * serviceManagementBean stores them as session ID to user principals, and we have to convert the
   * session ID to mbean name here. Gross, but it's the only way to not have JMX-specific stuff in
   * the ServiceManagementBean.
   */
  @Override
  public Map<String, Map<String, String>> getLoggedInSessions() {
    // First, get the map of session ID to user principals for that session.
    Map<Long, Map<String, String>> sessionPrincipalMap =
        serviceManagementBean.getLoggedInSessions();

    Map<String, Map<String, String>> result = new HashMap<>();

    for (Map.Entry<Long, Map<String, String>> entry : sessionPrincipalMap.entrySet()) {
      long sessionId = entry.getKey();
      Map<String, String> userPrincipals = entry.getValue();
      ObjectName sessionMBeanName =
          managementServiceHandler.getSessionMXBean(sessionId).getObjectName();
      result.put(sessionMBeanName.toString(), userPrincipals);
    }

    return result;
  }