put-role-mapping.asciidoc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. [role="xpack"]
  2. [[java-rest-high-security-put-role-mapping]]
  3. === Create or update role mapping API
  4. [[java-rest-high-security-put-role-mapping-execution]]
  5. ==== Execution
  6. Creating and updating a role mapping can be performed using the `security().putRoleMapping()`
  7. method:
  8. ["source","java",subs="attributes,callouts,macros"]
  9. --------------------------------------------------
  10. include-tagged::{doc-tests}/SecurityDocumentationIT.java[put-role-mapping-execute]
  11. --------------------------------------------------
  12. [[java-rest-high-security-put-role-mapping-response]]
  13. ==== Response
  14. The returned `PutRoleMappingResponse` contains a single field, `created`. This field
  15. serves as an indication if a role mapping was created or if an existing entry was updated.
  16. ["source","java",subs="attributes,callouts,macros"]
  17. --------------------------------------------------
  18. include-tagged::{doc-tests}/SecurityDocumentationIT.java[put-role-mapping-response]
  19. --------------------------------------------------
  20. <1> `created` is a boolean indicating whether the role mapping was created or updated
  21. [[java-rest-high-security-put-role-mapping-async]]
  22. ==== Asynchronous Execution
  23. This request can be executed asynchronously using the `security().putRoleMappingAsync()`
  24. method:
  25. ["source","java",subs="attributes,callouts,macros"]
  26. --------------------------------------------------
  27. include-tagged::{doc-tests}/SecurityDocumentationIT.java[put-role-mapping-execute-async]
  28. --------------------------------------------------
  29. <1> The `PutRoleMappingRequest` to execute and the `ActionListener` to use when
  30. the execution completes
  31. The asynchronous method does not block and returns immediately. Once the request
  32. has completed the `ActionListener` is called back using the `onResponse` method
  33. if the execution successfully completed or using the `onFailure` method if
  34. it failed.
  35. A typical listener for a `PutRoleMappingResponse` looks like:
  36. ["source","java",subs="attributes,callouts,macros"]
  37. --------------------------------------------------
  38. include-tagged::{doc-tests}/SecurityDocumentationIT.java[put-role-mapping-execute-listener]
  39. --------------------------------------------------
  40. <1> Called when the execution is successfully completed. The response is
  41. provided as an argument
  42. <2> Called in case of failure. The raised exception is provided as an argument