Reputation: 97
I have a web page which is connected to a spring @component
class.
There is a method that requires roles(by spring annotation @Secured('ROLE_USER')
) and it is called with a button.
My problem is when i click the button without having the required role,it causes an error named access denied exception.I want to redirect the page to error a page when this occurs. I tried access-denied-handler on application context but it did not work.
By the way, is @component
tag enough or should i add something else such as @controller
?
Upvotes: 1
Views: 1558
Reputation: 8574
Just add an error page to your web.xml like this
<error-page>
<error-code>403</error-code>
<location>/pages/accessDenied.jsp</location>
</error-page>
If you want to set error page using accessDeniedHandler take a look at this How to redirect to access-denied-page with spring security
Upvotes: 2