public final class Rest2LDAPContextFactory extends Object implements org.forgerock.json.resource.servlet.HttpServletContextFactory
Context
chain
comprising of a SecurityContext
and optionally an
AuthenticatedConnectionContext
.
This class provides integration between Rest2LDAP HTTP Servlets and the
Rest2LDAPAuthnFilter
, by providing a mechanism allowing the filter to
pass a pre-authenticated LDAP connection through to the underlying Rest2LDAP
implementation for use when performing subsequent LDAP operations. The
following code illustrates how an authentication Servlet filter can populate
the attributes:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) { // Authenticate the user. String username = getUserName(request); String password = getPassword(request); final Connection connection = getLDAPConnection(); // Publish the authenticated connection. try { connection.bind(username, password.toCharArray()); request.setAttribute(ATTRIBUTE_AUTHN_CONNECTION, connection); } catch (LdapException e) { // Fail the HTTP request. response.setStatus(...); return; } // Invoke the rest of the filter chain and then release the LDAP connection once // processing has completed. Note that this assumes that the filter chain is // processes requests synchronous. try { chain.doFilter(request, response); } finally { connection.close(); } }
Modifier and Type | Field and Description |
---|---|
static String |
ATTRIBUTE_AUTHN_CONNECTION
The name of the HTTP Servlet Request attribute where this factory expects
to find the authenticated user's authentication ID.
|
Modifier and Type | Method and Description |
---|---|
org.forgerock.json.resource.Context |
createContext(org.forgerock.json.resource.Context parent,
javax.servlet.http.HttpServletRequest request)
Creates a new
Context chain comprising of the provided parent
context(s), a SecurityContext obtained using a
SecurityContextFactory , and optionally a
AuthenticatedConnectionContext . |
org.forgerock.json.resource.Context |
createContext(javax.servlet.http.HttpServletRequest request)
Creates a new
Context chain comprising of a RootContext ,
a SecurityContext obtained using a SecurityContextFactory
, and optionally a AuthenticatedConnectionContext . |
static Rest2LDAPContextFactory |
getHttpServletContextFactory()
Returns the singleton context factory which can be used for obtaining
context information from a HTTP servlet request.
|
public static final String ATTRIBUTE_AUTHN_CONNECTION
org.forgerock.security.authcid
and it MUST contain a
String
if it is present.AuthenticatedConnectionContext
,
Constant Field Valuespublic static Rest2LDAPContextFactory getHttpServletContextFactory()
This method is named getHttpServletContextFactory
so that it can
easily be used for
configuring
JSON Resource Servlets.
public org.forgerock.json.resource.Context createContext(org.forgerock.json.resource.Context parent, javax.servlet.http.HttpServletRequest request) throws org.forgerock.json.resource.ResourceException
Context
chain comprising of the provided parent
context(s), a SecurityContext
obtained using a
SecurityContextFactory
, and optionally a
AuthenticatedConnectionContext
. The authenticated connection will
be obtained from the ATTRIBUTE_AUTHN_CONNECTION
attribute
contained in the provided HTTP servlet request. If the attribute is not
present then the AuthenticatedConnectionContext
will not be
created.parent
- The parent context.request
- The HTTP servlet request from which the security and
authenticated connection attributes should be obtained.Context
chain comprising of the provided parent
context(s), a SecurityContext
obtained using a
SecurityContextFactory
, and optionally a
AuthenticatedConnectionContext
.org.forgerock.json.resource.ResourceException
- If one of the attributes was present but had the wrong type.public org.forgerock.json.resource.Context createContext(javax.servlet.http.HttpServletRequest request) throws org.forgerock.json.resource.ResourceException
Context
chain comprising of a RootContext
,
a SecurityContext
obtained using a SecurityContextFactory
, and optionally a AuthenticatedConnectionContext
. The
authenticated connection will be obtained from the
ATTRIBUTE_AUTHN_CONNECTION
attribute contained in the provided
HTTP servlet request. If the attribute is not present then the
AuthenticatedConnectionContext
will not be created.createContext
in interface org.forgerock.json.resource.servlet.HttpServletContextFactory
request
- The HTTP servlet request from which the security and
authenticated connection attributes should be obtained.Context
chain comprising of a RootContext
,
a SecurityContext
obtained using a
SecurityContextFactory
, and optionally a
AuthenticatedConnectionContext
.org.forgerock.json.resource.ResourceException
- If one of the attributes was present but had the wrong type.Copyright © 2011-2015 ForgeRock AS. All Rights Reserved.