I’ve setup security on V24.5.4 using the Spring security integration/VaadinWebSecurity
and have most of it working as expected. It jumps to Login page when not authenticated, and respects the Annotations on each of the routed views, according to the Roles, however
I have an issue with the root view.
By default, all views require authentication with the exception of the login screen, which has a
@AnonymousAllowed
So this blocks access to root, however when I am logged in, I am still blocked from the root page, regardless of what Annotation I place on it.
It throws back the standard (dev mode) error page:
Reason: Consider adding one of the following annotations to make the view accessible: @AnonymousAllowed, @PermitAll, @RolesAllowed.
Available routes:
* [<root>](http://localhost:8080/)
I tried placing various Annotation on the main layout class (extending AppLayout) but I suspect this isn’t a regular View class so security annotations are not read here??
As this page builds itself in code (Building the navbar and draw) I can’t see where an annotation can be placed for the page. I’d rather no go into checking the authContext for roles etc as everywhere else in the app its using Annotation, so I’d like to keep it consistent.
Can anyone point me to how the root page is meant to be Annotated for access control please?
My Security config looks like this:
@Configuration
@EnableWebSecurity
class SecurityConfiguration(
@Autowired val userDetailsService: SITUserDetailsManager
) : VaadinWebSecurity() {
@Throws(Exception::class)
override fun configure(http: HttpSecurity) {
// ensure login is public
http.authorizeHttpRequests { auth -> auth.requestMatchers(AntPathRequestMatcher("/login")).permitAll() }
// Set custom details service to map SIT Users in DB into spring UserDetails
http.userDetailsService(userDetailsService)
http.formLogin { auth -> auth.successForwardUrl("/exploitatie") }
super.configure(http)
// This is important to register your login view to the
// navigation access control mechanism:
setLoginView(http, LoginView::class.java)
}
}```