CRecordUserDbRevokeRightFromRole

Revoke a right from a role in the user database.

This message belongs to the session manager API.

{
  "id": "07da6820-ac45-4071-9296-950b17e5dfbd",
  "name": "USER_DB_REVOKE_RIGHT_FROM_ROLE",
  "description": "Remove a right from a role.",
  "slots": [
    {
      "key": "SessionToken",
      "name": "SESSION_TOKEN",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "UUID",
      "description": "The session token."
    },
    {
      "key": "role",
      "name": "ROLE_ID",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "STRING",
      "description": "The id of the role."
    },
    {
      "key": "right",
      "name": "RIGHT_ID",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "STRING",
      "description": "The id of the right."
    }
  ]
}

Example of use of the class CRecordUserDbRevokeRightFromRole (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_RevokeRight. In addition, the role id and the right id are required.

private void revokeRightFromRole(@NotNull final UUID aToken,
                                 @NotNull final String aRoleId,
                                 @NotNull final String aRight) throws CException
{
    final CEnvelope env = CEnvelope.forMicroService(SESSION_MICROSERVICE_ID);

    final CRecord record = CRecordUserDbRevokeRightFromRole.create();
    CRecordUserDbRevokeRightFromRole.setSessionToken(record,
                                                     aToken);
    CRecordUserDbRevokeRightFromRole.setRoleId(record,
                                               aRoleId);
    CRecordUserDbRevokeRightFromRole.setRightId(record,
                                                aRight);
    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(CRecordUserDbRevokeRightFromRole.ID,
                  this::asyncRevokeRightFromRole);
private boolean asyncRevokeRightFromRole(@NotNull final CEnvelope aEnvelope,
                                         @NotNull final CRecord aRecord)
{
    if (aEnvelope.isAnswer())
    {
        final int resultCode = aEnvelope.getResultCode();
        if (resultCode == CResultCode.SUCCESS)
        {
            // ...
        }
        return true;
    }
    return false;
}

nyssr.net - Innovative Distributed System