I want to redirect to my login page when the user navigates to just /
. In my WebMvcConfig I specify a redirect from /
to /app/login
via
override fun addViewControllers(registry: ViewControllerRegistry) {
registry.addViewController("/").setViewName("redirect:/app/login")
registry.addRedirectViewController("/", "redirect:/app/login")
}
however, whenever the user naviagates to /
they get a 401 page since I don't allow that in my security config.
httpSecurity.authorizeRequests()
.antMatchers("/h2-console/**").permitAll()
.antMatchers("$GLOBAL_PATH/settings").permitAll()
.antMatchers("/app/**", "/api/security/**").permitAll()
.anyRequest().authenticated()
If I change the security to allow access by adding /**
like so .antMatchers("/**", "/app/**", "/api/security/**").permitAll()
it will redirect to the login just fine, but I don't want this since this allows access to anything under /
. I've tried adding just /
to the matcher like .antMatchers("/", "/app/**", "/api/security/**").permitAll()
but that still blocks it, I've also tried just adding ""
but that doesn't work either.
Once these didnt work I tried a request mapping
@RequestMapping("/")
fun redirectToLogin(request: HttpServletRequest): String {
return "redirect:/app/login"
}
But no luck there either, still 401.
Is there a way to exclusively allow access to just /
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…