authenticate.asciidoc 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. --
  2. :api: authenticate
  3. :response: AuthenticateResponse
  4. --
  5. [role="xpack"]
  6. [id="{upid}-{api}"]
  7. === Authenticate API
  8. [id="{upid}-{api}-sync"]
  9. ==== Execution
  10. Authenticating and retrieving information about a user can be performed
  11. using the `security().authenticate()` method:
  12. ["source","java",subs="attributes,callouts,macros"]
  13. --------------------------------------------------
  14. include-tagged::{doc-tests-file}[{api}-execute]
  15. --------------------------------------------------
  16. This method does not require a request object. The client waits for the
  17. +{response}+ to be returned before continuing with code execution.
  18. [id="{upid}-{api}-response"]
  19. ==== Response
  20. The returned +{response}+ contains four fields. The `user` field
  21. , accessed with `getUser`, contains all the information about this
  22. authenticated user. The field `enabled`, tells if this user is actually
  23. usable or has been temporarily deactivated. The field `authentication_realm`,
  24. accessed with `getAuthenticationRealm` contains the name and type of the
  25. Realm that has authenticated the user and the field `lookup_realm`,
  26. accessed with `getLookupRealm` contains the name and type of the Realm where
  27. the user information were retrieved from.
  28. ["source","java",subs="attributes,callouts,macros"]
  29. --------------------------------------------------
  30. include-tagged::{doc-tests-file}[{api}-response]
  31. --------------------------------------------------
  32. <1> `getUser` retrieves the `User` instance containing the information,
  33. see {javadoc-client}/security/user/User.html.
  34. <2> `enabled` tells if this user is usable or is deactivated.
  35. <3> `getAuthenticationRealm().getName()` retrieves the name of the realm that authenticated the user.
  36. <4> `getAuthenticationRealm().getType()` retrieves the type of the realm that authenticated the user.
  37. <5> `getLookupRealm().getName()` retrieves the name of the realm from where the user information is looked up.
  38. <6> `getLookupRealm().getType()` retrieves the type of the realm from where the user information is looked up.
  39. <7> `getAuthenticationType()` retrieves the authentication type of the authenticated user.
  40. <8> `getMetadata()` retrieves metadata relevant to this authentication.
  41. Note this is different from `user.getMetadata()`.
  42. For <<{upid}-create-service-account-token,service account token>> authentication, it contains
  43. a key of `_token_name` with the value being the token name.
  44. [id="{upid}-{api}-async"]
  45. ==== Asynchronous Execution
  46. This request can also be executed asynchronously:
  47. ["source","java",subs="attributes,callouts,macros"]
  48. --------------------------------------------------
  49. include-tagged::{doc-tests-file}[{api}-execute-async]
  50. --------------------------------------------------
  51. <1> The `ActionListener` to use when the execution completes. This method does
  52. not require a request object.
  53. The asynchronous method does not block and returns immediately. Once the request
  54. has completed the `ActionListener` is called back using the `onResponse` method
  55. if the execution completed successfully or using the `onFailure` method if
  56. it failed.
  57. A typical listener for a +{response}+ looks like:
  58. ["source","java",subs="attributes,callouts,macros"]
  59. --------------------------------------------------
  60. include-tagged::{doc-tests-file}[{api}-execute-listener]
  61. --------------------------------------------------
  62. <1> Called when the execution completed successfully. The response is
  63. provided as an argument.
  64. <2> Called in case of a failure. The exception is provided as an argument.