CRecordUserDbGetRightListForRole
Get all rights belonging to a role.
This message belongs to the session manager API. The Session Manager is part of the NY_Session2PlugIn plugin.
{
"id": "1efc20de-1f4a-4c4a-b66d-6a28ce245d78",
"name": "USER_DB_GET_RIGHT_LIST_FOR_ROLE",
"description": "Get the right list for a role.",
"slots": [
{
"key": "1",
"name": "ROLE_ID",
"direction": "REQUEST",
"presenceConstraint": "MANDATORY",
"type": "STRING",
"description": "The role id."
},
{
"key": "10",
"name": "RIGHTS",
"direction": "RESPONSE",
"presenceConstraint": "OPTIONAL",
"type": "RECORD_ARRAY",
"description": "The list of rights for one role."
}
]
}
Usage
Sending the request
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(final byte[] aToken,
@NotNull final String aRoleId) throws CException
{
final CEnvelope env = CEnvelope.forMicroService(SESSION_MICROSERVICE_ID);
env.setSessionToken(aToken);
final CRecord record = CRecordUserDbGetRightListForRole.create();
CRecordUserDbGetRightListForRole.setRoleId(record,
aRoleId);
sendRequest(env,
record);
}
Dealing with the response
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;
}