Control user substitution programatically

Hi, I could not find how can I perform user substitution through code and in my own service.

I would like to do following:

  1. List substitutions possible for current logged in user (same as dropdown in cuba UI)
  2. Choose 1 from above drop down as substitute user but using code
  3. Once work done, reset user substitution by code.

Let me know if more clarification needed. Right now I am able to do first point above by fetching rows from table UserSubstitution for logged in user.

Thanks for support.

Hi,
Please, take a look at the platform WebUserIndicator class code, you can find the examples there.

Thanks for your help. I see that following:

final App app = App.getInstance();
app.getConnection().substituteUser(user);

is what that substitutes the user. But I do not have access to cuba-web module from my services and I don’t think that adding that is recommended.

Let me know I am missing anything.

Thanks

You can use DataManager interface to load a list of the substitution users from the database. After that, you can select the particular user from the list and use Authentication bean to get any user sessions, see the documentation for more information.

Thanks Natalia,

I am able to list possible user substitutions by querying respective table. However the documentation you are referring is on authentication.begin() and authentication.end() which I believe is not same as use substitution.

authentication.begin() anyways won’t work if some user session is already tied to thread. So I have to save the current user session, set another user’s then end it and put the original back. But what I want is substitution as I want to put some delegation business logic based on userSession.getUser() and userSession.getSubstitutedUser() response.

Anyways if doing substitution turns out too tricky then I would go ahead with above approach.

Thanks

Hi Shashank,

I’ve created an issue which we’ll consider for a future version.

1 Like