From 16a2b3edc731848e479a5ba5dc85e73ddde4f431 Mon Sep 17 00:00:00 2001 From: momnpa333 Date: Thu, 25 Apr 2024 19:42:30 +0900 Subject: [PATCH] =?UTF-8?q?KNU-HAEDAL#1=20feat:=20docs=20=EB=B0=8F=20?= =?UTF-8?q?=EA=B6=8C=ED=95=9C=20=EA=B4=80=EB=A0=A8=20config=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/config/JwtAuthorizationFilter.java | 8 +++++++- .../gifticionfunding/auth/config/SecurityConfig.java | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/team/haedal/gifticionfunding/auth/config/JwtAuthorizationFilter.java b/src/main/java/team/haedal/gifticionfunding/auth/config/JwtAuthorizationFilter.java index 317d438..e5b8e38 100644 --- a/src/main/java/team/haedal/gifticionfunding/auth/config/JwtAuthorizationFilter.java +++ b/src/main/java/team/haedal/gifticionfunding/auth/config/JwtAuthorizationFilter.java @@ -5,6 +5,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.Authentication; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -23,14 +24,18 @@ @Component @RequiredArgsConstructor +@Slf4j public class JwtAuthorizationFilter extends OncePerRequestFilter { private final JwtProvider jwtProvider; @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException { + log.info("dofilterinternal 실행"); + + if (request.getRequestURI().startsWith("/oauth2") || request.getRequestURI().startsWith("/refresh") ||request.getRequestURI().startsWith("/swagger-ui")||request.getRequestURI().startsWith("/api-docs")||request.getRequestURI().startsWith("/v3")) { + log.info("다음필터 실행"); - if (request.getRequestURI().startsWith("/oauth2") | request.getRequestURI().startsWith("/refresh")) { filterChain.doFilter(request, response); return; } @@ -48,6 +53,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse throw new IllegalArgumentException("예상치 못한 토큰 오류"); } + log.info("다음필터 실행"); // 다음 Filter를 실행하기 위한 코드. 마지막 필터라면 필터 실행 후 리소스를 반환한다. filterChain.doFilter(request, response); } diff --git a/src/main/java/team/haedal/gifticionfunding/auth/config/SecurityConfig.java b/src/main/java/team/haedal/gifticionfunding/auth/config/SecurityConfig.java index f66668f..e1f8991 100644 --- a/src/main/java/team/haedal/gifticionfunding/auth/config/SecurityConfig.java +++ b/src/main/java/team/haedal/gifticionfunding/auth/config/SecurityConfig.java @@ -1,6 +1,7 @@ package team.haedal.gifticionfunding.auth.config; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; @@ -21,6 +22,7 @@ @Configuration @EnableWebSecurity @RequiredArgsConstructor +@Slf4j public class SecurityConfig { private final CustomAuthenticationEntryPoint customAuthenticationEntryPoint; private final CustomAccessDeniedHandler customAccessDeniedHandler; @@ -38,6 +40,7 @@ public class SecurityConfig { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { + log.info("필터체인 실행"); http .csrf(AbstractHttpConfigurer::disable) .cors(c -> c.configurationSource(corsConfigSource())) @@ -45,7 +48,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .sessionCreationPolicy(SessionCreationPolicy.STATELESS)) .authorizeHttpRequests(authReq -> authReq .requestMatchers(HttpMethod.OPTIONS).permitAll() - .requestMatchers("/", "/login", "/oauth2/**", "/refresh").permitAll() + .requestMatchers("/", "/login", "/oauth2/**", "/refresh","/swagger-ui/**","/api-docs","/v3/api-docs/**").permitAll() .anyRequest().authenticated()) .exceptionHandling(e -> e .authenticationEntryPoint(customAuthenticationEntryPoint)