@SuppressWarnings("unchecked")
  public <T> T get(Class<T> asoClass, ApplicationStateCreator<T> creator) {
    Session session = getSession();

    String key = buildKey(asoClass);

    Map<String, Object> asoMap = getASOMap();

    T aso = (T) asoMap.get(key);

    if (aso != null) return aso;

    // Otherwise, get/create it in the session and record it in the
    // aso map.

    aso = (T) session.getAttribute(key);

    if (aso == null) {
      aso = creator.create();
      session.setAttribute(key, aso);
    }

    asoMap.put(key, aso);

    return aso;
  }
  public <T> boolean exists(Class<T> asoClass) {
    String key = buildKey(asoClass);

    Session session = request.getSession(false);

    return session != null && session.getAttribute(key) != null;
  }
 @Override
 public ScreenState getCurrentScreenState() {
   Session session = request.getSession(false);
   if (session == null) {
     return null;
   }
   return (ScreenState) session.getAttribute(SESSION_KEY);
 }
 @Override
 public void exitCurrentScreen() {
   Session session = request.getSession(false);
   if (session != null) {
     LOG.trace("Clearing current screen.");
     session.setAttribute(SESSION_KEY, null);
   }
 }
 @Override
 public void setupOrRestoreScreen(String screenName) {
   Session session = request.getSession(true);
   ScreenState screen = (ScreenState) session.getAttribute(SESSION_KEY);
   if (screen == null || !screen.getName().equals(screenName)) {
     LOG.trace("Creating new screen state with name " + screenName);
     session.setAttribute(SESSION_KEY, new ScreenState(screenName));
   }
 }
  private TimeZone readTimeZoneFromSession() {
    Session session = request.getSession(false);

    if (session != null) {
      String id = (String) session.getAttribute(ATTRIBUTE_NAME);

      if (id != null) return TimeZone.getTimeZone(id);
    }

    return null;
  }
Esempio n. 7
0
  public boolean isSessionInvalidated() {
    // Double check to ensure that the session exists, but don't create it.
    if (session == null) {
      session = sessionFactory.getSession(false);
    }

    return session != null && session.isInvalidated();
  }
Esempio n. 8
0
  void onValidateForm() {

    provider.setUserDetailsService(userserve);

    provider.setPasswordEncoder(new ShaPasswordEncoder());
    authtoken = new UsernamePasswordAuthenticationToken(fLogin, fpass);
    provider.setSaltSource(salt);
    Authentication token = null;
    try {
      token = provider.authenticate(authtoken);
    } catch (org.springframework.security.BadCredentialsException e) {
      loginform.recordError("Either the Username or Password is incorrect, Please try again.");
      return;
    }
    if (token.isAuthenticated()) {
      System.out.println("user has been authenticated");
      this.user = userDAO.findByUsername(fLogin);
      SecurityContextHolder.getContext().setAuthentication(token);

      SavedRequest savedRequest =
          (SavedRequest)
              requestGlobals
                  .getHTTPServletRequest()
                  .getSession()
                  .getAttribute(AbstractProcessingFilter.SPRING_SECURITY_SAVED_REQUEST_KEY);
      Session s = request.getSession(false);
      s.invalidate();
      s = request.getSession(true);
      if (savedRequest != null) {
        url = null;

        try {
          url = new URL(savedRequest.getRequestURL());
        } catch (MalformedURLException e) {
          System.out.println("malformed url:" + savedRequest.getRequestURI());
        }
      }

    } else {
      // fpass = null;
      // fLogin = null;

      loginform.recordError("Either the Username or Password is incorrect, Please try again.");
    }
  }
  public void requestDidComplete() {
    Map<String, Object> map = getASOMap();

    for (String key : map.keySet()) {
      Object aso = map.get(key);

      if (aso == null) continue;

      if (needsRestore(aso)) {
        Session session = request.getSession(true);

        // It is expected that the ASO implements HttpSessionBindingListener and
        // can clear its dirty flag as it is saved.

        session.setAttribute(key, aso);
      }
    }
  }
  public void setClientTimeZone(TimeZone timeZone) {
    assert timeZone != null;

    identified = true;

    if (timeZone == this.timeZone) return;

    this.timeZone = timeZone;

    cookies.writeCookieValue(COOKIE_NAME, timeZone.getID());

    // Write to the Session, if it exists, in case the client doesn't support cookies.

    Session session = request.getSession(false);

    if (session != null) session.setAttribute(ATTRIBUTE_NAME, timeZone.getID());

    // Worst case: no session yet AND client doesn't support cookies. That means we'll likely
    // keep tracking the time zone (on the client) and updating (here on the server) until
    // a session gets created.
  }
Esempio n. 11
0
  public Session getSession(boolean create) {
    if (session != null && session.isInvalidated()) {
      session = null;
    }

    if (session == null) {
      // TAP5-1489 - Re-storage of session attributes at end of request should be configurable
      session = sessionFactory.getSession(create);
    }

    return session;
  }