has-privileges.asciidoc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. [role="xpack"]
  2. [[security-api-has-privileges]]
  3. === Has Privileges API
  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 {stack-ov}/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. `application`::
  21. `application`::: (string) The name of the application.
  22. `privileges`::: (list) A list of the privileges that you want to check for the
  23. specified resources. May be either application privilege names, or the names of
  24. actions that are granted by those privileges
  25. `resources`::: (list) A list of resource names against which the privileges
  26. should be checked
  27. ==== Authorization
  28. All users can use this API, but only to determine their own privileges.
  29. To check the privileges of other users, you must use the run as feature. For
  30. more information, see
  31. {xpack-ref}/run-as-privilege.html[Submitting Requests on Behalf of Other Users].
  32. ==== Examples
  33. The following example checks whether the current user has a specific set of
  34. cluster, index, and application privileges:
  35. [source,js]
  36. --------------------------------------------------
  37. GET _xpack/security/user/_has_privileges
  38. {
  39. "cluster": [ "monitor", "manage" ],
  40. "index" : [
  41. {
  42. "names": [ "suppliers", "products" ],
  43. "privileges": [ "read" ]
  44. },
  45. {
  46. "names": [ "inventory" ],
  47. "privileges" : [ "read", "write" ]
  48. }
  49. ],
  50. "application": [
  51. {
  52. "application": "inventory_manager",
  53. "privileges" : [ "read", "data:write/inventory" ],
  54. "resources" : [ "product/1852563" ]
  55. }
  56. ]
  57. }
  58. --------------------------------------------------
  59. // CONSOLE
  60. The following example output indicates which privileges the "rdeniro" user has:
  61. [source,js]
  62. --------------------------------------------------
  63. {
  64. "username": "rdeniro",
  65. "has_all_requested" : false,
  66. "cluster" : {
  67. "monitor" : true,
  68. "manage" : false
  69. },
  70. "index" : {
  71. "suppliers" : {
  72. "read" : true
  73. },
  74. "products" : {
  75. "read" : true
  76. },
  77. "inventory" : {
  78. "read" : true,
  79. "write" : false
  80. }
  81. },
  82. "application" : {
  83. "inventory_manager" : {
  84. "product/1852563" : {
  85. "read": false,
  86. "data:write/inventory": false
  87. }
  88. }
  89. }
  90. }
  91. --------------------------------------------------
  92. // TESTRESPONSE[s/"rdeniro"/"$body.username"/]
  93. // TESTRESPONSE[s/: false/: true/]