CRecordUserDbRemoveRolesFromUser

Revoke rights from a user.

This message belongs to the session manager API.

{
  "id": "bcca4b32-dcad-429f-8c29-822f81c0c1ce",
  "name": "USER_DB_REMOVE_ROLES_FROM_USER",
  "description": "Revoke some roles from a user.",
  "slots": [
    {
      "key": "SessionToken",
      "name": "SESSION_TOKEN",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "UUID",
      "description": "The session token."
    },
    {
      "key": "userId",
      "name": "USER_ID",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "STRING",
      "description": "The user id."
    },
    {
      "key": "roles",
      "name": "ROLES",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "STRING_ARRAY",
      "description": "The roles."
    }
  ]
}

Example of use of the class CRecordUserDbRemoveRolesFromUser (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_RemoveRoleFromUser. In addition, the user ID and the list of roles are required.

private void revokeRolesFromUser(@NotNull final UUID aToken,
                                 @NotNull final String aUserId,
                                 @NotNull final String[] aRoles) throws CException
{
    final CEnvelope env = CEnvelope.forMicroService(SESSION_MICROSERVICE_ID);

    final CRecord record = CRecordUserDbRemoveRolesFromUser.create();
    CRecordUserDbRemoveRolesFromUser.setSessionToken(record,
                                                     aToken);
    CRecordUserDbRemoveRolesFromUser.setUserId(record,
                                               aUserId);
    CRecordUserDbRemoveRolesFromUser.setRoles(record,
                                              aRoles);

    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(CRecordUserDbRemoveRolesFromUser.ID,
                  this::asyncRevokeRolesFromUser);
private boolean asyncRevokeRolesFromUser(@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