Skip to content

Commit 828ff01

Browse files
authored
[DOCS] Update snippets in security APIs (#46191) (#46401)
1 parent caf3e4d commit 828ff01

30 files changed

+99
-203
lines changed

x-pack/docs/en/rest-api/security/authenticate.asciidoc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ If the user cannot be authenticated, this API returns a 401 status code.
3131
To authenticate a user, submit a GET request to the
3232
`/_security/_authenticate` endpoint:
3333

34-
[source,js]
34+
[source,console]
3535
--------------------------------------------------
3636
GET /_security/_authenticate
3737
--------------------------------------------------
38-
// CONSOLE
3938

4039
The following example output provides information about the "rdeniro" user:
4140

42-
[source,js]
41+
[source,console-result]
4342
--------------------------------------------------
4443
{
4544
"username": "rdeniro",

x-pack/docs/en/rest-api/security/change-password.asciidoc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,18 @@ For more information about the native realm, see
5151

5252
The following example updates the password for the `jacknich` user:
5353

54-
[source,js]
54+
[source,console]
5555
--------------------------------------------------
5656
POST /_security/user/jacknich/_password
5757
{
5858
"password" : "s3cr3t"
5959
}
6060
--------------------------------------------------
61-
// CONSOLE
6261
// TEST[setup:jacknich_user]
6362

6463
A successful call returns an empty JSON structure.
6564

66-
[source,js]
65+
[source,console-result]
6766
--------------------------------------------------
6867
{}
6968
--------------------------------------------------
70-
// TESTRESPONSE

x-pack/docs/en/rest-api/security/clear-cache.asciidoc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,22 @@ To evict roles from the role cache, see the
4444

4545
For example, to evict all users cached by the `file` realm:
4646

47-
[source,js]
47+
[source,console]
4848
--------------------------------------------------
4949
POST /_security/realm/default_file/_clear_cache
5050
--------------------------------------------------
51-
// CONSOLE
5251

5352
To evict selected users, specify the `usernames` parameter:
5453

55-
[source,js]
54+
[source,console]
5655
--------------------------------------------------
5756
POST /_security/realm/default_file/_clear_cache?usernames=rdeniro,alpacino
5857
--------------------------------------------------
59-
// CONSOLE
6058

6159
To clear the caches for multiple realms, specify the realms as a comma-delimited
6260
list:
6361

64-
[source, js]
62+
[source,console]
6563
------------------------------------------------------------
6664
POST /_security/realm/default_file,ldap1/_clear_cache
6765
------------------------------------------------------------
68-
// CONSOLE

x-pack/docs/en/rest-api/security/clear-roles-cache.asciidoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ For more information about the native realm, see
3636
The clear roles cache API evicts roles from the native role cache. For example,
3737
to clear the cache for `my_admin_role`:
3838

39-
[source,js]
39+
[source,console]
4040
--------------------------------------------------
4141
POST /_security/role/my_admin_role/_clear_cache
4242
--------------------------------------------------
43-
// CONSOLE

x-pack/docs/en/rest-api/security/create-api-keys.asciidoc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ expire.
6565

6666
The following example creates an API key:
6767

68-
[source, js]
68+
[source,console]
6969
------------------------------------------------------------
7070
POST /_security/api_key
7171
{
@@ -93,7 +93,6 @@ POST /_security/api_key
9393
}
9494
}
9595
------------------------------------------------------------
96-
// CONSOLE
9796
<1> optional expiration for the API key being generated. If expiration is not
9897
provided then the API keys do not expire.
9998
<2> optional role descriptors for this API key, if not provided then permissions
@@ -102,7 +101,7 @@ POST /_security/api_key
102101
A successful call returns a JSON structure that provides
103102
API key information.
104103

105-
[source,js]
104+
[source,console-result]
106105
--------------------------------------------------
107106
{
108107
"id":"VuaCfGcBCdbkQm-e5aOx", <1>

x-pack/docs/en/rest-api/security/create-role-mappings.asciidoc

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ The Examples section below demonstrates the use of templated role names.
105105

106106
The following example assigns the "user" role to all users:
107107

108-
[source, js]
108+
[source,console]
109109
------------------------------------------------------------
110110
POST /_security/role_mapping/mapping1
111111
{
@@ -119,28 +119,26 @@ POST /_security/role_mapping/mapping1
119119
}
120120
}
121121
------------------------------------------------------------
122-
// CONSOLE
123122
<1> Mappings that have `enabled` set to `false` are ignored when role mapping
124123
is performed.
125124
<2> Metadata is optional.
126125

127126
A successful call returns a JSON structure that shows whether the mapping has
128127
been created or updated.
129128

130-
[source,js]
129+
[source,console-result]
131130
--------------------------------------------------
132131
{
133132
"role_mapping" : {
134133
"created" : true <1>
135134
}
136135
}
137136
--------------------------------------------------
138-
// TESTRESPONSE
139137
<1> When an existing mapping is updated, `created` is set to false.
140138

141139
The following example assigns the "user" and "admin" roles to specific users:
142140

143-
[source,js]
141+
[source,console]
144142
--------------------------------------------------
145143
POST /_security/role_mapping/mapping2
146144
{
@@ -151,10 +149,9 @@ POST /_security/role_mapping/mapping2
151149
}
152150
}
153151
--------------------------------------------------
154-
// CONSOLE
155152

156153
The following example matches users who authenticated against a specific realm:
157-
[source, js]
154+
[source,console]
158155
------------------------------------------------------------
159156
POST /_security/role_mapping/mapping3
160157
{
@@ -165,12 +162,11 @@ POST /_security/role_mapping/mapping3
165162
}
166163
}
167164
------------------------------------------------------------
168-
// CONSOLE
169165

170166
The following example matches any user where either the username is `esadmin`
171167
or the user is in the `cn=admin,dc=example,dc=com` group:
172168

173-
[source, js]
169+
[source,console]
174170
------------------------------------------------------------
175171
POST /_security/role_mapping/mapping4
176172
{
@@ -192,7 +188,6 @@ POST /_security/role_mapping/mapping4
192188
}
193189
}
194190
------------------------------------------------------------
195-
// CONSOLE
196191

197192
The example above is useful when the group names in your identity management
198193
system (such as Active Directory, or a SAML Identity Provider) do not have a
@@ -213,7 +208,7 @@ roles is inefficient and can have a negative effect on system performance.
213208
If you only need to map a subset of the groups, then you should do this
214209
using explicit mappings.
215210

216-
[source, js]
211+
[source,console]
217212
------------------------------------------------------------
218213
POST /_security/role_mapping/mapping5
219214
{
@@ -229,15 +224,14 @@ POST /_security/role_mapping/mapping5
229224
"enabled": true
230225
}
231226
------------------------------------------------------------
232-
// CONSOLE
233227
<1> The `tojson` mustache function is used to convert the list of
234228
group names into a valid JSON array.
235229
<2> Because the template produces a JSON array, the format must be
236230
set to `json`.
237231

238232
The following example matches users within a specific LDAP sub-tree:
239233

240-
[source, js]
234+
[source,console]
241235
------------------------------------------------------------
242236
POST /_security/role_mapping/mapping6
243237
{
@@ -248,12 +242,11 @@ POST /_security/role_mapping/mapping6
248242
}
249243
}
250244
------------------------------------------------------------
251-
// CONSOLE
252245

253246
The following example matches users within a particular LDAP sub-tree in a
254247
specific realm:
255248

256-
[source, js]
249+
[source,console]
257250
------------------------------------------------------------
258251
POST /_security/role_mapping/mapping7
259252
{
@@ -267,7 +260,6 @@ POST /_security/role_mapping/mapping7
267260
}
268261
}
269262
------------------------------------------------------------
270-
// CONSOLE
271263

272264
The rules can be more complex and include wildcard matching. For example, the
273265
following mapping matches any user where *all* of these conditions are met:
@@ -278,7 +270,7 @@ following mapping matches any user where *all* of these conditions are met:
278270
- the user does not have a `terminated_date`
279271

280272

281-
[source, js]
273+
[source,console]
282274
------------------------------------------------------------
283275
POST /_security/role_mapping/mapping8
284276
{
@@ -316,7 +308,6 @@ POST /_security/role_mapping/mapping8
316308
}
317309
}
318310
------------------------------------------------------------
319-
// CONSOLE
320311

321312
A templated role can be used to automatically map every user to their own
322313
custom role. The role itself can be defined through the
@@ -329,7 +320,7 @@ role that is their username prefixed with `_user_`.
329320
As an example, the user `nwong` would be assigned the `saml_user` and
330321
`_user_nwong` roles.
331322

332-
[source, js]
323+
[source,console]
333324
------------------------------------------------------------
334325
POST /_security/role_mapping/mapping9
335326
{
@@ -341,7 +332,6 @@ POST /_security/role_mapping/mapping9
341332
"enabled": true
342333
}
343334
------------------------------------------------------------
344-
// CONSOLE
345335
<1> Because it is not possible to specify both `roles` and `role_templates` in
346336
the same role mapping, we can apply a "fixed name" role by using a template
347337
that has no substitutions.

x-pack/docs/en/rest-api/security/create-roles.asciidoc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ For more information, see {stack-ov}/defining-roles.html[Defining roles].
8282

8383
The following example adds a role called `my_admin_role`:
8484

85-
[source,js]
85+
[source,console]
8686
--------------------------------------------------
8787
POST /_security/role/my_admin_role
8888
{
@@ -110,18 +110,16 @@ POST /_security/role/my_admin_role
110110
}
111111
}
112112
--------------------------------------------------
113-
// CONSOLE
114113

115114
A successful call returns a JSON structure that shows whether the role has been
116115
created or updated.
117116

118-
[source,js]
117+
[source,console-result]
119118
--------------------------------------------------
120119
{
121120
"role": {
122121
"created": true <1>
123122
}
124123
}
125124
--------------------------------------------------
126-
// TESTRESPONSE
127125
<1> When an existing role is updated, `created` is set to false.

x-pack/docs/en/rest-api/security/create-users.asciidoc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ access permissions. To create a user without any roles, specify an empty list:
104104

105105
The following example creates a user `jacknich`:
106106

107-
[source,js]
107+
[source,console]
108108
--------------------------------------------------
109109
POST /_security/user/jacknich
110110
{
@@ -117,18 +117,16 @@ POST /_security/user/jacknich
117117
}
118118
}
119119
--------------------------------------------------
120-
// CONSOLE
121120

122121
A successful call returns a JSON structure that shows whether the user has been
123122
created or updated.
124123

125-
[source,js]
124+
[source,console-result]
126125
--------------------------------------------------
127126
{
128127
"created": true <1>
129128
}
130129
--------------------------------------------------
131-
// TESTRESPONSE
132130
<1> When an existing user is updated, `created` is set to false.
133131

134132
After you add a user, requests from that user can be authenticated. For example:

x-pack/docs/en/rest-api/security/delegate-pki-authentication.asciidoc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,18 @@ client's certificate.
7373

7474
The following is an example request:
7575

76-
[source, js]
76+
[source,console]
7777
------------------------------------------------------------
7878
POST /_security/delegate_pki
7979
{
8080
"x509_certificate_chain": ["MIIDbTCCAlWgAwIBAgIJAIxTS7Qdho9jMA0GCSqGSIb3DQEBCwUAMFMxKzApBgNVBAMTIkVsYXN0aWNzZWFyY2ggVGVzdCBJbnRlcm1lZGlhdGUgQ0ExFjAUBgNVBAsTDUVsYXN0aWNzZWFyY2gxDDAKBgNVBAoTA29yZzAeFw0xOTA3MTkxMzMzNDFaFw0yMzA3MTgxMzMzNDFaMEoxIjAgBgNVBAMTGUVsYXN0aWNzZWFyY2ggVGVzdCBDbGllbnQxFjAUBgNVBAsTDUVsYXN0aWNzZWFyY2gxDDAKBgNVBAoTA29yZzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANHgMX2aX8t0nj4sGLNuKISmmXIYCj9RwRqS7L03l9Nng7kOKnhHu/nXDt7zMRJyHj+q6FAt5khlavYSVCQyrDybRuA5z31gOdqXerrjs2OXS5HSHNvoDAnHFsaYX/5geMewVTtc/vqpd7Ph/QtaKfmG2FK0JNQo0k24tcgCIcyMtBh6BA70yGBM0OT8GdOgd/d/mA7mRhaxIUMNYQzRYRsp4hMnnWoOTkR5Q8KSO3MKw9dPSpPe8EnwtJE10S3s5aXmgytru/xQqrFycPBNj4KbKVmqMP0G60CzXik5pr2LNvOFz3Qb6sYJtqeZF+JKgGWdaTC89m63+TEnUHqk0lcCAwEAAaNNMEswCQYDVR0TBAIwADAdBgNVHQ4EFgQU/+aAD6Q4mFq1vpHorC25/OY5zjcwHwYDVR0jBBgwFoAU8siFCiMiYZZm/95qFC75AG/LRE0wDQYJKoZIhvcNAQELBQADggEBAIRpCgDLpvXcgDHUk10uhxev21mlIbU+VP46ANnCuj0UELhTrdTuWvO1PAI4z+WbDUxryQfOOXO9R6D0dE5yR56L/J7d+KayW34zU7yRDZM7+rXpocdQ1Ex8mjP9HJ/Bf56YZTBQJpXeDrKow4FvtkI3bcIMkqmbG16LHQXeG3RS4ds4S4wCnE2nA6vIn9y+4R999q6y1VSBORrYULcDWxS54plHLEdiMr1vVallg82AGobS9GMcTL2U4Nx5IYZG7sbTk3LrDxVpVg/S2wLofEdOEwqCeHug/iOihNLJBabEW6z4TDLJAVW5KCY1DfhkYlBfHn7vxKkfKoCUK/yLWWI="] <1>
8181
}
8282
------------------------------------------------------------
83-
// CONSOLE
8483
<1> A one element certificate chain.
8584

8685
Which returns the following response:
8786

88-
[source,js]
87+
[source,console-result]
8988
--------------------------------------------------
9089
{
9190
"access_token" : "dGhpcyBpcyBub3QgYSByZWFsIHRva2VuIGJ1dCBpdCBpcyBvbmx5IHRlc3QgZGF0YS4gZG8gbm90IHRyeSB0byByZWFkIHRva2VuIQ==",

x-pack/docs/en/rest-api/security/delete-app-privileges.asciidoc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,16 @@ To use this API, you must have either:
3838
The following example deletes the `read` application privilege from the
3939
`myapp` application:
4040

41-
[source,js]
41+
[source,console]
4242
--------------------------------------------------
4343
DELETE /_security/privilege/myapp/read
4444
--------------------------------------------------
45-
// CONSOLE
4645
// TEST[setup:app0102_privileges]
4746

4847
If the role is successfully deleted, the request returns `{"found": true}`.
4948
Otherwise, `found` is set to false.
5049

51-
[source,js]
50+
[source,console-result]
5251
--------------------------------------------------
5352
{
5453
"myapp": {
@@ -58,5 +57,3 @@ Otherwise, `found` is set to false.
5857
}
5958
}
6059
--------------------------------------------------
61-
// TESTRESPONSE
62-

0 commit comments

Comments
 (0)