CRecordSessionCreateRight
With this request a new permission is stored in the database. This new right can then be assigned to users or roles by the administrator.
This message belongs to the Session Manager API.
The message is part of the kernel.
{ "id": "4b2bf3f8-7406-4829-9c1c-6f4c14188356", "name": "SESSION_CREATE_RIGHT ", "description": "Create a new right.", "slots": [ { "key": "right", "name": "RIGHT", "direction": "REQUEST", "mandatory": "true", "type": "STRING", "description": "The new right to add." }, { "key": "description", "name": "DESCRIPTION", "direction": "REQUEST", "mandatory": "true", "type": "STRING", "description": "The description of the new right." }, { "key": "protected", "name": "PROTECTED", "direction": "REQUEST", "mandatory": "false", "type": "BOOLEAN", "description": "True if the new right is protected." } ] }
Usage
Sending the request
You need the microservice ID of the session manager:
public static final IIdSESSION_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_CreateRight
.
In addition, the name of the permission, a description and a flag are required, which indicates whether the
permission may also be deleted again.
private void createRight(final byte[] aToken, @NotNull final String aRightId, @NotNull final String aDescription, @NotNull final boolean aIsProtected) throws CException { final CEnvelope env = CEnvelope.forMicroService(SESSION_MICROSERVICE_ID ); env.setSessionToken(aToken); final CRecord record =CRecordSessionCreateRight .create();CRecordSessionCreateRight .setRight(record, aRightId);CRecordSessionCreateRight .setDescription(record, aDescription);CRecordSessionCreateRight .setProtected(record, aIsProtected); 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(CRecordSessionCreateRight .ID, this::asyncCreateRight );
private booleanasyncCreateRight (@NotNull final CEnvelope aEnvelope, @NotNull final CRecord aRecord) { if (aEnvelope.isAnswer()) { final int resultCode = aEnvelope.getResultCode(); if (resultCode == CResultCode.SUCCESS) { // ... } return true; } return false; }