CRecordUserDbGetUserRecord

This request fetches a user's data from the microservice session manager.

This message belongs to the session manager API.

{
  "id": "f4459095-3a4a-48e5-8790-9fa3a416b8e4",
  "name": "USER_DB_GET_USER_RECORD",
  "description": "Get a user for displaying.",
  "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": "userRecord",
      "name": "USER",
      "direction": "ANSWER",
      "mandatory": "false",
      "type": "RECORD",
      "description": "The user record (see USER_DB_USER_RECORD)."
    },
    {
      "key": "roles",
      "name": "ROLES",
      "direction": "ANSWER",
      "mandatory": "false",
      "type": "STRING_ARRAY",
      "description": "The roles a user belongs to (incl. role of roles)."
    },
    {
      "key": "rights",
      "name": "RIGHTS",
      "direction": "ANSWER",
      "mandatory": "false",
      "type": "STRING_ARRAY",
      "description": "The rights of the user."
    }
  ]
}

Example of use of the class CRecordUserDbGetUserRecord (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");

To fetch the data of a single user, we need the user ID. Additionally, we need the session token of the current user to check the right to this request. The executing user needs the NY_GetUserData permission. User rights are stored in the user database by the administrator.

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

    final CRecord record = CRecordUserDbGetUserRecord.create();
    CRecordUserDbGetUserRecord.setSessionToken(record,
                                               aToken);
    CRecordUserDbGetUserRecord.setUserId(record,
                                         aUserId);

    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(CRecordUserDbGetUserRecord.ID,
                  this::asyncGetUserRecord);
private boolean asyncGetUserRecord(@NotNull final CEnvelope aEnvelope,
                                   @NotNull final CRecord aRecord)
{
    if (aEnvelope.isAnswer())
    {
        final int resultCode = aEnvelope.getResultCode();
        if (resultCode == CResultCode.SUCCESS)
        {
            final String userId1 = CRecordUserDbGetUserRecord.getUserId(aRecord,
                                                                        null);
            final String[] roles = CRecordUserDbGetUserRecord.getRoles(aRecord,
                                                                       null);
            final String[] rights = CRecordUserDbGetUserRecord.getRights(aRecord,
                                                                         null);
            final CRecord userRecord = CRecordUserDbGetUserRecord.getUser(aRecord,
                                                                          null);
            if (userRecord != null)
            {
                final String userId2 = CRecordUserDbUserRecord.getUserId(userRecord,
                                                                         null);
                // in reality the password SHA-384 Hash, base64 encoded
                final String password = CRecordUserDbUserRecord.getPassword(userRecord,
                                                                            null);
                final String realName = CRecordUserDbUserRecord.getRealName(userRecord,
                                                                            null);
                final String email = CRecordUserDbUserRecord.getEmail(userRecord,
                                                                      null);
                final String createdBy = CRecordUserDbUserRecord.getCreatedBy(userRecord,
                                                                              null);
                final LocalDateTime timeCreated = CRecordUserDbUserRecord.getTimeCreated(userRecord,
                                                                                         null);
                // ...
            }
            // ...
        }
        return true;
    }
    return false;
}

nyssr.net - Innovative Distributed System