Class RequestContext


public class RequestContext extends ThreadContext
The request execution context, i.e. the top-level thread-level context.
Version:
1.0
  • Constructor Details

    • RequestContext

      protected RequestContext(String id)
      Creates a new request execution context.
      Parameters:
      id - the context identifier (name)
  • Method Details

    • active

      public static RequestContext active()
      Returns the currently active request context. If no request context is available, null is returned.
      Returns:
      the currently active request context, or null
    • initLocal

      public static RequestContext initLocal(String userId) throws SecurityException
      Authenticates a verified user id and creates a new execution context. This method will verify that the user id exists and is enabled. But it also assumes that the user authentication can be trusted (via local login or similar).
      Parameters:
      userId - the request user id
      Returns:
      a new execution context
      Throws:
      SecurityException - if the user failed authentication
    • initWeb

      public static RequestContext initWeb(Request request)
      Creates a new request execution context for a web request. If a valid session is found, its user will be authenticated and added to the context.
      Parameters:
      request - the request being processed
      Returns:
      a new execution context
    • initAsync

      public static RequestContext initAsync(Session session, User user)
      Creates a new request execution context for an asynchronous request.
      Parameters:
      session - the request session (or null)
      user - the request user (or null)
      Returns:
      a new execution context
    • close

      public void close()
      Closes this context if and only if it is active for the thread. Normally this method is not called directly, but implicitly for contexts implementing AutoClosable. If this method is not called from the same thread that created the context, no changes will be made. The parent context will be set as the new active context. All object references will be cleared in preparation for garbage collection.
      Overrides:
      close in class Context
      See Also:
    • auth

      public User auth(String id) throws SecurityException
      Authenticates the specified user. This method will verify that the user exists and is enabled. It should only be called if a previous user authentication can be trusted, either via a cookie, command-line login or similar. After a successful authentication the context user will be set.
      Parameters:
      id - the unique user id
      Returns:
      the authenticated user
      Throws:
      SecurityException - if the user failed authentication
    • authBySession

      protected User authBySession() throws SecurityException
      Authenticates a user via the current request session. If no session is found (or if it is anonymous), null is returned. If the session is expired, user is invalid, etc. an exception is thrown.
      Returns:
      the authenticated user, or null
      Throws:
      SecurityException - if the session was expired or the user failed authentication
    • authByMd5Hash

      public User authByMd5Hash(String id, String suffix, String hash) throws SecurityException
      Authenticates a user via a two-step MD5 hash. If the user is disabled or the hashes don't match an exception is thrown.
      Parameters:
      id - the unique user id
      suffix - the user password hash suffix to append
      hash - the expected hashed result
      Returns:
      the authenticated user
      Throws:
      SecurityException - if the authentication failed
    • authByToken

      public User authByToken(String token) throws SecurityException
      Authenticates a user via an authentication token. If the token is expired, invalid or linked to a disabled user an exception is thrown. Note that tokens automatically invalidates when a user password is changed.
      Parameters:
      token - the authentication token
      Returns:
      the authenticated user
      Throws:
      SecurityException - if the token was invalid or user authentication failed
    • identifyCaller

      public void identifyCaller(String procedure, String token)
      Identifies the caller of a procedure. This method will validate the procedure call token and set the context identifier to the app path.
      Parameters:
      procedure - the procedure identifier
      token - the procedure call token