CRecordUserDbGetUserRecord
This request fetches a user's data from the microservice session manager.
This message belongs to the Session Manager API.
The Session Manager is part of the NY_Session2PlugIn plugin.
{ "id": "f4459095-3a4a-48e5-8790-9fa3a416b8e4", "name": "USER_DB_GET_USER_RECORD ", "description": "Get a user for displaying.", "slots": [ { "key": "1", "name": "USER_ID", "direction": "REQUEST", "mandatory": "true", "type": "STRING", "description": "The user id." }, { "key": "10", "name": "USER", "direction": "ANSWER", "mandatory": "false", "type": "RECORD", "description": "The user record (see USER_DB_USER_RECORD)." }, { "key": "11", "name": "ROLES", "direction": "ANSWER", "mandatory": "false", "type": "STRING_ARRAY", "description": "The roles a user belongs to (incl. role of roles)." }, { "key": "12", "name": "RIGHTS", "direction": "ANSWER", "mandatory": "false", "type": "RECORD_ARRAY", "description": "The rights of the user (type = USER_DB_RIGHT_RECORD)." } ] }
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");
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(final byte[] aToken, @NotNull final String aUserId) throws CException { final CEnvelope env = CEnvelope.forMicroService(SESSION_MICROSERVICE_ID ); env.setSessionToken(aToken); final CRecord record =CRecordUserDbGetUserRecord .create();CRecordUserDbGetUserRecord .setUserId(record, aUserId); 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(CRecordUserDbGetUserRecord .ID, this::asyncGetUserRecord );
private booleanasyncGetUserRecord (@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; }