Skip to content

Commit

Permalink
style: customize 403 error page with improved design
Browse files Browse the repository at this point in the history
  • Loading branch information
Guhapriya01 committed Sep 12, 2024
1 parent e5d500d commit 0111589
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 4 deletions.
8 changes: 7 additions & 1 deletion JtProject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@
</dependency>


<dependency>
<!--<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>-->

<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.3.0</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ SecurityFilterChain adminFilterChain(HttpSecurity http) throws Exception {

.logout(logout -> logout.logoutUrl("/admin/logout")
.logoutSuccessUrl("/admin/login")
.deleteCookies("JSESSIONID"));
.deleteCookies("JSESSIONID"))
.exceptionHandling(exception -> exception
.accessDeniedPage("/403") // Custom 403 page
);
http.csrf(csrf -> csrf.disable());
return http.build();
}
Expand All @@ -73,7 +76,10 @@ SecurityFilterChain userFilterChain(HttpSecurity http) throws Exception {

.logout(logout -> logout.logoutUrl("/logout")
.logoutSuccessUrl("/login")
.deleteCookies("JSESSIONID"));
.deleteCookies("JSESSIONID"))
.exceptionHandling(exception -> exception
.accessDeniedPage("/403") // Custom 403 page
);

http.csrf(csrf -> csrf.disable());
return http.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.jtspringproject.JtSpringProject.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class ErrorController {

@GetMapping("/403")
public String accessDenied() {
return "403";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public boolean userExists(String username) {

@Transactional
public User getUserByUsername(String username) {
Query<User> query = sessionFactory.getCurrentSession().createQuery("from User where username = :username", User.class);
Query<User> query = sessionFactory.getCurrentSession().createQuery("from CUSTOMER where username = :username");
query.setParameter("username", username);

try {
Expand Down
58 changes: 58 additions & 0 deletions JtProject/src/main/webapp/views/403.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>403 - Forbidden</title>
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f4f4f4;
color: #333;
text-align: center;
padding: 50px;
}
h1 {
font-size: 3em;
color: #e74c3c;
}
p {
font-size: 1.5em;
color: #555;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}
.button {
display: inline-block;
margin-top: 20px;
padding: 10px 20px;
font-size: 1.2em;
background-color: #3498db;
color: white;
text-decoration: none;
border-radius: 5px;
}
.button:hover {
background-color: #2980b9;
}
</style>
</head>
<body>
<div class="container">
<h1>403 - Forbidden</h1>
<p>Sorry, you do not have permission to access this page.</p>
</div>
</body>
</html>

0 comments on commit 0111589

Please sign in to comment.