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.
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.