CRecordUserDbGetRolesForUser
This message retrieves all roles that are assigned to a specific user.
This message belongs to the Session Manager API.
The Session Manager is part of the NY_Session2PlugIn plugin.
{ "id": "5ba1cd8b-26d5-40de-9edb-75b60b70c865", "name": "USER_DB_GET_ROLES_FOR_USER ", "description": "Get a list of roles belonging to a user.", "slots": [ { "key": "1", "name": "USER_ID", "direction": "REQUEST", "mandatory": "true", "type": "STRING", "description": "The user id." }, { "key": "10", "name": "ROLES", "direction": "ANSWER", "mandatory": "false", "type": "STRING_ARRAY", "description": "The roles a user belongs to." } ] }
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 roles assigned to a 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.
private void getRolesForUser(final byte[] aToken, @NotNull final String aUserId) throws CException { final CEnvelope env = CEnvelope.forMicroService(SESSION_MICROSERVICE_ID ); env.setSessionToken(aToken); final CRecord record =CRecordUserDbGetRolesForUser .create(); CRecordUserDbGetRolesForUser.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(CRecordUserDbGetRolesForUser .ID, this::asyncGetRolesForUser );
private booleanasyncGetRolesForUser (@NotNull final CEnvelope aEnvelope, @NotNull final CRecord aRecord) { if (aEnvelope.isAnswer()) { final int resultCode = aEnvelope.getResultCode(); if (resultCode == CResultCode.SUCCESS) { final String userId =CRecordUserDbGetRolesForUser .getUserId(aRecord, null) final String[] roles =CRecordUserDbGetRolesForUser .getRoles(aRecord, null); // ... } return true; } return false; }