CRecordUserDbGetRoleList

Fetch all available roles from the user database.

This message belongs to the session manager API.

{
  "id": "a1a7b721-3ea8-4ce3-b4ce-3dc54c49c8d1",
  "name": "USER_DB_GET_ROLE_LIST",
  "description": "Get a list of all available roles.",
  "slots": [
    {
      "key": "SessionToken",
      "name": "SESSION_TOKEN",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "UUID",
      "description": "The session token."
    },
    {
      "key": "roles",
      "name": "ROLES",
      "direction": "ANSWER",
      "mandatory": "false",
      "type": "STRING_ARRAY",
      "description": "A list of all roles."
    }
  ]
}

Example of use of the class CRecordUserDbGetRoleList (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_GetListOfRoles.

  private void getRoleList(@NotNull final UUID aToken) throws CException
  {
      final CEnvelope env = CEnvelope.forMicroService(SESSION_MICROSERVICE_ID);

      final CRecord record = CRecordUserDbGetRoleList.create();
      CRecordUserDbGetRoleList.setSessionToken(record,
                                               aToken);
      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(CRecordUserDbGetRoleList.ID,
                  this::asyncGetRoleList);
private boolean asyncGetRoleList(@NotNull final CEnvelope aEnvelope,
                                 @NotNull final CRecord aRecord)
{
    if (aEnvelope.isAnswer())
    {
        final int resultCode = aEnvelope.getResultCode();
        if (resultCode == CResultCode.SUCCESS)
        {
            final String[] roles = CRecordUserDbGetRoleList.getRoles(aRecord,
                                                                     null);
            // ...
        }
        return true;
    }
    return false;
}

nyssr.net - Innovative Distributed System