diff --git a/JtProject/pom.xml b/JtProject/pom.xml index a1de54c..4ae3260 100644 --- a/JtProject/pom.xml +++ b/JtProject/pom.xml @@ -52,10 +52,16 @@ - + + + + com.mysql + mysql-connector-j + 8.3.0 diff --git a/JtProject/src/main/java/com/jtspringproject/JtSpringProject/configuration/SecurityConfiguration.java b/JtProject/src/main/java/com/jtspringproject/JtSpringProject/configuration/SecurityConfiguration.java index 64dcbdc..8689a56 100644 --- a/JtProject/src/main/java/com/jtspringproject/JtSpringProject/configuration/SecurityConfiguration.java +++ b/JtProject/src/main/java/com/jtspringproject/JtSpringProject/configuration/SecurityConfiguration.java @@ -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(); } @@ -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(); diff --git a/JtProject/src/main/java/com/jtspringproject/JtSpringProject/controller/ErrorController.java b/JtProject/src/main/java/com/jtspringproject/JtSpringProject/controller/ErrorController.java new file mode 100644 index 0000000..d349634 --- /dev/null +++ b/JtProject/src/main/java/com/jtspringproject/JtSpringProject/controller/ErrorController.java @@ -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"; + } +} diff --git a/JtProject/src/main/java/com/jtspringproject/JtSpringProject/dao/userDao.java b/JtProject/src/main/java/com/jtspringproject/JtSpringProject/dao/userDao.java index f597f1f..0861e4d 100644 --- a/JtProject/src/main/java/com/jtspringproject/JtSpringProject/dao/userDao.java +++ b/JtProject/src/main/java/com/jtspringproject/JtSpringProject/dao/userDao.java @@ -70,7 +70,7 @@ public boolean userExists(String username) { @Transactional public User getUserByUsername(String username) { - Query query = sessionFactory.getCurrentSession().createQuery("from User where username = :username", User.class); + Query query = sessionFactory.getCurrentSession().createQuery("from CUSTOMER where username = :username"); query.setParameter("username", username); try { diff --git a/JtProject/src/main/webapp/views/403.jsp b/JtProject/src/main/webapp/views/403.jsp new file mode 100644 index 0000000..46f6bb8 --- /dev/null +++ b/JtProject/src/main/webapp/views/403.jsp @@ -0,0 +1,58 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +403 - Forbidden + + + +
+

403 - Forbidden

+

Sorry, you do not have permission to access this page.

+
+ +