Spring Security

Customize http 403 access denied page in Spring Security

<div dir&equals;"ltr" style&equals;"text-align&colon; justify&semi;">&NewLine;<p>In this tutorial we will discuss about the using custom access denied page or 403 page&lpar;Customized Access Denied Page in Spring Security&rpar; for access control for a specific resource or url&period;<&sol;p>&NewLine;<p>Access denied page appears when an unauthorized user which has not privileged for viewing a page&sol;section &comma; try to view it using their login &amp&semi; password&period; For example&comma; when an unprivileged user tries to view an admin section pages &comma; an error page will appear showing the error code 403 and a message &&num;8220&semi;Access is denied&&num;8221&semi;&period; In this section&comma; we will customize the access denied page&period;<&sol;p>&NewLine;<div id&equals;"ads-id" align&equals;"center"><&sol;div>&NewLine;<p>In the below example&comma; we will ensure secure URL access by providing auto generated Login form using Spring Security&period; User needs to provide correct login credential to view the page&period; For accessing admin section&comma; you need to provide admin login and password&period; While for user section&comma; both admin and user login are permitted&period; If you access with non admin privileges then it redirect to the custom access denied page as follows&period;<br &sol;>&NewLine;There are two ways for using custom denied page&period;<&sol;p>&NewLine;<h2><b>1&period; <&sol;b><b>access-denied-handler<&sol;b><&sol;h2>&NewLine;<pre class&equals;"highlight">&lt&semi;security&colon;http auto-config&equals;"true"&gt&semi; &NewLine; &lt&semi;security&colon;intercept-url pattern&equals;"&sol;admin&ast;" access&equals;"ROLE&lowbar;ADMIN" &sol;&gt&semi; &NewLine; &lt&semi;security&colon;logout logout-success-url&equals;"&sol;index" &sol;&gt&semi; &NewLine; &lt&semi;security&colon;intercept-url pattern&equals;"&sol;index&ast;" access&equals;"ROLE&lowbar;USER&comma;ROLE&lowbar;ADMIN" &sol;&gt&semi; &NewLine; &lt&semi;security&colon;logout logout-success-url&equals;"&sol;index" &sol;&gt&semi; &NewLine; &lt&semi;security&colon;access-denied-handler error-page&equals;"&sol;403"&sol;&gt&semi; &NewLine;&lt&semi;&sol;security&colon;http&gt&semi; &NewLine;<&sol;pre>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<div style&equals;"background-color&colon; &num;f2f9fc&semi; border&colon; 1px solid &num;c9e6f2&semi; border-radius&colon; 3px&semi; padding&colon; 16px&semi; line-height&colon; 1&period;45&semi;"><span style&equals;"color&colon; red&semi; font-size&colon; x-large&semi; text-align&colon; center&semi;"><b>Popular Tutorials<&sol;b><&sol;span><&sol;p>&NewLine;<ul style&equals;"text-align&colon; left&semi;">&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-tutorial&sol;"><em><strong>Spring Tutorial<&sol;strong> <&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-web-mvc-framework-chapter-38&sol;"><strong><em>Spring MVC Web Tutorial <&sol;em><&sol;strong><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;introduction-to-spring-boot-a-spring-boot-complete-guide&sol;"><strong>Spring Boot Tutorial<&sol;strong> <&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-take-baby-step-to-secure&sol;"><em>Spring Security Tutorial<&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-aop-tutorial-with-example-aspect-advice-pointcut-joinpoint&sol;"><em>Spring AOP Tutorial<&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;using-spring-jdbc-framework-chapter-32&sol;"><em>Spring JDBC Tutorial<&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-hateoas-hypermedia-driven-restful-web-service&sol;"><em><strong>Spring HATEOAS <&sol;strong><&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;microservices-with-spring-boot&sol;"><em><strong>Microservices with Spring Boot<&sol;strong><&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;jax-rs-web-service-tutorial&sol;"><strong><em>REST Webservice<&sol;em> <&sol;strong><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;core-java-baby-step-to-be-best-java-ian&sol;"><em><strong>Core Java <&sol;strong><&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;hibernate-3-on-baby-steps&sol;"><em><strong>Hibernate Tutorial<&sol;strong><&sol;em><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-batch-process-with-example&sol;"><strong><em>Spring Batch<&sol;em> <&sol;strong><&sol;a><&sol;b><&sol;li>&NewLine;<&sol;ul>&NewLine;<&sol;div>&NewLine;<p><b>Tag- <i>access-denied-handler<&sol;i><&sol;b><br &sol;>&NewLine;Defines the access-denied strategy that should be used&period; An access denied page can be defined or a reference to  an <b><i>AccessDeniedHandler <&sol;i><&sol;b>instance&period;<&sol;p>&NewLine;<p><b>Attribute- <i>error-page<&sol;i><&sol;b><br &sol;>&NewLine;The access denied page that an authenticated user will be redirected to if they request a page which they don&&num;8217&semi;t  have the authority to access&period;<&sol;p>&NewLine;<p>It means the user with authority as <b>ROLE&lowbar;ADMIN<&sol;b> can have access to URL <i><b>&sol;admin<&sol;b><&sol;i> &period; Also&comma; the URL <i><b>&sol;index <&sol;b><&sol;i>is open for both type of users having authority<b> ROLE&lowbar;USER or ROLE&lowbar;ADMIN<&sol;b> &period; If non authorized user try to access &sol;admin&comma; a &&num;8220&semi;<b>http 403 access denied custom page&lpar;403&period;jsp&rpar;<&sol;b>&&num;8221&semi; will be displayed&period;<&sol;p>&NewLine;<h2><b>2&period; AccessDeniedHandler&colon;<&sol;b><&sol;h2>&NewLine;<p>In second way&comma; create a class and implements Spring’s AccessDeniedHandler&comma; override handle&lpar;&rpar; method and put your access denied logic inside&period;<&sol;p>&NewLine;<pre class&equals;"highlight">package com&period;dineshonjava&period;error&period;handler&semi; &NewLine; &NewLine;import java&period;io&period;IOException&semi; &NewLine;import javax&period;servlet&period;ServletException&semi; &NewLine;import javax&period;servlet&period;http&period;HttpServletRequest&semi; &NewLine;import javax&period;servlet&period;http&period;HttpServletResponse&semi; &NewLine;import org&period;springframework&period;security&period;access&period;AccessDeniedException&semi; &NewLine;import org&period;springframework&period;security&period;web&period;access&period;AccessDeniedHandler&semi; &NewLine; &NewLine;public class MyAccessDeniedHandler implements AccessDeniedHandler &lbrace; &NewLine; private String accessDeniedUrl&semi; &NewLine; &NewLine; public MyAccessDeniedHandler&lpar;&rpar; &lbrace; &NewLine; &rcub; &NewLine; &NewLine; public MyAccessDeniedHandler&lpar;String accessDeniedUrl&rpar; &lbrace; &NewLine; this&period;accessDeniedUrl &equals; accessDeniedUrl&semi; &NewLine; &rcub; &NewLine; &NewLine; &commat;Override &NewLine; public void handle&lpar;HttpServletRequest request&comma; &NewLine; HttpServletResponse response&comma; &NewLine; AccessDeniedException accessDeniedException&rpar; throws IOException&comma; &NewLine; ServletException &lbrace; &NewLine; &NewLine; response&period;sendRedirect&lpar;accessDeniedUrl&rpar;&semi; &NewLine; request&period;getSession&lpar;&rpar;&period;setAttribute&lpar;"message"&comma; &NewLine; " Sorry user&lowbar;dineshonjava You don't have privileges to view this page&excl;&excl;&excl;"&rpar;&semi; &NewLine; &NewLine; &rcub; &NewLine; &NewLine; public String getAccessDeniedUrl&lpar;&rpar; &lbrace; &NewLine; return accessDeniedUrl&semi; &NewLine; &rcub; &NewLine; &NewLine; public void setAccessDeniedUrl&lpar;String accessDeniedUrl&rpar; &lbrace; &NewLine; this&period;accessDeniedUrl &equals; accessDeniedUrl&semi; &NewLine; &rcub; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<p><b>Declares above Spring bean<&sol;b>&period;<&sol;p>&NewLine;<pre class&equals;"highlight">&lt&semi;bean id&equals;"accessDeniedHandler" class&equals;"com&period;dineshonjava&period;error&period;handler&period;MyAccessDeniedHandler"&gt&semi; &NewLine; &lt&semi;property name&equals;"accessDeniedUrl" value&equals;"403" &sol;&gt&semi; &NewLine; &lt&semi;&sol;bean&gt&semi; &NewLine; &NewLine;&lt&semi;security&colon;http auto-config&equals;"true"&gt&semi; &NewLine; &lt&semi;security&colon;intercept-url pattern&equals;"&sol;admin&ast;" access&equals;"ROLE&lowbar;ADMIN" &sol;&gt&semi; &NewLine; &lt&semi;security&colon;logout logout-success-url&equals;"&sol;index" &sol;&gt&semi; &NewLine; &lt&semi;security&colon;intercept-url pattern&equals;"&sol;index&ast;" access&equals;"ROLE&lowbar;USER&comma;ROLE&lowbar;ADMIN" &sol;&gt&semi; &NewLine; &lt&semi;security&colon;logout logout-success-url&equals;"&sol;index" &sol;&gt&semi; &NewLine; &lt&semi;security&colon;access-denied-handler ref&equals;"accessDeniedHandler"&sol;&gt&semi; &NewLine;&lt&semi;&sol;security&colon;http&gt&semi; &NewLine;<&sol;pre>&NewLine;<p><b>Some helpful example related to this section is given below &colon;<&sol;b><br &sol;>&NewLine;Example related to Spring Security Authorized Access Using Auto generated Login Form&comma; <b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-hello-world-example&sol;" target&equals;"&lowbar;blank" rel&equals;"noopener">Click Here<&sol;a><&sol;b> &period;<br &sol;>&NewLine;Example related to Spring Security Authorized Access Using Custom Login Form&comma; <b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-form-based-login-example&sol;" target&equals;"&lowbar;blank" rel&equals;"noopener">Click Here<&sol;a><&sol;b> &period;<br &sol;>&NewLine;Example related to Spring Security Authorized Access with Customized Login from Database <b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-login-form-using&sol;" target&equals;"&lowbar;blank" rel&equals;"noopener">Click Here<&sol;a><&sol;b> &period;<&sol;p>&NewLine;<p>In last <b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-authorized-access&sol;" target&equals;"&lowbar;blank" rel&equals;"noopener">Spring Security Authorized Access Control Example<&sol;a><&sol;b> &comma; if non authorized user try to access a protected page&comma; default &&num;8220&semi;<b>http 403 access denied<&sol;b>&&num;8221&semi; will be display &colon;<&sol;p>&NewLine;<div class&equals;"separator" style&equals;"clear&colon; both&semi; text-align&colon; center&semi;"><img src&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-content&sol;uploads&sol;2013&sol;02&sol;authorized3&period;png" border&equals;"0" &sol;><&sol;div>&NewLine;<h2><b>Project Directory structure-<&sol;b><&sol;h2>&NewLine;<div class&equals;"separator" style&equals;"clear&colon; both&semi; text-align&colon; center&semi;"><img src&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-content&sol;uploads&sol;2013&sol;02&sol;authorized403&period;png" border&equals;"0" &sol;><&sol;div>&NewLine;<p><b>Creating welcome page &lpar;welcome&period;jsp&rpar;<&sol;b><&sol;p>&NewLine;<pre class&equals;"highlight">&lt&semi;&percnt;&commat; page language&equals;"java" contentType&equals;"text&sol;html&semi; charset&equals;ISO-8859-1" &NewLine; pageEncoding&equals;"ISO-8859-1"&percnt;&gt&semi; &NewLine;&lt&semi;&excl;DOCTYPE html PUBLIC "-&sol;&sol;W3C&sol;&sol;DTD HTML 4&period;01 Transitional&sol;&sol;EN" "http&colon;&sol;&sol;www&period;w3&period;org&sol;TR&sol;html4&sol;loose&period;dtd"&gt&semi; &NewLine;&lt&semi;&percnt;&commat; taglib prefix&equals;"c" uri&equals;"http&colon;&sol;&sol;java&period;sun&period;com&sol;jsp&sol;jstl&sol;core"&percnt;&gt&semi; &NewLine;&lt&semi;html&gt&semi; &NewLine;&lt&semi;head&gt&semi; &NewLine;&lt&semi;meta http-equiv&equals;"Content-Type" content&equals;"text&sol;html&semi; charset&equals;ISO-8859-1"&gt&semi; &NewLine;&lt&semi;title&gt&semi;WELCOME TO SECURE AREA&lt&semi;&sol;title&gt&semi; &NewLine;&lt&semi;&sol;head&gt&semi; &NewLine;&lt&semi;body&gt&semi; &NewLine; &lt&semi;h1&gt&semi;Message &colon; &dollar;&lbrace;message&rcub;&lt&semi;&sol;h1&gt&semi; &NewLine; &lt&semi;h1&gt&semi;Author &colon; &dollar;&lbrace;author&rcub;&lt&semi;&sol;h1&gt&semi; &NewLine; &lt&semi;a href&equals;'&lt&semi;c&colon;url value&equals;"&sol;j&lowbar;spring&lowbar;security&lowbar;logout" &sol;&gt&semi;' &gt&semi; Logout&lt&semi;&sol;a&gt&semi; &NewLine;&lt&semi;&sol;body&gt&semi; &NewLine;&lt&semi;&sol;html&gt&semi; &NewLine;<&sol;pre>&NewLine;<p><b>Assume below is your customized 403 page&colon;<br &sol;>&NewLine;403&period;jsp<br &sol;>&NewLine;<&sol;b><&sol;p>&NewLine;<pre class&equals;"highlight">&lt&semi;&percnt;&commat; page language&equals;"java" contentType&equals;"text&sol;html&semi; charset&equals;ISO-8859-1" &NewLine; pageEncoding&equals;"ISO-8859-1"&percnt;&gt&semi; &NewLine;&lt&semi;&excl;DOCTYPE html PUBLIC "-&sol;&sol;W3C&sol;&sol;DTD HTML 4&period;01 Transitional&sol;&sol;EN" "http&colon;&sol;&sol;www&period;w3&period;org&sol;TR&sol;html4&sol;loose&period;dtd"&gt&semi; &NewLine;&lt&semi;&percnt;&commat; taglib prefix&equals;"c" uri&equals;"http&colon;&sol;&sol;java&period;sun&period;com&sol;jsp&sol;jstl&sol;core"&percnt;&gt&semi; &NewLine;&lt&semi;html&gt&semi; &NewLine;&lt&semi;head&gt&semi; &NewLine;&lt&semi;meta http-equiv&equals;"Content-Type" content&equals;"text&sol;html&semi; charset&equals;ISO-8859-1"&gt&semi; &NewLine;&lt&semi;title&gt&semi;HTTP Status 403 - Access is denied&lt&semi;&sol;title&gt&semi; &NewLine;&lt&semi;&sol;head&gt&semi; &NewLine;&lt&semi;body&gt&semi; &NewLine; &lt&semi;h1&gt&semi;Message &colon; &dollar;&lbrace;message&rcub;&lt&semi;&sol;h1&gt&semi; &NewLine;&lt&semi;&sol;body&gt&semi; &NewLine;&lt&semi;&sol;html&gt&semi; &NewLine;<&sol;pre>&NewLine;<p><b>Creating AdminController class &lpar;AdminController&period;java&rpar;<br &sol;>&NewLine;AdminController&period;java<br &sol;>&NewLine;<&sol;b><&sol;p>&NewLine;<pre class&equals;"highlight">package com&period;dineshonjava&period;admin&period;controller&semi; &NewLine; &NewLine;import java&period;security&period;Principal&semi; &NewLine; &NewLine;import org&period;springframework&period;stereotype&period;Controller&semi; &NewLine;import org&period;springframework&period;ui&period;ModelMap&semi; &NewLine;import org&period;springframework&period;web&period;bind&period;annotation&period;RequestMapping&semi; &NewLine;import org&period;springframework&period;web&period;bind&period;annotation&period;RequestMethod&semi; &NewLine; &NewLine;&sol;&ast;&ast; &NewLine; &ast; &commat;author Dinesh Rajput &NewLine; &ast; &NewLine; &ast;&sol; &NewLine;&commat;Controller &NewLine;public class AdminController &lbrace; &NewLine; &NewLine; &commat;RequestMapping&lpar;value &equals; "&sol;admin"&comma; method &equals; RequestMethod&period;GET&rpar; &NewLine; public String welcomeAdmin&lpar;ModelMap model&comma; Principal principal&rpar; &lbrace; &NewLine; String username &equals; principal&period;getName&lpar;&rpar;&semi; &NewLine; model&period;addAttribute&lpar;"author"&comma; username&rpar;&semi; &NewLine; model&period;addAttribute&lpar;"message"&comma; "Hello Spring Security - ADMIN PAGE"&rpar;&semi; &NewLine; return "welcome"&semi; &NewLine; &NewLine; &rcub; &NewLine; &NewLine; &commat;RequestMapping&lpar;value &equals; "&sol;index"&comma; method &equals; RequestMethod&period;GET&rpar; &NewLine; public String printMessage&lpar;ModelMap model&comma; Principal principal&rpar; &lbrace; &NewLine; &NewLine; String username &equals; principal&period;getName&lpar;&rpar;&semi; &NewLine; model&period;addAttribute&lpar;"author"&comma; username&rpar;&semi; &NewLine; model&period;addAttribute&lpar;"message"&comma; "Hello Spring Security - USER LOGIN"&rpar;&semi; &NewLine; return "welcome"&semi; &NewLine; &rcub; &NewLine; &NewLine; &commat;RequestMapping&lpar;value &equals; "&sol;403"&comma; method &equals; RequestMethod&period;GET&rpar; &NewLine; public String accessDenied&lpar;ModelMap model&comma; Principal principal&rpar; &lbrace; &NewLine; String username &equals; principal&period;getName&lpar;&rpar;&semi; &NewLine; model&period;addAttribute&lpar;"message"&comma; "Sorry "&plus;username&plus;" You don't have privileges to view this page&excl;&excl;&excl;"&rpar;&semi; &NewLine; return "403"&semi; &NewLine; &rcub; &NewLine; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<p><b>Spring Securing Configuration file &lpar;sdnext-security&period;xml&rpar;<&sol;b><&sol;p>&NewLine;<pre class&equals;"highlight">&lt&semi;&quest;xml version&equals;"1&period;0" encoding&equals;"UTF-8"&quest;&gt&semi; &NewLine;&lt&semi;beans xmlns&equals;"http&colon;&sol;&sol;www&period;springframework&period;org&sol;schema&sol;beans" &NewLine; xmlns&colon;xsi&equals;"http&colon;&sol;&sol;www&period;w3&period;org&sol;2001&sol;XMLSchema-instance" &NewLine; xmlns&colon;> &NewLine;<b>Spring Configuration File &lpar;sdnext-servlet&period;xml&rpar;<&sol;b> &NewLine;<pre class&equals;"highlight">&lt&semi;&quest;xml version&equals;"1&period;0" encoding&equals;"UTF-8"&quest;&gt&semi; &NewLine;&lt&semi;beans xmlns&equals;"http&colon;&sol;&sol;www&period;springframework&period;org&sol;schema&sol;beans" &NewLine; xmlns&colon;xsi&equals;"http&colon;&sol;&sol;www&period;w3&period;org&sol;2001&sol;XMLSchema-instance" &NewLine; xmlns&colon;context&equals;"http&colon;&sol;&sol;www&period;springframework&period;org&sol;schema&sol;context" &NewLine; xmlns&colon;tx&equals;"http&colon;&sol;&sol;www&period;springframework&period;org&sol;schema&sol;tx" &NewLine; xsi&colon;schemaLocation&equals;" &NewLine;http&colon;&sol;&sol;www&period;springframework&period;org&sol;schema&sol;beans &NewLine;http&colon;&sol;&sol;www&period;springframework&period;org&sol;schema&sol;beans&sol;spring-beans-3&period;0&period;xsd &NewLine;http&colon;&sol;&sol;www&period;springframework&period;org&sol;schema&sol;context &NewLine;http&colon;&sol;&sol;www&period;springframework&period;org&sol;schema&sol;context&sol;spring-context-3&period;0&period;xsd &NewLine;http&colon;&sol;&sol;www&period;springframework&period;org&sol;schema&sol;tx &NewLine;http&colon;&sol;&sol;www&period;springframework&period;org&sol;schema&sol;tx&sol;spring-tx-3&period;0&period;xsd"&gt&semi; &NewLine; &NewLine; &lt&semi;context&colon;component-scan base-package&equals;"com&period;dineshonjava&period;admin" &sol;&gt&semi; &NewLine; &NewLine; &NewLine; &lt&semi;bean id&equals;"jspViewResolver" &NewLine; class&equals;"org&period;springframework&period;web&period;servlet&period;view&period;InternalResourceViewResolver"&gt&semi; &NewLine; &lt&semi;property name&equals;"viewClass" &NewLine; value&equals;"org&period;springframework&period;web&period;servlet&period;view&period;JstlView" &sol;&gt&semi; &NewLine; &lt&semi;property name&equals;"prefix" value&equals;"&sol;WEB-INF&sol;views&sol;" &sol;&gt&semi; &NewLine; &lt&semi;property name&equals;"suffix" value&equals;"&period;jsp" &sol;&gt&semi; &NewLine; &lt&semi;&sol;bean&gt&semi; &NewLine; &NewLine;&lt&semi;&sol;beans&gt&semi; &NewLine;<&sol;pre>&NewLine;<p><b>Running the example<&sol;b><&sol;p>&NewLine;<p>Now&comma; if non authorized user is access the protected page&comma; your customize 403 page will be displayed &colon;<&sol;p>&NewLine;<p>When you try to access the admin using below URL &colon;<&sol;p>&NewLine;<p><i><b>http&colon;&sol;&sol;localhost&colon;8080&sol;sdnext&sol;spring&lowbar;security&lowbar;login&semi;jsessionid&equals;A576B0C8EFB29231141D4FD3DE15A751<&sol;b><&sol;i><&sol;p>&NewLine;<p>You will get the below page &colon;<&sol;p>&NewLine;<div class&equals;"separator" style&equals;"clear&colon; both&semi; text-align&colon; left&semi;"><img src&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-content&sol;uploads&sol;2013&sol;02&sol;authorized403-1&period;png" width&equals;"600" height&equals;"174" border&equals;"0" &sol;><&sol;div>&NewLine;<p>When you try to access the admin page&sol;section using a normal user login&lpar;<b>Username &colon;<i> user&lowbar;dineshonjava<&sol;i>&comma; Password&colon; <i>sweetu<&sol;i><&sol;b>&rpar;&comma; you will get the below customized access denied page &colon;<&sol;p>&NewLine;<div class&equals;"separator" style&equals;"clear&colon; both&semi; text-align&colon; center&semi;"><img src&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-content&sol;uploads&sol;2013&sol;02&sol;authorized403-2-1024x135&period;png" width&equals;"600" height&equals;"84" border&equals;"0" &sol;><&sol;div>&NewLine;<h3><b>Download Source Code &plus; Libs<&sol;b><br &sol;>&NewLine;<a href&equals;"https&colon;&sol;&sol;sites&period;google&period;com&sol;site&sol;dinesh9582486434&sol;my-forms&sol;SpringSecurityCustomAccessDeniedPage&period;zip&quest;attredirects&equals;0&amp&semi;d&equals;1" target&equals;"&lowbar;blank" rel&equals;"noopener"><b>SpringSecurityCustomAccessDeniedPage&period;zip<&sol;b><&sol;a><&sol;h3>&NewLine;<p><b>References- <&sol;b><br &sol;>&NewLine;<a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-form-based-login-example&sol;" target&equals;"&lowbar;blank" rel&equals;"noopener"><b>https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-form-based-login-example&sol;<&sol;b><&sol;a><br &sol;>&NewLine;<a href&equals;"http&colon;&sol;&sol;static&period;springsource&period;org&sol;spring-security&sol;site&sol;" target&equals;"&lowbar;blank" rel&equals;"noopener"><b>Spring Security<&sol;b><&sol;a><br &sol;>&NewLine;<a href&equals;"http&colon;&sol;&sol;static&period;springsource&period;org&sol;spring-security&sol;site&sol;docs&sol;3&period;0&period;x&sol;reference&sol;springsecurity&period;html" target&equals;"&lowbar;blank" rel&equals;"noopener"><b>Spring Security documentation<&sol;b><&sol;a><&sol;p>&NewLine;<div style&equals;"background-color&colon; &num;f2f9fc&semi; border-radius&colon; 3px&semi; border&colon; 1px solid &num;c9e6f2&semi; line-height&colon; 1&period;45&semi; padding&colon; 16px&semi;"><span style&equals;"color&colon; red&semi; font-size&colon; x-large&semi; text-align&colon; center&semi;"><b>Spring Security Related Posts<&sol;b><&sol;span><&sol;p>&NewLine;<ul>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-interview-questions-and-answers&sol;"><span style&equals;"color&colon; red&semi;">Spring Security Interview Questions and Answers<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-java-based-configuration-with-example&sol;"><span style&equals;"color&colon; red&semi;">Spring Security Java Based Configuration with Example<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-xml-namespace-configuration-example&sol;"><span style&equals;"color&colon; red&semi;">Spring Security XML Namespace Configuration Example<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-hello-world-example&sol;"><span style&equals;"color&colon; red&semi;">Spring Security XML Based Hello World Example<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-form-based-login-example&sol;"><span style&equals;"color&colon; red&semi;">Spring Security form-based login example <&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-login-form-using&sol;"><span style&equals;"color&colon; red&semi;">Spring Security Login Form Based Example Using Database<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-http-basic&sol;"><span style&equals;"color&colon; red&semi;">Spring Security Authentication Example Using HTTP Basic <&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-authorized-access&sol;"><span style&equals;"color&colon; red&semi;"> Spring Security Authorized Access Control Example <&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;customize-http-403-access-denied-page&sol;"><span style&equals;"color&colon; red&semi;">Spring Security Customized Access Denied Page<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-custom-error-message&sol;"><span style&equals;"color&colon; red&semi;">Spring Security Custom Error Message<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-logout-example&sol;"><span style&equals;"color&colon; red&semi;"> Spring Security Logout Example<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-fetch-logged-in-username&sol;"><span style&equals;"color&colon; red&semi;">Spring Security Fetch Logged in Username<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<li><b><a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-password-hashing&sol;"><span style&equals;"color&colon; red&semi;">Spring Security Password Hashing<&sol;span><&sol;a><&sol;b><&sol;li>&NewLine;<&sol;ul>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<&sol;div>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<div style&equals;"background-color&colon; &num;ff99cc&semi;">                        <b>     &lt&semi;&lt&semi;<a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-authorized-access&sol;">previous<&sol;a>&lt&semi;&lt&semi;             &vert;&vert; <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-take-baby-step-to-secure&sol;">index  <&sol;a>&vert;&vert;         &gt&semi;&gt&semi;<a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-custom-error-message&sol;">next<&sol;a>&gt&semi;&gt&semi;<&sol;b><&sol;div>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<&sol;div>&NewLine;<div class&equals;"wp-post-navigation"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <div class&equals;"wp-post-navigation-pre"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-authorized-access&sol;">Previous<&sol;a> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <&sol;div> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <div class&equals;"wp-post-navigation-next"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;spring-security-password-hashing&sol;">Next<&sol;a> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <&sol;div> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;<&sol;div>&NewLine;<script type&equals;"text&sol;javascript">&NewLine;jQuery&lpar;document&rpar;&period;ready&lpar;function&lpar;&dollar;&rpar; &lbrace;&NewLine; &dollar;&period;post&lpar;'https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-admin&sol;admin-ajax&period;php'&comma; &lbrace;action&colon; 'mts&lowbar;view&lowbar;count'&comma; id&colon; '574'&rcub;&rpar;&semi;&NewLine;&rcub;&rpar;&semi;&NewLine;<&sol;script>

Dinesh Rajput

Dinesh Rajput is the chief editor of a website Dineshonjava, a technical blog dedicated to the Spring and Java technologies. It has a series of articles related to Java technologies. Dinesh has been a Spring enthusiast since 2008 and is a Pivotal Certified Spring Professional, an author of a book Spring 5 Design Pattern, and a blogger. He has more than 10 years of experience with different aspects of Spring and Java design and development. His core expertise lies in the latest version of Spring Framework, Spring Boot, Spring Security, creating REST APIs, Microservice Architecture, Reactive Pattern, Spring AOP, Design Patterns, Struts, Hibernate, Web Services, Spring Batch, Cassandra, MongoDB, and Web Application Design and Architecture. He is currently working as a technology manager at a leading product and web development company. He worked as a developer and tech lead at the Bennett, Coleman & Co. Ltd and was the first developer in his previous company, Paytm. Dinesh is passionate about the latest Java technologies and loves to write technical blogs related to it. He is a very active member of the Java and Spring community on different forums. When it comes to the Spring Framework and Java, Dinesh tops the list!

Share
Published by
Dinesh Rajput

Recent Posts

Strategy Design Patterns using Lambda

Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…

4 years ago

Decorator Pattern using Lambda

Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…

4 years ago

Delegating pattern using lambda

Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…

4 years ago

Spring Vs Django- Know The Difference Between The Two

Technology has emerged a lot in the last decade, and now we have artificial intelligence;…

4 years ago

TOP 20 MongoDB INTERVIEW QUESTIONS 2022

Managing a database is becoming increasingly complex now due to the vast amount of data…

4 years ago

Scheduler @Scheduled Annotation Spring Boot

Overview In this article, we will explore Spring Scheduler how we could use it by…

4 years ago