has-privileges.asciidoc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. [role="xpack"]
  2. [[security-api-has-privileges]]
  3. === Has privileges API
  4. ++++
  5. <titleabbrev>Has privileges</titleabbrev>
  6. ++++
  7. [[security-api-has-privilege]]
  8. Determines whether the logged in user has a specified list of privileges.
  9. [[security-api-has-privileges-request]]
  10. ==== {api-request-title}
  11. `GET /_security/user/_has_privileges`
  12. `POST /_security/user/_has_privileges`
  13. [[security-api-has-privileges-prereqs]]
  14. ==== {api-prereq-title}
  15. * All users can use this API, but only to determine their own privileges.
  16. To check the privileges of other users, you must use the run as feature. For
  17. more information, see
  18. <<run-as-privilege>>.
  19. [[security-api-has-privileges-desc]]
  20. ==== {api-description-title}
  21. For a list of the privileges that you can specify in this API,
  22. see <<security-privileges>>.
  23. A successful call returns a JSON structure that shows whether each specified
  24. privilege is assigned to the user.
  25. [[security-api-has-privileges-request-body]]
  26. ==== {api-request-body-title}
  27. `cluster`:: (list) A list of the cluster privileges that you want to check.
  28. `index`::
  29. `names`::: (list) A list of indices.
  30. `allow_restricted_indices`::: (Boolean) This needs to be set to `true` (default
  31. is `false`) if using wildcards or regexps for patterns that cover restricted
  32. indices. Implicitly, restricted indices do not match index patterns because
  33. restricted indices usually have limited privileges and including them in
  34. pattern tests would render most such tests `false`. If restricted indices are
  35. explicitly included in the `names` list, privileges will be checked against
  36. them regardless of the value of `allow_restricted_indices`.
  37. `privileges`::: (list) A list of the privileges that you want to check for the
  38. specified indices.
  39. `application`::
  40. `application`::: (string) The name of the application.
  41. `privileges`::: (list) A list of the privileges that you want to check for the
  42. specified resources. May be either application privilege names, or the names of
  43. actions that are granted by those privileges
  44. `resources`::: (list) A list of resource names against which the privileges
  45. should be checked
  46. [[security-api-has-privileges-example]]
  47. ==== {api-examples-title}
  48. The following example checks whether the current user has a specific set of
  49. cluster, index, and application privileges:
  50. [source,console]
  51. --------------------------------------------------
  52. GET /_security/user/_has_privileges
  53. {
  54. "cluster": [ "monitor", "manage" ],
  55. "index" : [
  56. {
  57. "names": [ "suppliers", "products" ],
  58. "privileges": [ "read" ]
  59. },
  60. {
  61. "names": [ "inventory" ],
  62. "privileges" : [ "read", "write" ]
  63. }
  64. ],
  65. "application": [
  66. {
  67. "application": "inventory_manager",
  68. "privileges" : [ "read", "data:write/inventory" ],
  69. "resources" : [ "product/1852563" ]
  70. }
  71. ]
  72. }
  73. --------------------------------------------------
  74. The following example output indicates which privileges the "rdeniro" user has:
  75. [source,console-result]
  76. --------------------------------------------------
  77. {
  78. "username": "rdeniro",
  79. "has_all_requested" : false,
  80. "cluster" : {
  81. "monitor" : true,
  82. "manage" : false
  83. },
  84. "index" : {
  85. "suppliers" : {
  86. "read" : true
  87. },
  88. "products" : {
  89. "read" : true
  90. },
  91. "inventory" : {
  92. "read" : true,
  93. "write" : false
  94. }
  95. },
  96. "application" : {
  97. "inventory_manager" : {
  98. "product/1852563" : {
  99. "read": false,
  100. "data:write/inventory": false
  101. }
  102. }
  103. }
  104. }
  105. --------------------------------------------------
  106. // TESTRESPONSE[s/"rdeniro"/"$body.username"/]
  107. // TESTRESPONSE[s/: false/: true/]