CRecordUserDbGrantRightToRole
This message grants a user right to a role in the user database.
This message belongs to the Session Manager API.
The Session Manager is part of the NY_Session2PlugIn plugin.
{
"id": "ce7e7567-8bd0-423a-8385-95d4c863cf3b",
"name": "USER_DB_GRANT_RIGHT_TO_ROLE",
"description": "Grant a right to a role.",
"slots": [
{
"key": "1",
"name": "ROLE_ID",
"direction": "REQUEST",
"presenceConstraint": "MANDATORY",
"type": "STRING",
"description": "The id of the role."
},
{
"key": "2",
"name": "RIGHT_ID",
"direction": "REQUEST",
"presenceConstraint": "MANDATORY",
"type": "STRING",
"description": "The id of the right."
},
{
"key": "3",
"name": "RIGHT_IDS",
"direction": "REQUEST",
"presenceConstraint": "MANDATORY",
"type": "STRING_ARRAY",
"description": "Right IDs to grant."
}
]
}
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_GrantRight. In addition, the role id and the right id
are required. If you want to grant several rights to the role, you can use the
setRightIds() method.
private void grantRightToRole(final byte[] aToken,
@NotNull final String aRoleId,
@NotNull final String aRight) throws CException
{
final CEnvelope env = CEnvelope.forMicroService(SESSION_MICROSERVICE_ID);
env.setSessionToken(aToken);
final CRecord record = CRecordUserDbGrantRightToRole.create();
CRecordUserDbGrantRightToRole.setRoleId(record,
aRoleId);
CRecordUserDbGrantRightToRole.setRightId(record,
aRight);
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(CRecordUserDbGrantRightToRole.ID,
this::asyncGrantRightToRole);
private boolean asyncGrantRightToRole(@NotNull final CEnvelope aEnvelope,
@NotNull final CRecord aRecord)
{
if (aEnvelope.isAnswer())
{
final int resultCode = aEnvelope.getResultCode();
if (resultCode == CResultCode.SUCCESS)
{
// ...
}
return true;
}
return false;
}