Java Community | Help. Code. Learn.JC|HCL
Java Community | Help. Code. Learn.โ€ข16mo agoโ€ข
9 replies
Romans

Spring(Boot) Security preauthorize auth return 200 on "false" instead of 403

Hello! Hope this is the right section .I've a "problem" with spring boot and spring security.
In controllers i've the classic @PreAuthorize("hasAnyAuthority(....)").
I would like to receive the error 403 (in order to redirect to the 403.ftlh in case of no authentication).
Just now instead if i open the page that does not pass the @PreAuthorize, returns the page with status 200, but blank, for because any api in the controlled is executed (correctly).
I tried to put in the security config an http.executionHandling() but it won't execute anyway.
The basic requests i've is:
http.authorizeHttpRequest(authorize -> authorize.anymatchers("/img/","js/",etc).permitAll()
.anyMatchers("/","/logout","/error/**").permitAll()
.anyRequest.authenticated())

But still get 200 (and blank page) opening that page
Was this page helpful?