CRecordSessionLogin

This record is used for the login of a user.

This message belongs to the session manager API.

{
  "id": "a8c83b58-a567-4eb9-b3b4-ce568899a696",
  "name": "SESSION_LOGIN",
  "description": "LogIn.",
  "slots": [
    {
      "key": "userId",
      "name": "USER_ID",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "STRING",
      "description": "The user id."
    },
    {
      "key": "pw",
      "name": "PASSWORD",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "STRING",
      "description": "The base64 encoded hash (SHA384) of the password."
    },
    {
      "key": "token",
      "name": "TOKEN",
      "direction": "ANSWER",
      "mandatory": "false",
      "type": "UUID",
      "description": "A token (only on SUCCESS)."
    }
  ]
}

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

In the example we take the password directly from a Swing password widget. For the request you need the Base64-encoded SHA384 hash of the password in addition to the userId. You can use a utility method of the kernel: CUtilPassword.hashPassword().

// request
private void login(@NotNull final String aUserId,
                   @NotNull final JPasswordField aPasswordField) throws CException
{
    final String passwordHash = CUtilPassword.hashPassword(aPasswordField.getPassword());

    final CEnvelope env = CEnvelope.forMicroService(SESSION_MICROSERVICE_ID);

    final CRecord record = CRecordSessionLogin.create();
    CRecordSessionLogin.setUserId(record,
                                  aUserId);
    CRecordSessionLogin.setPassword(record,
                                    passwordHash);

    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(CRecordSessionLogin.ID,
                  this::asyncSessionLogin);

// fetch reply
private boolean asyncSessionLogin(@NotNull final CEnvelope aEnvelope,
                                  @NotNull final CRecord aRecord)
{
    if (aEnvelope.isAnswer())
    {
        final int resultCode = aEnvelope.getResultCode();
        if (resultCode == CResultCode.SUCCESS)
        {
            final UUID token = CRecordSessionLogin.getToken(aRecord,
                                                            null);
            // ...
        }
        else
        {
            // ...
        }
        return true;
    }
    return false;
}

nyssr.net - Innovative Distributed System