@Override
  public void setSessionAttributeForString(String key, String value) {
    HttpServletRequest request =
        ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    HttpSession session = request.getSession();
    session.setAttribute(key, value);
    LoginSessionInterface loginSession = null;
    SessionDataInterface sessionData = null;
    try {
      sessionData =
          loginSessionDataRepository.findBySessionKey(
              cookieValidation.getCookieValue(request, "XA_ID"), key);
      if (sessionData != null) {
        sessionData.setStringValue(value);
        sessionData.setDataType(DATA_TYPE.STRING.value);
        loginSessionDataRepository.update(sessionData);
      } else {
        loginSessionDataRepository.saveSessionData(
            session.getAttribute("userId").toString(),
            runtimeLogInfoHelper.getCustomerId(),
            DATA_TYPE.STRING.value,
            null,
            value,
            null,
            null,
            null,
            cookieValidation.getCookieValue(request, "XA_ID"),
            key);
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  @Override
  public void removeSessionAllAttributes() {
    HttpServletRequest request =
        ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    HttpSession session = request.getSession();
    List<SessionDataInterface> sessionDatalist = null;

    System.out.println("Removing session data for key: ");

    LoginSessionInterface loginSession = null;

    try {
      sessionDatalist =
          loginSessionDataRepository.findByAppSessionId(
              cookieValidation.getCookieValue(request, "XA_ID"));

      loginSessionDataRepository.deleteAll(cookieValidation.getCookieValue(request, "XA_ID"));
      System.out.println("Remove data from Session data Table");
    } catch (SpartanPersistenceException e1) {
      System.out.println("Requested Session Id not found");
    } catch (Exception e1) {
      System.out.println("Requested Session Id not found");
    }
    Enumeration<String> sessionNamesEnumeration = session.getAttributeNames();

    List<String> sessionattributeNames = new ArrayList<String>();

    while (sessionNamesEnumeration.hasMoreElements()) {
      session.removeAttribute(sessionNamesEnumeration.nextElement());
    }
  }
  @Override
  public void removeSessionAttribute(String key) {
    HttpServletRequest request =
        ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    HttpSession session = request.getSession();
    SessionDataInterface sessionData = null;

    System.out.println("Removing session data for key: " + key);

    LoginSessionInterface loginSession = null;

    try {
      sessionData =
          loginSessionDataRepository.findBySessionKey(
              cookieValidation.getCookieValue(request, "XA_ID"), key);
      if (sessionData != null) {
        loginSessionDataRepository.delete(sessionData.getDataId());
        System.out.println("Remove data from Session data Table");
      }
    } catch (SpartanPersistenceException e1) {
      System.out.println("Requested Session Id not found");
    } catch (Exception e1) {
      System.out.println("Requested Session Id not found");
    }
    session.removeAttribute(key);
  }
Exemplo n.º 4
0
 private boolean validateRequest(
     HttpSession session, HttpServletRequest request, HttpServletResponse response)
     throws SpartanAccessDeniedException {
   if (!sessionValidation.checkIgnoreURL(request)) {
     sessionValidation.validateSession(session, request, response);
     cookieValidation.validateSessionCookie(session, request);
   }
   return true;
 }
  @Override
  public void removeSessionAllAttributes() {
    HttpServletRequest request =
        ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    HttpSession session = request.getSession();
    List<SessionDataInterface> sessionDatalist = null;

    System.out.println("Removing session data for key: ");

    LoginSessionInterface loginSession = null;

    try {
      sessionDatalist =
          loginSessionDataRepository.findByAppSessionId(
              cookieValidation.getCookieValue(request, "XA_ID"));

      loginSessionDataRepository.deleteAll(cookieValidation.getCookieValue(request, "XA_ID"));
      System.out.println("Remove data from Session data Table");
      // loginSession =
      // loginSessionInterfaceRepository.findById(session.getAttribute("usidHash").toString());

    } catch (SpartanPersistenceException e1) {
      System.out.println("Requested Session Id not found");
    } catch (Exception e1) {
      System.out.println("Requested Session Id not found");
    }
    // session.removeAttribute(key);
    Enumeration<String> sessionNamesEnumeration = session.getAttributeNames();

    List<String> sessionattributeNames = new ArrayList<String>();

    while (sessionNamesEnumeration.hasMoreElements()) {
      session.removeAttribute(sessionNamesEnumeration.nextElement());
    }
    /*
     * if (loginSession != null) {
     *
     * String sessionData = loginSession.getSessionData(); try { JSONObject
     * sessionDataObject = new JSONObject(sessionData);
     * sessionDataObject.remove(key); updateSession(loginSession,
     * sessionDataObject.toString()); } catch (JSONException e) {
     * e.printStackTrace(); }
     */
  }
  @Override
  public Object getSessionData(String key) {
    HttpServletRequest request =
        ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    HttpSession session = request.getSession();
    if (session.getAttribute(key) != null) {
      System.out.println("Returning session data from session for key: " + key);
      return session.getAttribute(key);
    } else {
      try {
        // LoginSessionInterface loginSession = null;
        SessionDataInterface sessionData = null;
        sessionData =
            loginSessionDataRepository.findBySessionKey(
                cookieValidation.getCookieValue(request, "XA_ID"), key);
        if (sessionData != null) {
          // loginSession =
          // loginSessionInterfaceRepository.findById(session.getAttribute("usidHash").toString());
          if (sessionData.getDataType() == 1) {
            session.setAttribute(key, sessionData.getNumberValue());
          } else if (sessionData.getDataType() == 2) {
            session.setAttribute(key, sessionData.getDateTimeValue());

          } else if (sessionData.getDataType() == 3) {
            session.setAttribute(key, sessionData.getStringValue());

          } else if (sessionData.getDataType() == 4) {
            session.setAttribute(key, sessionData.getBooleanValue());
          } else if (sessionData.getDataType() == 5) {
            session.setAttribute(key, sessionData.getJsonValue());
          }
          /*if (loginSession != null) {
          String sessionData = loginSession.getSessionData();
          JSONObject sessionDataObject = new JSONObject(sessionData);
          if (sessionDataObject.has(key)) {
          	 Put the value in Http session
          	session.setAttribute(key, sessionDataObject.get(key));
          	System.out.println("Returning session data from db for key: " + key);
          	return sessionDataObject.get(key);
          }*/
          return session.getAttribute(key);
        }

        return null;
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    return null;
  }
  @Override
  public void removeSessionAttribute(String key) {
    HttpServletRequest request =
        ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    HttpSession session = request.getSession();
    SessionDataInterface sessionData = null;

    System.out.println("Removing session data for key: " + key);

    LoginSessionInterface loginSession = null;

    try {
      sessionData =
          loginSessionDataRepository.findBySessionKey(
              cookieValidation.getCookieValue(request, "XA_ID"), key);
      if (sessionData != null) {
        loginSessionDataRepository.delete(sessionData.getDataId());
        System.out.println("Remove data from Session data Table");
      }
      // loginSession =
      // loginSessionInterfaceRepository.findById(session.getAttribute("usidHash").toString());

    } catch (SpartanPersistenceException e1) {
      System.out.println("Requested Session Id not found");
    } catch (Exception e1) {
      System.out.println("Requested Session Id not found");
    }
    session.removeAttribute(key);
    /*if (loginSession != null) {

    	String sessionData = loginSession.getSessionData();
    	try {
    		JSONObject sessionDataObject = new JSONObject(sessionData);
    		sessionDataObject.remove(key);
    		updateSession(loginSession, sessionDataObject.toString());
    	} catch (JSONException e) {
    		e.printStackTrace();
    	}
    }*/
  }
  @Override
  public Object getSessionData(String key) {
    HttpServletRequest request =
        ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    HttpSession session = request.getSession();
    if (session.getAttribute(key) != null) {
      System.out.println("Returning session data from session for key: " + key);
      return session.getAttribute(key);
    } else {
      try {
        SessionDataInterface sessionData = null;
        sessionData =
            loginSessionDataRepository.findBySessionKey(
                cookieValidation.getCookieValue(request, "XA_ID"), key);
        if (sessionData != null) {
          if (sessionData.getDataType() == 1) {
            session.setAttribute(key, sessionData.getNumberValue());
          } else if (sessionData.getDataType() == 2) {
            session.setAttribute(key, sessionData.getDateTimeValue());

          } else if (sessionData.getDataType() == 3) {
            session.setAttribute(key, sessionData.getStringValue());

          } else if (sessionData.getDataType() == 4) {
            session.setAttribute(key, sessionData.getBooleanValue());
          } else if (sessionData.getDataType() == 5) {
            session.setAttribute(key, sessionData.getJsonValue());
          }
          return session.getAttribute(key);
        }

        return null;
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    return null;
  }
  @Override
  public <T> Object getSessionDataForObject(String key, Class clazz) {
    HttpServletRequest request =
        ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    HttpSession session = request.getSession();
    SessionDataInterface sessionData = null;
    try {
      if (session.getAttribute(key) != null) {
        return new JSONObjectMapperHelper().fromJSON(session.getAttribute(key).toString(), clazz);
      }
      sessionData =
          loginSessionDataRepository.findBySessionKey(
              cookieValidation.getCookieValue(request, "XA_ID"), key);
      if (sessionData != null) {
        if (sessionData.getDataType() == 5) {
          session.setAttribute(key, sessionData.getJsonValue());

          return new JSONObjectMapperHelper().fromJSON(sessionData.getJsonValue(), clazz);
        }
      }
    } catch (Exception e) {
    }
    return null;
  }