Module io.jooby
Package io.jooby

Interface SessionStore

All Known Implementing Classes:
SessionStore.InMemory

public interface SessionStore
Load and save sessions from store (memory, database, etc.).
Since:
2.0.0
Author:
edgar
  • Field Details

    • DEFAULT_TIMEOUT

      static final int DEFAULT_TIMEOUT
      Default session timeout in minutes.
      See Also:
  • Method Details

    • newSession

      @NonNull Session newSession(@NonNull Context ctx)
      Creates a new session. This method must:

      - Set session as new Session.setNew(boolean) - Optionally, set session creation time Session.setCreationTime(Instant) - Optionally, set session last accessed time Session.setLastAccessedTime(Instant)

      Parameters:
      ctx - Web context.
      Returns:
      A new session.
    • findSession

      @Nullable Session findSession(@NonNull Context ctx)
      Find an existing session by ID. For existing session this method must:

      - Optionally, Retrieve/restore session creation time - Optionally, Set session last accessed time Session.setLastAccessedTime(Instant)

      Parameters:
      ctx - Web context.
      Returns:
      An existing session or null.
    • deleteSession

      void deleteSession(@NonNull Context ctx, @NonNull Session session)
      Delete a session from store. This method must NOT call Session.destroy().
      Parameters:
      ctx - Web context.
      session - Current session.
    • touchSession

      void touchSession(@NonNull Context ctx, @NonNull Session session)
      Session attributes/state has changed. Every time a session attribute is put or removed it, this method is executed as notification callback.
      Parameters:
      ctx - Web context.
      session - Current session.
    • saveSession

      void saveSession(@NonNull Context ctx, @NonNull Session session)
      Save a session. This method must save:

      - Session attributes/data - Optionally set Session metadata like: creationTime, lastAccessed time, etc.

      This method is call after response is send to client, so context and response shouldn't be modified.

      Parameters:
      ctx - Web context.
      session - Current session.
    • renewSessionId

      void renewSessionId(@NonNull Context ctx, @NonNull Session session)
      Renew Session ID. This operation might or might not be implemented by a Session Store.
      Parameters:
      ctx - Web Context.
      session - Session.
    • memory

      @NonNull static SessionStore memory(int timeout)
      Creates a cookie based session and store data in memory. Session data is not keep after restart.

      It uses the default session cookie: SessionToken.SID.

      - Session data is not keep after restart.

      Parameters:
      timeout - Timeout in seconds. Use -1 for no timeout.
      Returns:
      Session store.
    • memory

      @NonNull static SessionStore memory()
      Creates a cookie based session and store data in memory. Session data is not keep after restart.

      It uses the default session cookie: SessionToken.SID.

      - Session expires after 30 minutes of inactivity. - Session data is not keep after restart.

      Returns:
      Session store.
    • memory

      @NonNull static SessionStore memory(@NonNull Duration timeout)
      Creates a cookie based session and store data in memory. Session data is not keep after restart.

      It uses the default session cookie: SessionToken.SID.

      Parameters:
      timeout - Expires session after amount of inactivity time.
      Returns:
      Session store.
    • memory

      @NonNull static SessionStore memory(@NonNull Cookie cookie)
      Creates a cookie based session and store data in memory.

      - Session expires after 30 minutes of inactivity. - Session data is not keep after restart.

      Parameters:
      cookie - Cookie to use.
      Returns:
      Session store.
    • memory

      @NonNull static SessionStore memory(@NonNull Cookie cookie, @NonNull Duration timeout)
      Creates a cookie based session and store data in memory. Session data is not keep after restart.
      Parameters:
      cookie - Cookie to use.
      timeout - Expires session after amount of inactivity time.
      Returns:
      Session store.
    • memory

      @NonNull static SessionStore memory(@NonNull SessionToken token)
      Creates a session store that save data in memory. - Session expires after 30 minutes of inactivity. - Session data is not keep after restart.
      Parameters:
      token - Session token.
      Returns:
      Session store.
    • memory

      @NonNull static SessionStore memory(@NonNull SessionToken token, @NonNull Duration timeout)
      Creates a session store that save data in memory. Session data is not keep after restart.
      Parameters:
      token - Session token.
      timeout - Expires session after amount of inactivity time.
      Returns:
      Session store.
    • signed

      @NonNull static SessionStore signed(@NonNull String secret)
      Creates a session store that uses (un)signed data. Session data is signed it using HMAC_SHA256.

      See Cookie.sign(String, String) and Cookie.unsign(String, String).

      Parameters:
      secret - Secret token to signed data.
      Returns:
      A browser session store.
    • signed

      @NonNull static SessionStore signed(@NonNull String secret, @NonNull Cookie cookie)
      Creates a session store that uses (un)signed data. Session data is signed it using HMAC_SHA256.

      See Cookie.sign(String, String) and Cookie.unsign(String, String).

      Parameters:
      secret - Secret token to signed data.
      cookie - Cookie to use.
      Returns:
      A browser session store.
    • signed

      @NonNull static SessionStore signed(@NonNull String secret, @NonNull SessionToken token)
      Creates a session store that uses (un)signed data. Session data is signed it using HMAC_SHA256.

      See Cookie.sign(String, String) and Cookie.unsign(String, String).

      Parameters:
      secret - Secret token to signed data.
      token - Session token to use.
      Returns:
      A browser session store.
    • signed

      @NonNull static SessionStore signed(@NonNull SessionToken token, @NonNull Function<String,Map<String,String>> decoder, @NonNull Function<Map<String,String>,String> encoder)
      Creates a session store that save data into Cookie. Cookie data is (un)signed it using the given decoder and encoder.
      Parameters:
      token - Token to use.
      decoder - Decoder to use.
      encoder - Encoder to use.
      Returns:
      Cookie session store.