CRecordUserDbGetRoleList
This message is used to get all available roles from the user database.
This message belongs to the session manager API. The Session Manager is part of the NY_Session2PlugIn plugin.
{
"id": "a1a7b721-3ea8-4ce3-b4ce-3dc54c49c8d1",
"name": "USER_DB_GET_ROLE_LIST",
"description": "Get a list of all available roles.",
"slots": [
{
"key": "10",
"name": "ROLES",
"direction": "RESPONSE",
"presenceConstraint": "OPTIONAL",
"type": "STRING_ARRAY",
"description": "A list of all roles."
}
]
}
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_GetListOfRoles.
private void getRoleList(final byte[] aToken) throws CException
{
final CEnvelope env = CEnvelope.forMicroService(SESSION_MICROSERVICE_ID);
env.setSessionToken(aToken);
final CRecord record = CRecordUserDbGetRoleList.create();
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(CRecordUserDbGetRoleList.ID,
this::asyncGetRoleList);
private boolean asyncGetRoleList(@NotNull final CEnvelope aEnvelope,
@NotNull final CRecord aRecord)
{
if (aEnvelope.isAnswer())
{
final int resultCode = aEnvelope.getResultCode();
if (resultCode == CResultCode.SUCCESS)
{
final String[] roles = CRecordUserDbGetRoleList.getRoles(aRecord,
null);
// ...
}
return true;
}
return false;
}