Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to redirect the access denied page in spring security?

I want to know how to redirect the access denied page in spring security? Shall I use some kind of handler or edit in web.xml?

thanks

like image 322
sudo Avatar asked Jan 16 '12 02:01

sudo


People also ask

How does Spring Security handle Access Denied?

Access Denied Handler. Using an access denied handler instead of a page has the advantage that we can define custom logic to be executed before redirecting to the 403 page. For this, we need to create a class that implements the AccessDeniedHandler interface and overrides the handle() method.

How do I return a 403 Spring boot?

Use this: response. setStatus(403) . Save this answer.


1 Answers

Have you read the relevant sections of the Spring Security manual, namely the AccessDeniedHandler and the namespace appendix.

If you want more control, you can use

 <http use-expressions="true">
     <intercept-url pattern="/denied/*" access="permitAll" />

     <access-denied-handler error-page="/denied">

     <!-- The rest of your configuration -->
 </http>

Where /denied maps to a web controller class which you write. Make sure /denied/** is unprotected.

If this doesn't answer your question, could you please explain in some more detail what you're trying to achieve?

like image 153
Shaun the Sheep Avatar answered Sep 22 '22 07:09

Shaun the Sheep