Package org.rapidcontext.app.model
Class RequestContext
java.lang.Object
org.rapidcontext.core.ctx.Context
org.rapidcontext.core.ctx.ThreadContext
org.rapidcontext.app.model.RequestContext
The request execution context, i.e. the top-level thread-level context.
- Version:
- 1.0
-
Field Summary
Fields inherited from class org.rapidcontext.core.ctx.ThreadContext
CX_CREATED, CX_LOG, CX_REQUEST, CX_SESSION, CX_USER, MAX_LOG_LENGTHFields inherited from class org.rapidcontext.core.ctx.Context
actives, CX_DIRECTORY, CX_ENVIRONMENT, CX_SCHEDULER, CX_STORAGE, id, parent, root -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedRequestContext(String id) Creates a new request execution context. -
Method Summary
Modifier and TypeMethodDescriptionstatic RequestContextactive()Returns the currently active request context.Authenticates the specified user.authByMd5Hash(String id, String suffix, String hash) Authenticates a user via a two-step MD5 hash.protected UserAuthenticates a user via the current request session.authByToken(String token) Authenticates a user via an authentication token.voidclose()Closes this context if and only if it is active for the thread.voididentifyCaller(String procedure, String token) Identifies the caller of a procedure.static RequestContextCreates a new request execution context for an asynchronous request.static RequestContextAuthenticates a verified user id and creates a new execution context.static RequestContextCreates a new request execution context for a web request.Methods inherited from class org.rapidcontext.core.ctx.ThreadContext
created, hasAccess, hasDirectAccess, hasReadAccess, hasSearchAccess, hasWriteAccess, isLogging, log, log, logError, logRepr, logRequest, logResponse, logTrace, request, requireAccess, requireReadAccess, requireSearchAccess, requireWriteAccess, session, sessionRequired, user
-
Constructor Details
-
RequestContext
Creates a new request execution context.- Parameters:
id- the context identifier (name)
-
-
Method Details
-
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
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
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
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. -
auth
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
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
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 idsuffix- the user password hash suffix to appendhash- the expected hashed result- Returns:
- the authenticated user
- Throws:
SecurityException- if the authentication failed
-
authByToken
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
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 identifiertoken- the procedure call token
-