CRecordUserDbGetRightListForRole
Get all permissions belonging to a role.
This message belongs to the session manager API.
{ "id": "1efc20de-1f4a-4c4a-b66d-6a28ce245d78", "name": "USER_DB_GET_RIGHT_LIST_FOR_ROLE", "description": "Get the right list for a role.", "slots": [ { "key": "SessionToken", "name": "SESSION_TOKEN", "direction": "REQUEST", "mandatory": "true", "type": "UUID", "description": "The session token." }, { "key": "role", "name": "ROLE_ID", "direction": "REQUEST", "mandatory": "true", "type": "STRING", "description": "The role id." }, { "key": "rights", "name": "RIGHTS", "direction": "ANSWER", "mandatory": "false", "type": "STRING_ARRAY", "description": "The list of rights for one role." } ] }
Example of use of the class CRecordUserDbGetRightListForRole (after generating)
You need the microservice ID of the session manager:
public static final IId SESSION_MICROSERVICE_ID = CIdFactory.fromObject("ccf168c1-f18b-4229-85f9-24461a19ee6a");
The own SessionToken is needed to verify the authorization for the change.
You need the permission NY_GetRightList
.
In addition, the role ID is required.
private void getRightListForRole(@NotNull final UUID aToken, @NotNull final String aRoleId) throws CException { final CEnvelope env = CEnvelope.forMicroService(SESSION_MICROSERVICE_ID); final CRecord record = CRecordUserDbGetRightListForRole.create(); CRecordUserDbGetRightListForRole.setSessionToken(record, aToken); CRecordUserDbGetRightListForRole.setRoleId(record, aRoleId); sendRequest(env, record); }
To catch the response of the request, we need a message handler. We add it in the constructor of the message handler registry.
// constructor: addMessageHandler(CRecordUserDbGetRightListForRole.ID, this::asyncGetRightListForRole);
private boolean asyncGetRightListForRole(@NotNull final CEnvelope aEnvelope, @NotNull final CRecord aRecord) { if (aEnvelope.isAnswer()) { final int resultCode = aEnvelope.getResultCode(); if (resultCode == CResultCode.SUCCESS) { final String roleId = CRecordUserDbGetRightListForRole.getRoleId(aRecord, null); final String[] rights = CRecordUserDbGetRightListForRole.getRights(aRecord, null); // ... } return true; } return false; }