I’ve been trying to implement a project that uses Keycloak OIDC. I’ve been following the example from:
but the:
@Inject
SecurityIdentity identity;
in MainView.java is always null.
The code can be found at
A small test application to combine vaadin quarkus and keycloak.
in the branch oidc.
The application will direct me to the keycloak login but when I get to the /admin page it says I’m not logged in.
I have struggled with this for the last two days. Please take a look and let me know why this isn’t working.
Thank you
Matthew
marcoc_753
(Marco Collovati)
May 9, 2025, 5:30am
2
Field injection happens after the constructor is called. You need to inject SecurityIdentity
as a constructor argument.
The alternative is to move your logic in a @PostConstruct
annotated method, but I suggest the constructor injection.
Thank you Marco. This worked well. I’ve also upgraded the project to use NavigationAccessControl.
Still trying to get logout working well. When I press the logout link at the bottom it takes 15 seconds to logout and return to the app.
anchor = new Anchor("/logout", "Logout");
anchor.getElement().setAttribute("router-ignore", "");
I hope others find this little app useful.