I want my controller to return the right HTTP response code when the user lacks permission to view a particular page.
access. AccessDeniedException("403 returned"); This returns a 403 in the response header. This works perfectly and should be the accepted answer because it's most flexible.
Simply disabling CSRF on your configure method with http. csrf(). disable(); is all that needed to be done for my put requests to stop receiving 403.
The simple answer is; “You need to be given the correct access”. Without being given the correct access you'd technically be hacking the server, as it is specifically set up to restrict said access.
Step 1 – Add Spring Boot Security Configurations The configuration of the spring boot security is changed to handle the unauthorized access denied error. Spring boot security allows you to add a redirected url if a 403 Forbidden / Access Denied error occurs.
You can also just throw
org.springframework.security.access.AccessDeniedException("403 returned");
This returns a 403 in the response header.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With