diff --git a/src/main/java/ktb/hackathon/ktbgratitudediary/config/AopConfig.java b/src/main/java/ktb/hackathon/ktbgratitudediary/config/AopConfig.java new file mode 100644 index 0000000..c683709 --- /dev/null +++ b/src/main/java/ktb/hackathon/ktbgratitudediary/config/AopConfig.java @@ -0,0 +1,29 @@ +package ktb.hackathon.ktbgratitudediary.config; + +import jakarta.servlet.http.HttpServletRequest; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +@Slf4j +@Aspect +@Configuration +public class AopConfig { + + @Before("execution(* ktb.hackathon.ktbgratitudediary.controller.*.*(..))") + public void logBefore(JoinPoint joinPoint) { + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + if (attributes != null) { + HttpServletRequest request = attributes.getRequest(); + + String requestURL = request.getRequestURI(); + String methodType = request.getMethod(); + + log.info("HTTP Request - {} {}", methodType, requestURL); + } + } +} diff --git a/src/main/java/ktb/hackathon/ktbgratitudediary/security/filter/JwtAuthenticationFilter.java b/src/main/java/ktb/hackathon/ktbgratitudediary/security/filter/JwtAuthenticationFilter.java index 62087c6..5c2cd8a 100644 --- a/src/main/java/ktb/hackathon/ktbgratitudediary/security/filter/JwtAuthenticationFilter.java +++ b/src/main/java/ktb/hackathon/ktbgratitudediary/security/filter/JwtAuthenticationFilter.java @@ -26,16 +26,9 @@ public class JwtAuthenticationFilter extends GenericFilterBean { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; - log.info("RequestURI: {}", request.getRequestURI()); String token = resolveToken(request); - if(token == null) { - log.error("AccessToken is Null"); - ((HttpServletResponse) servletResponse) - .sendError(HttpServletResponse.SC_UNAUTHORIZED, "AccessToken is Null"); - return; - } - if (jwtTokenProvider.validateToken(token)) { + if (token != null && jwtTokenProvider.validateToken(token)) { var authentication = jwtTokenProvider.getAuthentication(token); SecurityContextHolder.getContext().setAuthentication(authentication); } diff --git a/src/main/java/ktb/hackathon/ktbgratitudediary/security/securityConfig.java b/src/main/java/ktb/hackathon/ktbgratitudediary/security/securityConfig.java index c6c1b94..a595cb2 100644 --- a/src/main/java/ktb/hackathon/ktbgratitudediary/security/securityConfig.java +++ b/src/main/java/ktb/hackathon/ktbgratitudediary/security/securityConfig.java @@ -95,7 +95,6 @@ public CorsConfigurationSource corsConfigurationSource() { configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); // 허용할 메서드 설정 configuration.setAllowedHeaders(List.of("Authorization", "Content-Type")); // 허용할 헤더 설정 configuration.setAllowCredentials(true); // 쿠키 등 자격 증명 허용 -// configuration.setAllowCredentials(false); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", configuration); // 모든 경로에 대해 CORS 설정 적용