NOTE: You are looking at documentation for an older release. For the latest information, see the current release documentation.
Put Role Mapping API
editPut Role Mapping API
editExecution
editCreating 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"), rules, null, RefreshPolicy.NONE); final PutRoleMappingResponse response = client.security().putRoleMapping(request, RequestOptions.DEFAULT);
Response
editThe 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 Execution
editThis 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: