Spring Security : Customize 403 access denied page

In this post , we will see how to customize 403 access denied page.
If user do not have access to page, then it will show default 403 page which will look like as below:

Spring security 403 access denied

You can customize 403 as below page:

Spring security 403 customize page

If you want to configure custom 403 access denied page, there are two ways to do it.

  • Using access-denied-handler error-page
  • Using AccessDeniedHandler ref

Using access-denied-handler error-page

You can put entry for attribute access-denied-handler in spring-security.xml as below.
so if user does not have access to page, it will be redirected to /403 and you can handle 403 in controller class as below:
We can create 403.jsp as below:

Please refer to Spring security database authentication for spring-security.xml and other files.
Using AccessDeniedHandler ref:
You can also use AccessDeniedHandler to handle 403 access denied page.

You need to add ref in http tag in spring-security.xml.

Download source code:

click to begin
20KB .zip

Was this post helpful?


import_contacts

You may also like:

Related Posts

  • 10 May

    Spring Boot + Spring Security example

    Table of ContentsGithub Source code:Spring Boot + Spring Security example:Project structure:Tools used for creating below project:Maven dependencies:Was this post helpful? In this post, we will see how to create Spring boot + Spring Security example. Let’s see how Spring boot makes over life simpler.I am going to apply Spring Security on Spring Boot hello world […]

  • 14 September

    Spring Rest + Spring Security example

    Table of ContentsRun the applicationIf you getting 404 error with above steps, you may need to follow below steps:Was this post helpful? In this post , we are going to apply Spring Security on Spring Rest example. Web services tutorial: Introduction to web services Web services interview questions SOAP web service introduction RESTful web service […]

  • 12 September

    spring security database authentication example

    Table of ContentsCreate Controller  and viewRun the applicationDownload source code:Was this post helpful? In previous post, we have already seen  how to use custom login page in Spring security. We have declared username and password in spring-security.xml but what if you want to read it from database. In most of the cases, we will read […]

  • 15 January

    Spring Security custom login form example

    Table of ContentsSpring MVC tutorial:Create Controller  and viewRun the applicationDownload source code:Was this post helpful? In previous post,we have used default login page generated by Spring security framework. In this post, we will see how to use custom login page in Spring security. Spring MVC tutorial: Spring MVC hello world example Spring MVC Hibernate MySQL […]

  • 12 January

    Spring Security hello world example

    Table of ContentsSpring MVC tutorial:Run the applicationDownload source code:Was this post helpful? In this post, we will see how to apply basic spring security to spring mvc hello world example. Spring MVC tutorial: Spring MVC hello world example Spring MVC Hibernate MySQL example Spring MVC interceptor example Spring MVC angularjs example Spring MVC @RequestMapping example […]

Leave a Reply

Your email address will not be published.

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.