Accessing nevisIDM over REST from nevisAuth ScriptState
The nevisIDM REST services can be accessed from within the nevisAuth AuthState ScriptState
with an API included in the package nevisidmcl. To make the API available in the ScriptState, the classpath of the AuthEngine must be extended with the path/opt/nevisidmcl/nevisauth/lib. The API can be used to cover use-cases which are not supported out-of-the-box by the nevisIDM authentication plug-ins.
API
The API is located in the package ch.nevis.idm.client and supports the following elements:
IdmRestClient
The IdmRestClient can be used to access nevisIDM as the nevisauth user. The supported methods are listed in the following table.
Method | Inputs | Output | Description |
---|---|---|---|
String get (String url) | String url: URL of the REST endpoint. | String containing the JSON response body. | Performs a GET request to the input URL. Throws an IdmRestClientException if the return code is greater than or equal to 400. |
String patch (String url, String body) | String url: URL of the REST endpoint. String body: JSON request body to be used in the PATCH request. | String containing the JSON response body. | Performs a PATCH request to the input URL with the input request body. Throws an IdmRestClientException if the return code is greater than or equal to 400. |
String post (String url, String body) | String url: URL of the REST endpoint. String body: JSON request body to be used in the POST request. | String containing the location header, if available. | Performs a POST request to the input URL with the input request body. Throws an IdmRestClientException if the return code is greater than or equal to 400. |
void put (String url) | String url: URL of the REST endpoint. | - | Performs a PUT request to the input URL. Throws an IdmRestClientException if the return code is greater than or equal to 400. |
void delete (String url) | String url: URL of the REST endpoint. | - | Performs a DELETE request to the input URL. Throws an IdmRestClientException if the return code is greater than or equal to 400. |
IdmRestClientFactory
The IdmRestClientFactory is a factory to get an instance of an IdmRestClient.
Method | Output | Description |
---|---|---|
IdmRestClient getInstance() | An IdmRestClient instance. | A factory to get an instance of an IdmRestClient. |
IdmRestClientException
The IdmRestClientException is a runtime exception that is thrown in case of failures in the IdmRestClient.
AuthTokenProvider
The AuthTokenProvider creates a signed token with the provided lifetime for the nevisauth user in nevisIDM.
Method | Input | Output | Description |
---|---|---|---|
String getAuthTokenString(long timeToLive) | long timeToLive: The lifetime of the signed token in seconds. | String containing a signed token for the nevisauth user in nevisIDM. | Creates a signed token for the nevisauth user in nevisIDM. The lifetime of the token corresponds with the value provided in timeToLive. Throws an AuthTokenProviderException in case of failure. |
AuthTokenProviderFactory
The AuthTokenProviderFactory is a factory to get an instance of an AuthTokenProvider.
Method | Output | Description |
---|---|---|
AuthTokenProvider getInstance() | An AuthTokenProvider instance. | A factory to get an instance of an AuthTokenProvider. |
AuthTokenProviderException
The AuthTokenProviderException is a runtime exception that is thrown in case of failures in the AuthTokenProvider.
Example
The following code block shows a simple GET REST request example to retrieve the default client.
Retrieving the default client
import ch.nevis.idm.client.IdmRestClient
import ch.nevis.idm.client.IdmRestClientFactory
// Input
String url = 'http://your-hostname:8989/nevisidm/api/core/v1/clients/100'
IdmRestClient idmRestClient = new IdmRestClientFactory().getInstance()
String result = 'Done'
try {
result = idmRestClient.get(url)
} catch(Exception e) {
LOG.error(e)
result = e.getMessage()
}
// Output
LOG.info("Result: $result");
notes.setProperty('result', result)