Package org.forgerock.services.context
Class ClientContext
- java.lang.Object
-
- org.forgerock.services.context.AbstractContext
-
- org.forgerock.services.context.ClientContext
-
- All Implemented Interfaces:
Context
public final class ClientContext extends AbstractContext
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 Classes Modifier and Type Class Description static class
ClientContext.Builder
Builder for creatingClientContext
instances.
-
Field Summary
-
Fields inherited from class org.forgerock.services.context.AbstractContext
data
-
-
Constructor Summary
Constructors Constructor Description ClientContext(JsonValue savedContext, ClassLoader classLoader)
Restore from JSON representation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ClientContext.Builder
buildExternalClientContext(Context parent)
Creates aClientContext.Builder
for creating an externalClientContext
instance.Collection<? extends Certificate>
getCertificates()
Returns the collection (possibly empty) of certificate(s) provided by the client.String
getLocalAddress()
Returns the IP address of the interface that received the request.int
getLocalPort()
Returns the port of the interface that received the request.String
getRemoteAddress()
Returns the IP address of the client (or last proxy) that sent the request or an empty string if the client is internal.int
getRemotePort()
Returns the source port of the client (or last proxy) that sent the request or-1
if the client is internal.String
getRemoteUser()
Returns the login of the user making this request or an empty string if not known.String
getUserAgent()
Returns the value of the User-Agent HTTP Header (if any, returns an empty string otherwise).boolean
isExternal()
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 Detail
-
ClientContext
public ClientContext(JsonValue savedContext, ClassLoader classLoader)
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 Detail
-
buildExternalClientContext
public static ClientContext.Builder buildExternalClientContext(Context parent)
Creates aClientContext.Builder
for creating an externalClientContext
instance.- Parameters:
parent
- The parent context.- Returns:
- A builder for an external
ClientContext
instance.
-
newInternalClientContext
public static ClientContext newInternalClientContext(Context parent)
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
public String 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
public String 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
public Collection<? extends Certificate> 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
public String 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
public String 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.
-
-