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

import_contacts

You may also like:

Related Posts

  • 10 May

    Spring Boot + Spring Security example

    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 example. Github Source code: Download Spring Boot + Spring Security example: Here are steps to create a Spring boot + […]

  • 14 September

    Spring Rest + Spring Security example

    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 introduction Difference between SOAP and REST web services SOAP web service example in java using eclipse JAX-WS web service eclipse tutorial JAX-WS […]

  • 12 September

    spring security database authentication example

    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 credentials from database. In this post, we will do authentication using database. We […]

  • 15 January

    Spring Security custom login form example

    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 example Spring MVC interceptor example Spring MVC angularjs example Spring MVC @RequestMapping example Spring Component,Service, […]

  • 12 January

    Spring Security hello world example

    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 Spring Component,Service, Repository and Controller example Spring MVC @ModelAttribute annotation example Spring […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.