Ejemplo n.º 1
0
  @Action(
      value = "/admin/exitTerms",
      results = {@Result(name = "success", location = "/admin/menu.action", type = "redirect")})
  public String exitTerms() {

    Long userId = AuthUtil.getUserId(servletRequest.getSession());
    // check user map
    if (userSchSessionMap != null && !userSchSessionMap.isEmpty()) {

      // get user servletRequest.getSession()s
      for (Long userKey : userSchSessionMap.keySet()) {
        UserSchSessions userSchSessions = userSchSessionMap.get(userKey);

        // get current time and subtract number of hours set to determine expire time
        Calendar expireTime = Calendar.getInstance();
        expireTime.add(
            Calendar.HOUR,
            (-1
                * Integer.parseInt(
                    AppConfigLkup.getProperty(
                        "timeoutSshAfter")))); // subtract hours to get expire time

        // if current user or session has timed out remove ssh session
        if (userId.equals(userKey) || userSchSessions.getStartTime().before(expireTime.getTime())) {
          Map<Long, SchSession> schSessionMap = userSchSessionMap.get(userKey).getSchSessionMap();

          for (Long sessionKey : schSessionMap.keySet()) {

            SchSession schSession = schSessionMap.get(sessionKey);

            // disconnect ssh session
            schSession.getChannel().disconnect();
            schSession.getSession().disconnect();
            schSession.setChannel(null);
            schSession.setSession(null);
            schSession.setInputToChannel(null);
            schSession.setCommander(null);
            schSession.setOutFromChannel(null);
            schSession = null;
            // remove from map
            schSessionMap.remove(sessionKey);
          }

          // clear and remove session map for user
          schSessionMap.clear();
          userSchSessionMap.remove(userKey);
          SessionOutputUtil.removeUserSession(userKey);
        }
      }
    }

    return SUCCESS;
  }