Refresh UserSession

Hello guys,

I have the following scenario: My user has to be in many accessGroups but only one active at a specific moment. So I created a User_Group relation. The active one is the one saved on user. When the user changes the active Group I update the group field on user entity.
After doing this, how can I force refresh the session? For now, I just called the loginService.logout() and the user is forced to login again. Is there a way to avoid this?

Thank you!

how did you call a logout? from where? i’m trying to disconnect my user from an app, and don’t know how to do it(((

Hi,

If you want to logout user from web application you can use App object, as it is done by LogoutButton component:

App.getInstance().logout();

In this case, application will show confirmation dialog if there are unsaved changes in opened windows. If you want to force logout use Connection directly:

Connection connection = App.getInstance().getConnection();
connection.logout();
2 Likes

Unfortunately, you have to logout user from web client to replace the access group. You can implement automatic logout/login again logic in web application using Connection object, something like this:

Connection connection = App.getInstance().getConnection();

UserSession session = connection.getSession();

String login = session.getUser().getLogin();
Locale locale = session.getLocale();

connection.logout();
((ExternallyAuthenticatedConnection) connection).loginAfterExternalAuthentication(login, locale);
1 Like

A post was split to a new topic: RuntimeException: A connector with id xxx is already registered

Hi Rares,

Another approach that you might consider is the possibility to use user substitution to solbe this kind of problem. I used to use that in oder to achieve something similar…
You create multiple user accounts in different access groups with potentially different roles for a single user. Then you link those user accounts through user substitutions.
This way the user can actively switch between the different scenarios / hats that he wants to wear…

It actually worked great and did include only minimal programming…

Bye
Mario