authenticate.asciidoc 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. [id="{upid}-{api}-async"]
  40. ==== Asynchronous Execution
  41. This request can also be executed asynchronously:
  42. ["source","java",subs="attributes,callouts,macros"]
  43. --------------------------------------------------
  44. include-tagged::{doc-tests-file}[{api}-execute-async]
  45. --------------------------------------------------
  46. <1> The `ActionListener` to use when the execution completes. This method does
  47. not require a request object.
  48. The asynchronous method does not block and returns immediately. Once the request
  49. has completed the `ActionListener` is called back using the `onResponse` method
  50. if the execution completed successfully or using the `onFailure` method if
  51. it failed.
  52. A typical listener for a +{response}+ looks like:
  53. ["source","java",subs="attributes,callouts,macros"]
  54. --------------------------------------------------
  55. include-tagged::{doc-tests-file}[{api}-execute-listener]
  56. --------------------------------------------------
  57. <1> Called when the execution completed successfully. The response is
  58. provided as an argument.
  59. <2> Called in case of a failure. The exception is provided as an argument.