Hi, Roland!
I’ve looked at the attached project and can highlight a few points that will give you some context.
It’s worth clarifying from the outset that Vaadin client-server interaction has some limitations.
So navigation in this case will not suit you.
Let’s clarify from the beginning - the side menu is a nested component on the MainView
.
Now, take a look at this: @Route(value = "BlankViewTest", layout = MainView.class)
Since you tried to navigate from the BlankView
, whose layout is MainView
, your side menu was not redrawn after authentication.
So you still see the side menu from the anonymous user role (can be seen in the user indicator at the bottom of the side menu).
When you try to navigate to UserList
, you just open it in the MainView
layout. Thus the side menu is still not redrawn.
In order to redraw the side menu and completely update the access rights for the current authenticated user, you need to make hard navigation.
In other words, you must completely recreate MainView.
You can use the com.vaadin.flow.component.page.Page
class API.
Something like that:
com.vaadin.flow.component.page.Page#setLocation(java.lang.String)
You can also use UI.getCurrent().getPage()
to access the current page.
Be careful, navigation is performed asynchronously with sending a request to the client sice (js call), so info about the client side on the server may not be relevant until the fetching.
So you need to use something like that:
@Subscribe
public void onAttachEvent(final AttachEvent event) {
try {
loginViewSupport.authenticate(
AuthDetails.of("admin", "admin")
);
} catch (final BadCredentialsException | DisabledException | LockedException | AccessDeniedException e) {
System.out.println("login failed ");
}
UI.getCurrent().getPage().setLocation("users");
}
When opening the view this way, the current page opens in a clean way and recreates all components.
Regards,
Dmitriy