What I now want to achieve is, that some pages were secured and some not. For that I add @PermitAll to those which I want to secure and @AnonymousAllowed to them I dont want to be secured. Calling the routes directly via browser navigation works as intended. Keyloak redirect for @PermitAll pages is done, for @AnonymousAllowed not.
The problem I got is, navigating from one page to the other, using UI.navigate(route). When calling UI.navigate(ToASecuredPageWithPermitAll) from a page with @AnonymousAllowed to a page with @PermitAll I got the following info message:
`Could not navigate to ‘securedview’
Available routes:
securedview`
Clicking on “securedview” doesnt do anything. Just calling the route directly via browser provides the intended behavior. What I´d like to achieve is the same behavior as directly accessing secured page: Redirect to Keycloak login page.
I tried it and the setup is getting much more weird than before: My main route “” is redirected then to sso.vaadin.com although I haven´t configured anything like this. My other routes with @AnonymousAllowed are forcing a login login with my dedicated Keycloak now, althought they shoudlnt because of the annotation.
I’m wondering how you are changing from the anonymous page to the non-public page. I’m not sure if it’s related to keycloak or just how the Vaadin UI and the Spring session is handled.
Can you explain how you can reproduce the error?
Thanks for the explanation. Looks like this makes the difference. navigate doesnt trigger a complete http security flow and with that, keycloak is not triggered, while setLocation does.
Generally my integration is very fragile, or Im doing something completly wrong. Copied the working configuration from the now working project (A) to another (project B). Including spring-boot-starter-security and spring-boot-starter-oauth2-client in pom, same application.properties and the mentioned SecurityConfiguration and KeycloakLogoutHandler (working in project A) as described in the documentation. Added @AnonymousAllowed to the main route and got a complete different behaviour: The main route / is now secured (redirect to keyloak) although I annotated it with @AnonymousAllowed. Enabled the Springboot security logs by adding logging.level.org.springframework.security=DEBUG and see a complete different bahavior of the projects.
Working project A: 2023-08-21T21:21:27.289+02:00 DEBUG 13284 --- [nio-8083-exec-1] o.s.security.web.FilterChainProxy : Securing GET /MyRoute 2023-08-21T21:21:27.304+02:00 DEBUG 13284 --- [nio-8083-exec-1] o.s.s.w.a.AnonymousAuthenticationFilter : Set SecurityContextHolder to anonymous SecurityContext 2023-08-21T21:21:27.310+02:00 DEBUG 13284 --- [nio-8083-exec-1] o.s.security.web.FilterChainProxy : Secured GET /MyRoute 2023-08-21T21:21:27.410+02:00 INFO 13284 --- [nio-8083-exec-1] c.vaadin.flow.spring.SpringInstantiator : The number of beans implementing 'I18NProvider' is 0. Cannot use Spring beans for I18N, falling back to the default behavior 2023-08-21T21:21:27.538+02:00 DEBUG 13284 --- [nio-8083-exec-2] o.s.security.web.FilterChainProxy : Securing GET /VAADIN/build/indexhtml-51bec632.js 2023-08-21T21:21:27.538+02:00 DEBUG 13284 --- [nio-8083-exec-3] o.s.security.web.FilterChainProxy : Securing GET /VAADIN/build/index-ebbc34ab.css 2023-08-21T21:21:27.539+02:00 DEBUG 13284 --- [nio-8083-exec-2] o.s.s.w.a.AnonymousAuthenticationFilter : Set SecurityContextHolder to anonymous SecurityContext 2023-08-21T21:21:27.539+02:00 DEBUG 13284 --- [nio-8083-exec-3] o.s.s.w.a.AnonymousAuthenticationFilter : Set SecurityContextHolder to anonymous SecurityContext
Im wondering why the HttpSessionRequestCache is adding ?continue to my main route although I just called / in my browser. Maybe thats the issue this parameter/route might then be secured. But not sure if this is the issues, but nevertheless wondering why it adds the “?continue”.