WARNING: Deprecated in 7.15.0.
The Java REST Client is deprecated in favor of the Java API Client.
Create or update role mapping APIedit
Executionedit
Creating and updating a role mapping can be performed using the security().putRoleMapping()
method:
final RoleMapperExpression rules = AnyRoleMapperExpression.builder() .addExpression(FieldRoleMapperExpression.ofUsername("*")) .addExpression(FieldRoleMapperExpression.ofGroups("cn=admins,dc=example,dc=com")) .build(); final PutRoleMappingRequest request = new PutRoleMappingRequest("mapping-example", true, Collections.singletonList("superuser"), Collections.emptyList(), rules, null, RefreshPolicy.NONE); final PutRoleMappingResponse response = client.security().putRoleMapping(request, RequestOptions.DEFAULT);
Responseedit
The returned PutRoleMappingResponse
contains a single field, created
. This field
serves as an indication if a role mapping was created or if an existing entry was updated.
Asynchronous Executionedit
This request can be executed asynchronously using the security().putRoleMappingAsync()
method:
The asynchronous method does not block and returns immediately. Once the request
has completed the ActionListener
is called back using the onResponse
method
if the execution successfully completed or using the onFailure
method if
it failed.
A typical listener for a PutRoleMappingResponse
looks like: