Package org.forgerock.services.context
Class ClientContext
java.lang.Object
org.forgerock.services.context.AbstractContext
org.forgerock.services.context.ClientContext
- All Implemented Interfaces:
Context
Client context gives easy access to client-related information that are available into the request.
Supported data includes:
- Remote IP address
- Remote port
- Username
- Client provided certificates
- User-Agent information
- Whether the client is external
- Whether the connection to the client is secure
- Local port
- Local address
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Builder for creatingClientContext
instances. -
Field Summary
Fields inherited from class org.forgerock.services.context.AbstractContext
data
-
Constructor Summary
ConstructorDescriptionClientContext
(JsonValue savedContext, ClassLoader classLoader) Restore from JSON representation. -
Method Summary
Modifier and TypeMethodDescriptionstatic ClientContext.Builder
buildExternalClientContext
(Context parent) Creates aClientContext.Builder
for creating an externalClientContext
instance.Collection<? extends Certificate>
Returns the collection (possibly empty) of certificate(s) provided by the client.Returns the IP address of the interface that received the request.int
Returns the port of the interface that received the request.Returns the IP address of the client (or last proxy) that sent the request or an empty string if the client is internal.int
Returns the source port of the client (or last proxy) that sent the request or-1
if the client is internal.Returns the login of the user making this request or an empty string if not known.Returns the value of the User-Agent HTTP Header (if any, returns an empty string otherwise).boolean
Returnstrue
if this client is external.boolean
isSecure()
Returnstrue
if this client connection is secure.static ClientContext
newInternalClientContext
(Context parent) Creates an internalClientContext
instance.Methods inherited from class org.forgerock.services.context.AbstractContext
as, asContext, containsContext, containsContext, get, getContext, getContextName, getId, getParent, getRootId, isRootContext, toJsonValue, toString
-
Constructor Details
-
ClientContext
Restore from JSON representation.- Parameters:
savedContext
- The JSON representation from which this context's attributes should be parsed.classLoader
- The ClassLoader which can properly resolve the persisted class-name.
-
-
Method Details
-
buildExternalClientContext
Creates aClientContext.Builder
for creating an externalClientContext
instance.- Parameters:
parent
- The parent context.- Returns:
- A builder for an external
ClientContext
instance.
-
newInternalClientContext
Creates an internalClientContext
instance. All data related to external context (e.g remote address, user agent...) will be set with empty non null values. The returned internalClientContext
is considered as secure.- Parameters:
parent
- The parent context.- Returns:
- An internal
ClientContext
instance.
-
getRemoteUser
Returns the login of the user making this request or an empty string if not known.- Returns:
- the login of the user making this request or an empty string if not known.
-
getRemoteAddress
Returns the IP address of the client (or last proxy) that sent the request or an empty string if the client is internal.- Returns:
- the IP address of the client (or last proxy) that sent the request or an empty string if the client is internal.
-
getRemotePort
public int getRemotePort()Returns the source port of the client (or last proxy) that sent the request or-1
if the client is internal.- Returns:
- the source port of the client (or last proxy) that sent the request
or
-1
if the client is internal.
-
getCertificates
Returns the collection (possibly empty) of certificate(s) provided by the client. If no certificates are available, an empty list is returned.- Returns:
- the collection (possibly empty) of certificate(s) provided by the client.
-
getUserAgent
Returns the value of the User-Agent HTTP Header (if any, returns an empty string otherwise).- Returns:
- the value of the User-Agent HTTP Header (if any, returns an empty string otherwise).
-
isExternal
public boolean isExternal()Returnstrue
if this client is external.- Returns:
true
if this client is external.
-
isSecure
public boolean isSecure()Returnstrue
if this client connection is secure. It is the responsibility to the underlying protocol/implementation to determine whether or not the connection is secure. For example HTTPS and internal connections are meant to be secure.- Returns:
true
if this client connection is secure.
-
getLocalAddress
Returns the IP address of the interface that received the request.- Returns:
- the IP address of the server that received the request.
-
getLocalPort
public int getLocalPort()Returns the port of the interface that received the request.- Returns:
- the port of the interface that received the request.
-