diff --git a/app/api/src/main/java/org/example/config/SecurityConfig.java b/app/api/src/main/java/org/example/config/SecurityConfig.java index 18196f1a..440d3db7 100644 --- a/app/api/src/main/java/org/example/config/SecurityConfig.java +++ b/app/api/src/main/java/org/example/config/SecurityConfig.java @@ -1,6 +1,9 @@ package org.example.config; import java.util.Collections; +import lombok.RequiredArgsConstructor; +import org.example.filter.ExceptionHandlerFilter; +import org.example.filter.JWTFilter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; @@ -8,13 +11,18 @@ import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfigurationSource; @Configuration @EnableWebSecurity +@RequiredArgsConstructor public class SecurityConfig { + private final JWTFilter jwtFilter; + private final ExceptionHandlerFilter exceptionHandlerFilter; + @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { return http @@ -29,6 +37,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .requestMatchers("swagger-ui/**", "/v3/api-docs/**").permitAll() .anyRequest().permitAll() ) + .addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class) + .addFilterBefore(exceptionHandlerFilter, JWTFilter.class) .build(); } diff --git a/app/api/src/main/java/org/example/error/GlobalExceptionHandler.java b/app/api/src/main/java/org/example/error/GlobalExceptionHandler.java index 70228898..1ce2f8d3 100644 --- a/app/api/src/main/java/org/example/error/GlobalExceptionHandler.java +++ b/app/api/src/main/java/org/example/error/GlobalExceptionHandler.java @@ -1,8 +1,8 @@ package org.example.error; -import exception.BusinessException; -import exception.ErrorResponse; -import exception.GlobalError; +import org.example.exception.BusinessException; +import org.example.exception.ErrorResponse; +import org.example.exception.GlobalError; import jakarta.validation.ConstraintViolationException; import java.util.UUID; import lombok.extern.slf4j.Slf4j; diff --git a/app/api/src/main/java/org/example/filter/ExceptionHandlerFilter.java b/app/api/src/main/java/org/example/filter/ExceptionHandlerFilter.java index 79631fc0..90796597 100644 --- a/app/api/src/main/java/org/example/filter/ExceptionHandlerFilter.java +++ b/app/api/src/main/java/org/example/filter/ExceptionHandlerFilter.java @@ -1,8 +1,8 @@ package org.example.filter; import com.fasterxml.jackson.databind.ObjectMapper; -import exception.BusinessException; -import exception.ErrorResponse; +import org.example.exception.BusinessException; +import org.example.exception.ErrorResponse; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; diff --git a/app/api/src/main/java/org/example/security/token/JWTFilter.java b/app/api/src/main/java/org/example/filter/JWTFilter.java similarity index 94% rename from app/api/src/main/java/org/example/security/token/JWTFilter.java rename to app/api/src/main/java/org/example/filter/JWTFilter.java index 7ba797b9..b0f608c1 100644 --- a/app/api/src/main/java/org/example/security/token/JWTFilter.java +++ b/app/api/src/main/java/org/example/filter/JWTFilter.java @@ -1,4 +1,4 @@ -package org.example.security.token; +package org.example.filter; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.servlet.FilterChain; @@ -11,6 +11,8 @@ import org.example.security.dto.AuthenticatedUser; import org.example.security.dto.TokenParam; import org.example.security.dto.UserParam; +import org.example.security.token.JWTProcessor; +import org.example.security.token.RefreshTokenProcessor; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; diff --git a/app/api/src/main/java/org/example/security/token/JWTProcessor.java b/app/api/src/main/java/org/example/security/token/JWTProcessor.java index c1ce7678..e37295f8 100644 --- a/app/api/src/main/java/org/example/security/token/JWTProcessor.java +++ b/app/api/src/main/java/org/example/security/token/JWTProcessor.java @@ -1,6 +1,6 @@ package org.example.security.token; -import exception.BusinessException; +import org.example.exception.BusinessException; import io.jsonwebtoken.ExpiredJwtException; import io.jsonwebtoken.Jwt; import io.jsonwebtoken.Jwts; diff --git a/app/api/src/main/java/org/example/security/vo/TokenError.java b/app/api/src/main/java/org/example/security/vo/TokenError.java index a7d91e34..3cd03fbe 100644 --- a/app/api/src/main/java/org/example/security/vo/TokenError.java +++ b/app/api/src/main/java/org/example/security/vo/TokenError.java @@ -1,6 +1,6 @@ package org.example.security.vo; -import exception.BusinessError; +import org.example.exception.BusinessError; public enum TokenError implements BusinessError { diff --git a/app/api/src/test/java/org/example/security/token/JWTProcessorTest.java b/app/api/src/test/java/org/example/security/token/JWTProcessorTest.java index d9b4ebaa..6139f963 100644 --- a/app/api/src/test/java/org/example/security/token/JWTProcessorTest.java +++ b/app/api/src/test/java/org/example/security/token/JWTProcessorTest.java @@ -3,7 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import exception.BusinessException; +import org.example.exception.BusinessException; import java.util.Date; import java.util.UUID; import org.example.property.TokenProperty; diff --git a/common/src/main/java/exception/BusinessError.java b/common/src/main/java/org/example/exception/BusinessError.java similarity index 82% rename from common/src/main/java/exception/BusinessError.java rename to common/src/main/java/org/example/exception/BusinessError.java index 5b3012e3..625b21dc 100644 --- a/common/src/main/java/exception/BusinessError.java +++ b/common/src/main/java/org/example/exception/BusinessError.java @@ -1,4 +1,4 @@ -package exception; +package org.example.exception; public interface BusinessError { diff --git a/common/src/main/java/exception/BusinessException.java b/common/src/main/java/org/example/exception/BusinessException.java similarity index 87% rename from common/src/main/java/exception/BusinessException.java rename to common/src/main/java/org/example/exception/BusinessException.java index 34c08b6a..9fc9e5ac 100644 --- a/common/src/main/java/exception/BusinessException.java +++ b/common/src/main/java/org/example/exception/BusinessException.java @@ -1,4 +1,4 @@ -package exception; +package org.example.exception; public class BusinessException extends RuntimeException { diff --git a/common/src/main/java/exception/ErrorResponse.java b/common/src/main/java/org/example/exception/ErrorResponse.java similarity index 98% rename from common/src/main/java/exception/ErrorResponse.java rename to common/src/main/java/org/example/exception/ErrorResponse.java index 772de6ec..94ad2830 100644 --- a/common/src/main/java/exception/ErrorResponse.java +++ b/common/src/main/java/org/example/exception/ErrorResponse.java @@ -1,4 +1,4 @@ -package exception; +package org.example.exception; public record ErrorResponse( String errorId, diff --git a/common/src/main/java/exception/GlobalError.java b/common/src/main/java/org/example/exception/GlobalError.java similarity index 98% rename from common/src/main/java/exception/GlobalError.java rename to common/src/main/java/org/example/exception/GlobalError.java index 980b7f4a..bed9ca06 100644 --- a/common/src/main/java/exception/GlobalError.java +++ b/common/src/main/java/org/example/exception/GlobalError.java @@ -1,4 +1,4 @@ -package exception; +package org.example.exception; public enum GlobalError implements BusinessError {