HTTP access
Set the HTTP port
The following steps demonstrate how to set up an HTTP port if none was configured at setup time
with the --httpPort
option:
-
Create an HTTP connection handler:
$ dsconfig \ create-connection-handler \ --hostname localhost \ --port 4444 \ --bindDN uid=admin \ --bindPassword password \ --handler-name HTTP \ --type http \ --set enabled:true \ --set listen-port:8080 \ --no-prompt \ --usePkcs12TrustStore /path/to/opendj/config/keystore \ --trustStorePassword:file /path/to/opendj/config/keystore.pin
-
Enable an HTTP access log.
-
The following command enables JSON-based HTTP access logging:
$ dsconfig \ set-log-publisher-prop \ --hostname localhost \ --port 4444 \ --bindDN uid=admin \ --bindPassword password \ --publisher-name "Json File-Based HTTP Access Logger" \ --set enabled:true \ --no-prompt \ --usePkcs12TrustStore /path/to/opendj/config/keystore \ --trustStorePassword:file /path/to/opendj/config/keystore.pin
-
The following command enables HTTP access logging:
$ dsconfig \ set-log-publisher-prop \ --hostname localhost \ --port 4444 \ --bindDN uid=admin \ --bindPassword password \ --publisher-name "File-Based HTTP Access Logger" \ --set enabled:true \ --no-prompt \ --usePkcs12TrustStore /path/to/opendj/config/keystore \ --trustStorePassword:file /path/to/opendj/config/keystore.pin
-
-
After you set up an HTTP port, enable an HTTP endpoint.
For details, see Configure HTTP user APIs or Use administrative APIs.
Set the HTTPS port
At setup time use the --httpsPort
option.
Later, follow these steps to set up an HTTPS port:
-
Create an HTTPS connection handler.
The following example sets the port to
8443
and uses the default server certificate:$ dsconfig \ create-connection-handler \ --hostname localhost \ --port 4444 \ --bindDN uid=admin \ --bindPassword password \ --handler-name HTTPS \ --type http \ --set enabled:true \ --set listen-port:8443 \ --set use-ssl:true \ --set key-manager-provider:PKCS12 \ --set trust-manager-provider:"JVM Trust Manager" \ --usePkcs12TrustStore /path/to/opendj/config/keystore \ --trustStorePassword:file /path/to/opendj/config/keystore.pin \ --no-prompt
If the key manager provider has multiple key pairs that DS could use for TLS, where the secret key was generated with the same key algorithm, such as
EC
orRSA
, you can specify which key pairs to use with the--set ssl-cert-nickname:server-cert
option. The server-cert is the certificate alias of the key pair. This option is not necessary if there is only one server key pair, or if each secret key was generated with a different key algorithm. -
Enable the HTTP access log.
-
The following command enables JSON-based HTTP access logging:
$ dsconfig \ set-log-publisher-prop \ --hostname localhost \ --port 4444 \ --bindDN uid=admin \ --bindPassword password \ --publisher-name "Json File-Based HTTP Access Logger" \ --set enabled:true \ --no-prompt \ --usePkcs12TrustStore /path/to/opendj/config/keystore \ --trustStorePassword:file /path/to/opendj/config/keystore.pin
-
The following command enables HTTP access logging:
$ dsconfig \ set-log-publisher-prop \ --hostname localhost \ --port 4444 \ --bindDN uid=admin \ --bindPassword password \ --publisher-name "File-Based HTTP Access Logger" \ --set enabled:true \ --no-prompt \ --usePkcs12TrustStore /path/to/opendj/config/keystore \ --trustStorePassword:file /path/to/opendj/config/keystore.pin
-
-
If the deployment requires SSL client authentication, set the properties
ssl-client-auth-policy
andtrust-manager-provider
appropriately. -
After you set up an HTTPS port, enable an HTTP endpoint.
For details, see Configure HTTP user APIs, or Use administrative APIs.
Configure HTTP user APIs
The way directory data appears to client applications is configurable. You configure a Rest2ldap endpoint for each HTTP API to user data.
A Rest2ldap mapping file defines how JSON resources map to LDAP entries.
The default mapping file is /path/to/opendj/config/rest2ldap/endpoints/api/example-v1.json
.
The default mapping works with Example.com data from the evaluation setup profile.
Edit or add mapping files for your own APIs. For details, see REST to LDAP reference.
If you have set up a directory server with the ds-evaluation
profile, you can skip the first two steps:
-
If necessary, change the properties of the default Rest2ldap endpoint, or create a new endpoint.
The default Rest2ldap HTTP endpoint is named
/api
after itsbase-path
. Thebase-path
must be the same as the name, and is read-only after creation. By default, the/api
endpoint requires authentication.The following example enables the default
/api
endpoint:$ dsconfig \ set-http-endpoint-prop \ --hostname localhost \ --port 4444 \ --bindDN uid=admin \ --bindPassword password \ --endpoint-name /api \ --set authorization-mechanism:"HTTP Basic" \ --set config-directory:config/rest2ldap/endpoints/api \ --set enabled:true \ --no-prompt \ --usePkcs12TrustStore /path/to/opendj/config/keystore \ --trustStorePassword:file /path/to/opendj/config/keystore.pin
Alternatively, you can create another Rest2ldap endpoint to expose a different HTTP API, or to publish data under an alternative base path, such as
/rest
:$ dsconfig \ create-http-endpoint \ --hostname localhost \ --port 4444 \ --bindDN uid=admin \ --bindPassword password \ --endpoint-name /rest \ --type rest2ldap-endpoint \ --set authorization-mechanism:"HTTP Basic" \ --set config-directory:config/rest2ldap/endpoints/api \ --set enabled:true \ --no-prompt \ --usePkcs12TrustStore /path/to/opendj/config/keystore \ --trustStorePassword:file /path/to/opendj/config/keystore.pin
-
If necessary, adjust the endpoint configuration to use an alternative HTTP authorization mechanism.
By default, the Rest2ldap endpoint maps HTTP Basic authentication to LDAP authentication. Change the
authorization-mechanism
setting as necessary. For details, see Configure HTTP Authorization. -
Try reading a resource.
The following example generates the CA certificate in PEM format from the server deployment ID and password. It uses the CA certificate to trust the server certificate. A CA certificate is only necessary if the CA is not well-known:
$ dskeymgr \ export-ca-cert \ --deploymentId $DEPLOYMENT_ID \ --deploymentIdPassword password \ --outputFile ca-cert.pem $ curl \ --cacert ca-cert.pem \ --user bjensen:hifalutin \ https://localhost:8443/api/users/bjensen?_prettyPrint=true { "_id" : "bjensen", "_rev" : "<revision>", "_schema" : "frapi:opendj:rest2ldap:posixUser:1.0", "userName" : "bjensen@example.com", "displayName" : [ "Barbara Jensen", "Babs Jensen" ], "name" : { "givenName" : "Barbara", "familyName" : "Jensen" }, "description" : "Original description", "manager" : { "_id" : "trigden", "_rev" : "<revision>" }, "groups" : [ { "_id" : "Carpoolers", "_rev" : "<revision>" } ], "contactInformation" : { "telephoneNumber" : "+1 408 555 1862", "emailAddress" : "bjensen@example.com" }, "uidNumber" : 1076, "gidNumber" : 1000, "homeDirectory" : "/home/bjensen" }
Configure HTTP authorization
HTTP authorization mechanisms map HTTP credentials to LDAP credentials.
Multiple HTTP authorization mechanisms can be enabled simultaneously. You can assign different mechanisms to Rest2ldap endpoints and to the Admin endpoint.
By default, these HTTP authorization mechanisms are supported:
- HTTP Anonymous
-
Process anonymous HTTP requests, optionally binding with a specified DN.
If no bind DN is specified (default), anonymous LDAP requests are used.
This mechanism is enabled by default.
- HTTP Basic (enabled by default)
-
Process HTTP Basic authentication requests by mapping the HTTP Basic identity to a user’s directory account.
By default, the exact match identity mapper with its default configuration is used to map the HTTP Basic user name to an LDAP
uid
. The DS server then searches in all local public naming contexts to find the user’s entry based in theuid
value. For details, see Identity Mappers. - HTTP OAuth2 CTS
-
Process OAuth 2.0 requests as a resource server, acting as an AM Core Token Service (CTS) store.
When the client bearing an OAuth 2.0 access token presents the token to access the JSON resource, the server tries to resolve the access token against the CTS data that it serves for AM. If the access token resolves correctly (is found in the CTS data and has not expired), the DS server extracts the user identity and OAuth 2.0 scopes. If the required scopes are present and the token is valid, it maps the user identity to a directory account.
This mechanism makes it possible to resolve access tokens by making an internal request, avoiding a request to AM. This mechanism does not ensure that the token requested will have already been replicated to the replica where the request is routed.
AM’s CTS store is constrained to a specific layout. The
authzid-json-pointer
must useuserName/0
for the user identifier. - HTTP OAuth2 OpenAM
-
Process OAuth 2.0 requests as a resource server, sending requests to AM for access token resolution.
When the client bearing an OAuth 2.0 access token presents the token to access the JSON resource, the directory service requests token information from AM. If the access token is valid, the DS server extracts the user identity and OAuth 2.0 scopes. If the required scopes are present, it maps the user identity to a directory account.
Access token resolution requests should be sent over HTTPS. You can configure a truststore manager if necessary to trust the authorization server certificate, and a keystore manager to obtain the DS server certificate if the authorization server requires mutual authentication.
- HTTP OAuth2 Token Introspection (RFC7662)
-
Handle OAuth 2.0 requests as a resource server, sending requests to an RFC 7662-compliant authorization server for access token resolution.
The DS server must be registered as a client of the authorization server.
When the client bearing an OAuth 2.0 access token presents the token to access the JSON resource, the DS server requests token introspection from the authorization server. If the access token is valid, the DS server extracts the user identity and OAuth 2.0 scopes. If the required scopes are present, it maps the user identity to a directory account.
Access token resolution requests should be sent over HTTPS. You can configure a truststore manager if necessary to trust the authorization server certificate, and a keystore manager to obtain the DS server certificate if the authorization server requires mutual authentication.
The HTTP OAuth2 File mechanism is an internal interface intended for testing, and not supported for production use. |
When more than one authentication mechanism is specified, mechanisms are applied in the following order:
-
If the client request has an
Authorization
header, and an OAuth 2.0 mechanism is specified, the server attempts to apply the OAuth 2.0 mechanism. -
If the client request has an
Authorization
header, or has the custom credentials headers specified in the configuration, and an HTTP Basic mechanism is specified, the server attempts to apply the Basic Auth mechanism. -
Otherwise, if an HTTP anonymous mechanism is specified, and none of the previous mechanisms apply, the server attempts to apply the mechanism for anonymous HTTP requests.
There are many possibilities when configuring HTTP authorization mechanisms. This procedure shows only one OAuth 2.0 example.
The example below uses settings as listed in the following table. When using secure connections, make sure the servers can trust each other’s certificates. Download ForgeRock Access Management software from the ForgeRock BackStage download site:
Setting | Value |
---|---|
OpenAM URL |
|
Authorization server endpoint |
|
Identity repository |
DS server configured by the examples that follow. |
OAuth 2.0 client ID |
|
OAuth 2.0 client secret |
|
OAuth 2.0 client scopes |
|
Rest2ldap configuration |
Default settings. See Configure HTTP User APIs. |
Read the ForgeRock Access Management documentation if necessary to install and configure AM. Then follow these steps to try the demonstration:
-
Update the default HTTP OAuth2 OpenAM configuration:
$ dsconfig \ set-http-authorization-mechanism-prop \ --hostname localhost \ --port 4444 \ --bindDN uid=admin \ --bindPassword password \ --mechanism-name "HTTP OAuth2 OpenAM" \ --set enabled:true \ --set token-info-url:https://am.example.com:8443/openam/oauth2/tokeninfo \ --no-prompt \ --usePkcs12TrustStore /path/to/opendj/config/keystore \ --trustStorePassword:file /path/to/opendj/config/keystore.pin
-
Update the default Rest2ldap endpoint configuration to use HTTP OAuth2 OpenAM as the authorization mechanism:
$ dsconfig \ set-http-endpoint-prop \ --hostname localhost \ --port 4444 \ --bindDN uid=admin \ --bindPassword password \ --endpoint-name "/api" \ --set authorization-mechanism:"HTTP OAuth2 OpenAM" \ --no-prompt \ --usePkcs12TrustStore /path/to/opendj/config/keystore \ --trustStorePassword:file /path/to/opendj/config/keystore.pin
-
Obtain an access token with the appropriate scopes:
$ curl \ --request POST \ --user "myClientID:password" \ --data "grant_type=password&username=bjensen&password=hifalutin&scope=read%20uid%20write" \ https://am.example.com:8443/openam/oauth2/access_token { "access_token": "token-string", "scope": "uid read write", "token_type": "Bearer", "expires_in": 3599 }
Use HTTPS when obtaining access tokens.
-
Request a resource at the Rest2ldap endpoint using HTTP Bearer authentication with the access token:
$ curl \ --header "Authorization: Bearer token-string" \ --cacert ca-cert.pem \ https://localhost:8443/api/users/bjensen?_prettyPrint=true { "_id": "bjensen", "_rev": "<revision>", "_schema": "frapi:opendj:rest2ldap:posixUser:1.0", "_meta": {}, "userName": "bjensen@example.com", "displayName": ["Barbara Jensen", "Babs Jensen"], "name": { "givenName": "Barbara", "familyName": "Jensen" }, "description": "Original description", "contactInformation": { "telephoneNumber": "+1 408 555 1862", "emailAddress": "bjensen@example.com" }, "uidNumber": 1076, "gidNumber": 1000, "homeDirectory": "/home/bjensen", "manager": { "_id": "trigden", "displayName": "Torrey Rigden" } }
Use HTTPS when presenting access tokens.
Use administrative APIs
The APIs for configuring and monitoring DS servers are under the following endpoints:
/admin/config
-
Provides a REST API to the server configuration under
cn=config
.By default, this endpoint is protected by the HTTP Basic authorization mechanism. Users reading and editing the configuration must have appropriate privileges, such as
config-read
andconfig-write
.Each LDAP entry maps to a resource under
/admin/config
, with default values shown in the resource even if they are not set in the LDAP representation. /alive
-
Provides an endpoint to check whether the server is currently alive, meaning that its internal checks have not found any errors that would require administrative action.
By default, this endpoint returns a status code to anonymous requests, and supports authenticated requests. For details, see Server is Alive (HTTP).
/healthy
-
Provides an endpoint to check whether the server is currently healthy, meaning that it is alive and any replication delays are below a configurable threshold.
By default, this endpoint returns a status code to anonymous requests, and supports authenticated requests. For details, see Server Health (HTTP).
/metrics/api
-
Provides read-only access through Forgerock Common REST to a JSON-based view of
cn=monitor
and the monitoring backend.By default, the HTTP Basic authorization mechanism protects this endpoint. Users reading monitoring information must have the
monitor-read
privilege.The endpoint represents a collection where each LDAP entry maps to a resource under
/metrics/api
. Use a REST Query with a_queryFilter
parameter to access this endpoint. To return all resources, use/metrics/api?_queryFilter=true
. /metrics/prometheus
-
Provides an API to the server monitoring information for use with Prometheus monitoring software.
By default, this endpoint is protected by the HTTP Basic authorization mechanism. Users reading monitoring information must have the
monitor-read
privilege.
To use the Admin endpoint APIs, follow these steps:
-
Grant users access to the endpoints as appropriate:
-
For access to
/admin/config
, assignconfig-read
orconfig-write
privileges, and a global ACI to read or updatecn=config
.The following example grants Kirsten Vaughan access to read the configuration:
$ ldapmodify \ --hostname localhost \ --port 1636 \ --useSsl \ --usePkcs12TrustStore /path/to/opendj/config/keystore \ --trustStorePassword:file /path/to/opendj/config/keystore.pin \ --bindDN uid=admin \ --bindPassword password << EOF dn: uid=kvaughan,ou=People,dc=example,dc=com changetype: modify add: ds-privilege-name ds-privilege-name: config-read EOF $ dsconfig \ set-access-control-handler-prop \ --add global-aci:\(target=\"ldap:///cn=config\"\)\(targetattr=\"*\"\)\ \(version\ 3.0\;\ acl\ \"Read\ configuration\"\;\ allow\ \(read,search\)\ userdn=\"ldap:///uid=kvaughan,ou=People,dc=example,dc=com\"\;\) \ --hostname localhost \ --port 4444 \ --bindDN uid=admin \ --bindPassword password \ --usePkcs12TrustStore /path/to/opendj/config/keystore \ --trustStorePassword:file /path/to/opendj/config/keystore.pin \ --no-prompt
-
For access to
/metrics
endpoints, if no account for monitoring was created at setup time, assign themonitor-read
privilege.The following example adds the
monitor-read
privilege to Kirsten Vaughan’s entry:$ ldapmodify \ --hostname localhost \ --port 1636 \ --useSsl \ --usePkcs12TrustStore /path/to/opendj/config/keystore \ --trustStorePassword:file /path/to/opendj/config/keystore.pin \ --bindDN uid=admin \ --bindPassword password << EOF dn: uid=kvaughan,ou=People,dc=example,dc=com changetype: modify add: ds-privilege-name ds-privilege-name: monitor-read EOF
For details, see Administrative privileges.
-
-
Adjust the
authorization-mechanism
settings for the Admin endpoint.By default, the Admin endpoint uses the HTTP Basic authorization mechanism. The HTTP Basic authorization mechanism default configuration resolves the user identity extracted from the HTTP request to an LDAP user identity as follows:
-
If the request has an
Authorization: Basic
header for HTTP Basic authentication, the server extracts the username and password. -
If the request has
X-OpenIDM-Username
andX-OpenIDM-Password
headers, the server extracts the username and password. -
The server uses the default exact match identity mapper to search for a unique match between the username and the UID attribute value of an entry in the local public naming contexts of the DS server.
In other words, in LDAP terms, it searches under all user data base DNs for
(uid=http-username)
. The usernamekvaughan
maps to the example entry with DNuid=kvaughan,ou=People,dc=example,dc=com
.For details, see Identity mappers, and Configure HTTP authorization.
-
-
Test access to the endpoint as an authorized user.
The following example reads the Admin endpoint resource under
/admin/config
. The following example generates the CA certificate in PEM format from the server deployment ID and password. It uses the CA certificate to trust the server certificate. A CA certificate is only necessary if the CA is not well-known:$ dskeymgr \ export-ca-cert \ --deploymentId $DEPLOYMENT_ID \ --deploymentIdPassword password \ --outputFile ca-cert.pem $ curl \ --cacert ca-cert.pem \ --user kvaughan:bribery \ https://localhost:8443/admin/config/http-endpoints/%2Fadmin?_prettyPrint=true { "_id" : "/admin", "_rev" : "<revision>", "_schema" : "admin-endpoint", "java-class" : "org.opends.server.protocols.http.rest2ldap.AdminEndpoint", "base-path" : "/admin", "authorization-mechanism" : [ { "_id" : "HTTP Basic", "_rev" : "<revision>" } ], "enabled" : true }
Notice how the path to the resource in the example above,
/admin/config/http-endpoints/%2Fadmin
, corresponds to the DN of the entry undercn=config
, which isds-cfg-base-path=/admin,cn=HTTP Endpoints,cn=config
.The following example demonstrates reading everything under
/metrics/api
:$ curl \ --cacert ca-cert.pem \ --user kvaughan:bribery \ https://localhost:8443/metrics/api?_queryFilter=true