SecurityContext
s directly rather than via request attributes.@Deprecated public final class SecurityContextFactory extends Object implements HttpContextFactory
SecurityContext
whose
authentication ID and authorization ID are taken from attributes contained
in the HTTP request.
This class provides integration with the common authentication framework and is intended to work as follows:
Map<String, Object>
containing the principals keyed on the principal name. NOTE: various
reserved principal names are defined in SecurityContext
.
ATTRIBUTE_AUTHCID
attribute.
Map
containing the
authorization principals in the HTTP servlet request's
ATTRIBUTE_AUTHZID
attribute.
SecurityContextFactory
to
obtain the authentication ID and authorization principals from the HTTP
request's attributes.
public Promise<Response, ResponseException> filter(Context context, Request request, Handler next) {
// Authenticate the user.
String authcid = getUserName(request);
String password = getPassword(request);
// Add the attributes.
if (checkCredentials(authcid, password)) {
// Obtain principals for authorization.
Map<String, Object> authzid = new HashMap<>();
authzid.put(AUTHZID_ID, id);
...
AttributesContext attributesContext = context.asContext(AttributesContext.class);
attributesContext.getAttributes().put(ATTRIBUTE_AUTHCID, authcid);
attributesContext.getAttributes().put(ATTRIBUTE_AUTHZID, authzid);
}
}
Modifier and Type | Field and Description |
---|---|
static String |
ATTRIBUTE_AUTHCID
Deprecated.
The name of the HTTP Request attribute where this factory expects to
find the authenticated user's authentication ID.
|
static String |
ATTRIBUTE_AUTHZID
Deprecated.
The name of the HTTP Request attribute where this factory expects to
find the authenticated user's authorization ID.
|
Modifier and Type | Method and Description |
---|---|
org.forgerock.services.context.SecurityContext |
createContext(org.forgerock.services.context.Context parent)
Deprecated.
Creates a new
SecurityContext using the attributes contained in
the provided HTTP request. |
org.forgerock.services.context.SecurityContext |
createContext(org.forgerock.services.context.Context context,
org.forgerock.http.protocol.Request request)
Deprecated.
Creates a new
SecurityContext using the attributes contained in
the provided HTTP request. |
static SecurityContextFactory |
getHttpServletContextFactory()
Deprecated.
Returns the singleton security context factory which can be used for
obtaining context information from a HTTP request.
|
public static final String ATTRIBUTE_AUTHCID
org.forgerock.authentication.principal
and it MUST
contain a String
if it is present.SecurityContext.getAuthenticationId()
,
Constant Field Valuespublic static final String ATTRIBUTE_AUTHZID
org.forgerock.authentication.context
and it MUST
contain a Map<String, Object>
if it is present.SecurityContext.getAuthorization()
,
Constant Field Valuespublic static SecurityContextFactory getHttpServletContextFactory()
public org.forgerock.services.context.SecurityContext createContext(org.forgerock.services.context.Context parent) throws ResourceException
SecurityContext
using the attributes contained in
the provided HTTP request. The authentication ID will be obtained from
the ATTRIBUTE_AUTHCID
attribute, and the authorization ID will
be obtained from the ATTRIBUTE_AUTHCID
attribute.
It is not an error if either of the attributes are not present, but a
ResourceException
will be thrown if they are present but have the
wrong type.
parent
- The parent context.ResourceException
- If one of the attributes was present but had the wrong type.public org.forgerock.services.context.SecurityContext createContext(org.forgerock.services.context.Context context, org.forgerock.http.protocol.Request request) throws ResourceException
SecurityContext
using the attributes contained in
the provided HTTP request. The authentication ID will be obtained from
the ATTRIBUTE_AUTHCID
attribute, and the authorization ID will
be obtained from the ATTRIBUTE_AUTHCID
attribute.
It is not an error if either of the attributes are not present, but a
ResourceException
will be thrown if they are present but have the
wrong type.
createContext
in interface HttpContextFactory
context
- The parent context.request
- The HTTP request from which the authentication ID and
authorization ID attributes should be obtained.ResourceException
- If one of the attributes was present but had the wrong type.Copyright 2010-2022 ForgeRock AS.