has-privileges.asciidoc 3.5 KB

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