privileges.asciidoc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. [role="xpack"]
  2. [[security-api-privileges]]
  3. === Privilege APIs
  4. [[security-api-has-privilege]]
  5. The `has_privileges` API allows you to determine whether the logged in user has
  6. a specified list of privileges.
  7. ==== Request
  8. `GET _xpack/security/user/_has_privileges`
  9. ==== Description
  10. For a list of the privileges that you can specify in this API,
  11. see {xpack-ref}/security-privileges.html[Security Privileges].
  12. A successful call returns a JSON structure that shows whether each specified
  13. privilege is assigned to the user.
  14. ==== Request Body
  15. `cluster`:: (list) A list of the cluster privileges that you want to check.
  16. `index`::
  17. `names`::: (list) A list of indices.
  18. `privileges`::: (list) A list of the privileges that you want to check for the
  19. specified indices.
  20. ==== Authorization
  21. All users can use this API, but only to determine their own privileges.
  22. To check the privileges of other users, you must use the run as feature. For
  23. more information, see
  24. {xpack-ref}/run-as-privilege.html[Submitting Requests on Behalf of Other Users].
  25. ==== Examples
  26. The following example checks whether the current user has a specific set of
  27. cluster and indices privileges:
  28. [source,js]
  29. --------------------------------------------------
  30. GET _xpack/security/user/_has_privileges
  31. {
  32. "cluster": [ "monitor", "manage" ],
  33. "index" : [
  34. {
  35. "names": [ "suppliers", "products" ],
  36. "privileges": [ "read" ]
  37. },
  38. {
  39. "names": [ "inventory" ],
  40. "privileges" : [ "read", "write" ]
  41. }
  42. ]
  43. }
  44. --------------------------------------------------
  45. // CONSOLE
  46. The following example output indicates which privileges the "rdeniro" user has:
  47. [source,js]
  48. --------------------------------------------------
  49. {
  50. "username": "rdeniro",
  51. "has_all_requested" : false,
  52. "cluster" : {
  53. "monitor" : true,
  54. "manage" : false
  55. },
  56. "index" : {
  57. "suppliers" : {
  58. "read" : true
  59. },
  60. "products" : {
  61. "read" : true
  62. },
  63. "inventory" : {
  64. "read" : true,
  65. "write" : false
  66. }
  67. },
  68. "application" : {}
  69. }
  70. --------------------------------------------------
  71. // TESTRESPONSE[s/"rdeniro"/"$body.username"/]
  72. // TESTRESPONSE[s/: false/: true/]