@@ -105,7 +105,7 @@ The Examples section below demonstrates the use of templated role names.
105105
106106The following example assigns the "user" role to all users:
107107
108- [source, js ]
108+ [source,console ]
109109------------------------------------------------------------
110110POST /_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
127126A successful call returns a JSON structure that shows whether the mapping has
128127been 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
141139The following example assigns the "user" and "admin" roles to specific users:
142140
143- [source,js ]
141+ [source,console ]
144142--------------------------------------------------
145143POST /_security/role_mapping/mapping2
146144{
@@ -151,10 +149,9 @@ POST /_security/role_mapping/mapping2
151149 }
152150}
153151--------------------------------------------------
154- // CONSOLE
155152
156153The following example matches users who authenticated against a specific realm:
157- [source, js ]
154+ [source,console ]
158155------------------------------------------------------------
159156POST /_security/role_mapping/mapping3
160157{
@@ -165,12 +162,11 @@ POST /_security/role_mapping/mapping3
165162 }
166163}
167164------------------------------------------------------------
168- // CONSOLE
169165
170166The following example matches any user where either the username is `esadmin`
171167or the user is in the `cn=admin,dc=example,dc=com` group:
172168
173- [source, js ]
169+ [source,console ]
174170------------------------------------------------------------
175171POST /_security/role_mapping/mapping4
176172{
@@ -192,7 +188,6 @@ POST /_security/role_mapping/mapping4
192188 }
193189}
194190------------------------------------------------------------
195- // CONSOLE
196191
197192The example above is useful when the group names in your identity management
198193system (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.
213208If you only need to map a subset of the groups, then you should do this
214209using explicit mappings.
215210
216- [source, js ]
211+ [source,console ]
217212------------------------------------------------------------
218213POST /_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
238232The following example matches users within a specific LDAP sub-tree:
239233
240- [source, js ]
234+ [source,console ]
241235------------------------------------------------------------
242236POST /_security/role_mapping/mapping6
243237{
@@ -248,12 +242,11 @@ POST /_security/role_mapping/mapping6
248242 }
249243}
250244------------------------------------------------------------
251- // CONSOLE
252245
253246The following example matches users within a particular LDAP sub-tree in a
254247specific realm:
255248
256- [source, js ]
249+ [source,console ]
257250------------------------------------------------------------
258251POST /_security/role_mapping/mapping7
259252{
@@ -267,7 +260,6 @@ POST /_security/role_mapping/mapping7
267260 }
268261}
269262------------------------------------------------------------
270- // CONSOLE
271263
272264The rules can be more complex and include wildcard matching. For example, the
273265following 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------------------------------------------------------------
283275POST /_security/role_mapping/mapping8
284276{
@@ -316,7 +308,6 @@ POST /_security/role_mapping/mapping8
316308 }
317309}
318310------------------------------------------------------------
319- // CONSOLE
320311
321312A templated role can be used to automatically map every user to their own
322313custom role. The role itself can be defined through the
@@ -329,7 +320,7 @@ role that is their username prefixed with `_user_`.
329320As an example, the user `nwong` would be assigned the `saml_user` and
330321`_user_nwong` roles.
331322
332- [source, js ]
323+ [source,console ]
333324------------------------------------------------------------
334325POST /_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.
0 commit comments