CRecordUserDbCreateRight
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.
{ "id": "4b2bf3f8-7406-4829-9c1c-6f4c14188356", "name": "USER_DB_CREATE_RIGHT", "description": "Create a new right.", "slots": [ { "key": "SessionToken", "name": "SESSION_TOKEN", "direction": "REQUEST", "mandatory": "true", "type": "UUID", "description": "The session token." }, { "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." } ] }
Example of use of the class CRecordUserDbCreateRight (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_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(@NotNull final UUID aToken, @NotNull final String aRightId, @NotNull final String aDescription, @NotNull final boolean aIsProtected) throws CException { final CEnvelope env = CEnvelope.forMicroService(SESSION_MICROSERVICE_ID); final CRecord record = CRecordUserDbCreateRight.create(); CRecordUserDbCreateRight.setSessionToken(record, aToken); CRecordUserDbCreateRight.setRight(record, aRightId); CRecordUserDbCreateRight.setDescription(record, aDescription); CRecordUserDbCreateRight.setProtected(record, aIsProtected); 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(CRecordUserDbCreateRight.ID, this::asyncCreateRight);
private boolean asyncCreateRight(@NotNull final CEnvelope aEnvelope, @NotNull final CRecord aRecord) { if (aEnvelope.isAnswer()) { final int resultCode = aEnvelope.getResultCode(); if (resultCode == CResultCode.SUCCESS) { // ... } return true; } return false; }