How do I return a 403 Forbidden in Spring MVC?

Will Harris picture Will Harris · Sep 5, 2008 · Viewed 55.9k times · Source

I want my controller to return the right HTTP response code when the user lacks permission to view a particular page.

Answer

Chris Ritchie picture Chris Ritchie · Jul 19, 2016

You can also just throw

org.springframework.security.access.AccessDeniedException("403 returned");

This returns a 403 in the response header.