diff --git a/pom.xml b/pom.xml
index 809654a..39cc9bb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,6 +1,6 @@
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
org.springframework.boot
@@ -54,6 +54,21 @@
org.springframework.boot
spring-boot-starter-security
+
+ io.jsonwebtoken
+ jjwt-api
+ 0.11.5
+
+
+ io.jsonwebtoken
+ jjwt-impl
+ 0.11.5
+
+
+ io.jsonwebtoken
+ jjwt-jackson
+ 0.11.5
+
org.springframework.boot
spring-boot-starter-web
@@ -62,16 +77,27 @@
org.springframework.boot
spring-boot-starter-web-services
+
+
+
+
+
org.springframework.session
spring-session-jdbc
+
org.springframework.boot
spring-boot-devtools
runtime
true
+
+
+
+
+
com.mysql
mysql-connector-j
@@ -199,4 +225,4 @@
-
\ No newline at end of file
+
diff --git a/src/main/java/org/cmh/backend/Config/CorsConfig.java b/src/main/java/org/cmh/backend/Config/CorsConfig.java
deleted file mode 100644
index d178880..0000000
--- a/src/main/java/org/cmh/backend/Config/CorsConfig.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package org.cmh.backend.Config;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.web.servlet.config.annotation.CorsRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-
-@Configuration
-public class CorsConfig {
-
- @Bean
- public WebMvcConfigurer corsConfigurer() {
- return new WebMvcConfigurer() {
- @Override
- public void addCorsMappings(CorsRegistry registry) {
- registry.addMapping("/api/**")
- .allowedOrigins("http://localhost:3000")
- .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
- .allowedHeaders("*")
- .allowCredentials(true);
- }
- };
- }
-}
\ No newline at end of file
diff --git a/src/main/java/org/cmh/backend/Config/SecurityConfig.java b/src/main/java/org/cmh/backend/Config/SecurityConfig.java
index 48dd95f..c917d0a 100644
--- a/src/main/java/org/cmh/backend/Config/SecurityConfig.java
+++ b/src/main/java/org/cmh/backend/Config/SecurityConfig.java
@@ -3,52 +3,21 @@ package org.cmh.backend.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
-import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain;
-import org.springframework.web.cors.CorsConfiguration;
-import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
-import org.springframework.web.filter.CorsFilter;
-
-import java.util.List;
@Configuration
-@EnableWebSecurity
public class SecurityConfig {
- @Bean
- public PasswordEncoder passwordEncoder() {
- return new BCryptPasswordEncoder();
- }
-
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
- http
- .csrf(csrf -> csrf.disable())
- .cors(cors -> cors.configurationSource(corsConfigurationSource()))
+ // Use the new API to disable CSRF
+ http.csrf(AbstractHttpConfigurer::disable)
+ // Permit all requests
.authorizeHttpRequests(authorize -> authorize
- .requestMatchers("/api/auth/register", "/api/auth/login").permitAll()
- .anyRequest().authenticated()
+ .anyRequest().permitAll()
);
return http.build();
}
-
- @Bean
- public UrlBasedCorsConfigurationSource corsConfigurationSource() {
- UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
- CorsConfiguration config = new CorsConfiguration();
- config.setAllowCredentials(true);
- config.setAllowedOrigins(List.of("http://localhost:3000"));
- config.setAllowedHeaders(List.of("*"));
- config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS"));
- source.registerCorsConfiguration("/**", config);
- return source;
- }
-
- @Bean
- public CorsFilter corsFilter() {
- return new CorsFilter(corsConfigurationSource());
- }
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/cmh/backend/Utils/GlobalExceptionHandler.java b/src/main/java/org/cmh/backend/Utils/GlobalExceptionHandler.java
new file mode 100644
index 0000000..b513f14
--- /dev/null
+++ b/src/main/java/org/cmh/backend/Utils/GlobalExceptionHandler.java
@@ -0,0 +1,15 @@
+package org.cmh.backend.Utils;
+
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+
+@ControllerAdvice
+public class GlobalExceptionHandler {
+
+ @ExceptionHandler(JwtValidationException.class)
+ public ResponseEntity