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
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for creatingClientContextinstances. -
Field Summary
Fields inherited from class org.forgerock.services.context.AbstractContext
data -
Constructor Summary
ConstructorsConstructorDescriptionClientContext(JsonValue savedContext, ClassLoader classLoader) Restore from JSON representation. -
Method Summary
Modifier and TypeMethodDescriptionstatic ClientContext.BuilderbuildExternalClientContext(Context parent) Creates aClientContext.Builderfor creating an externalClientContextinstance.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.intReturns 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.intReturns the source port of the client (or last proxy) that sent the request or-1if 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).booleanReturnstrueif this client is external.booleanisSecure()Returnstrueif this client connection is secure.static ClientContextnewInternalClientContext(Context parent) Creates an internalClientContextinstance.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.Builderfor creating an externalClientContextinstance.- Parameters:
parent- The parent context.- Returns:
- A builder for an external
ClientContextinstance.
-
newInternalClientContext
Creates an internalClientContextinstance. All data related to external context (e.g remote address, user agent...) will be set with empty non null values. The returned internalClientContextis considered as secure.- Parameters:
parent- The parent context.- Returns:
- An internal
ClientContextinstance.
-
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-1if the client is internal.- Returns:
- the source port of the client (or last proxy) that sent the request
or
-1if 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()Returnstrueif this client is external.- Returns:
trueif this client is external.
-
isSecure
public boolean isSecure()Returnstrueif 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:
trueif 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.
-