mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-11 07:25:23 +00:00
bdd8460906
This adds the security `_authenticate` API to the HLREST client. It is unlike some of the other APIs because the request does not have a body. The commit also creates the `User` entity. It is important to note that the `User` entity does not have the `enabled` flag. The `enabled` flag is part of the response, alongside the `User` entity. Moreover this adds the `SecurityIT` test class (extending `ESRestHighLevelClientTestCase`). Relates #29827
67 lines
2.3 KiB
Plaintext
67 lines
2.3 KiB
Plaintext
|
|
--
|
|
:api: authenticate
|
|
:response: AuthenticateResponse
|
|
--
|
|
|
|
[id="{upid}-{api}"]
|
|
=== Authenticate API
|
|
|
|
[id="{upid}-{api}-sync"]
|
|
==== Execution
|
|
|
|
Authenticating and retrieving information about a user can be performed
|
|
using the `security().authenticate()` method:
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
--------------------------------------------------
|
|
include-tagged::{doc-tests-file}[{api}-execute]
|
|
--------------------------------------------------
|
|
|
|
This method does not require a request object. The client waits for the
|
|
+{response}+ to be returned before continuing with code execution.
|
|
|
|
[id="{upid}-{api}-response"]
|
|
==== Response
|
|
|
|
The returned +{response}+ contains two fields. Firstly, the `user` field
|
|
, accessed with `getUser`, contains all the information about this
|
|
authenticated user. The other field, `enabled`, tells if this user is actually
|
|
usable or has been temporalily deactivated.
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
--------------------------------------------------
|
|
include-tagged::{doc-tests-file}[{api}-response]
|
|
--------------------------------------------------
|
|
<1> `getUser` retrieves the `User` instance containing the information,
|
|
see {javadoc-client}/security/user/User.html.
|
|
<2> `enabled` tells if this user is usable or is deactivated.
|
|
|
|
[id="{upid}-{api}-async"]
|
|
==== Asynchronous Execution
|
|
|
|
This request can also be executed asynchronously:
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
--------------------------------------------------
|
|
include-tagged::{doc-tests-file}[{api}-execute-async]
|
|
--------------------------------------------------
|
|
<1> The `ActionListener` to use when the execution completes. This method does
|
|
not require a request object.
|
|
|
|
The asynchronous method does not block and returns immediately. Once the request
|
|
has completed the `ActionListener` is called back using the `onResponse` method
|
|
if the execution completed successfully or using the `onFailure` method if
|
|
it failed.
|
|
|
|
A typical listener for a +{response}+ looks like:
|
|
|
|
["source","java",subs="attributes,callouts,macros"]
|
|
--------------------------------------------------
|
|
include-tagged::{doc-tests-file}[{api}-execute-listener]
|
|
--------------------------------------------------
|
|
<1> Called when the execution completed successfully. The response is
|
|
provided as an argument.
|
|
<2> Called in case of a failure. The exception is provided as an argument.
|
|
|