CRecordSessionLogin
This record is used for the login of a user.
This message belongs to the Session Manager API.
It is part of the kernel.
{ "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." } ] }
Usage
Sending the request
You need the microservice ID of the session manager:
public static final IIdSESSION_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); }
Dealing with the response
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 booleanasyncSessionLogin (@NotNull final CEnvelope aEnvelope, @NotNull final CRecord aRecord) { if (aEnvelope.isAnswer()) { final int resultCode = aEnvelope.getResultCode(); if (resultCode == CResultCode.SUCCESS) { final byte[] token = aEnvelope.getSessionToken(); // ... } else { // ... } return true; } return false; }