Skip to content

Commit e13fee7

Browse files
committed
[CICD] securityConfig 수정
1 parent 419cdf6 commit e13fee7

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/main/java/fitfit/domain/token/filter/JwtAuthenticationFilter.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,45 @@
66
import jakarta.servlet.http.HttpServletRequest;
77
import jakarta.servlet.http.HttpServletResponse;
88
import lombok.RequiredArgsConstructor;
9+
import org.springframework.http.HttpMethod;
910
import org.springframework.lang.NonNull;
1011
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
1112
import org.springframework.security.core.context.SecurityContextHolder;
1213
import org.springframework.security.core.userdetails.UserDetails;
1314
import org.springframework.security.core.userdetails.UserDetailsService;
1415
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
1516
import org.springframework.stereotype.Component;
17+
import org.springframework.util.AntPathMatcher;
1618
import org.springframework.web.filter.OncePerRequestFilter;
1719

1820
import java.io.IOException;
21+
import java.util.List;
1922

2023
@Component
2124
@RequiredArgsConstructor
2225
public class JwtAuthenticationFilter extends OncePerRequestFilter {
2326

2427
private final JwtProvider jwtProvider;
2528
private final UserDetailsService userDetailsService;
29+
private final AntPathMatcher antPathMatcher = new AntPathMatcher();
30+
31+
private static final List<String> WHITE_LIST = List.of(
32+
"/swagger-ui/**",
33+
"/v3/api-docs/**",
34+
"/swagger-resources/**",
35+
"/webjars/**",
36+
"/auth/**",
37+
"/api/members/auth/kko",
38+
"/auth/refresh"
39+
);
40+
41+
@Override
42+
protected boolean shouldNotFilter(HttpServletRequest request) {
43+
if (request.getMethod().equalsIgnoreCase(HttpMethod.OPTIONS.name())) {
44+
return true;
45+
}
46+
return WHITE_LIST.stream().anyMatch(white -> antPathMatcher.match(white, request.getRequestURI()));
47+
}
2648

2749
@Override
2850
protected void doFilterInternal(
@@ -53,7 +75,6 @@ protected void doFilterInternal(
5375
SecurityContextHolder.getContext().setAuthentication(authToken);
5476
}
5577
} catch (Exception e) {
56-
// Bearer 토큰이 있지만 유효하지 않은 경우, 컨텍스트를 비워서 인증되지 않은 상태로 만듭니다.
5778
SecurityContextHolder.clearContext();
5879
}
5980

0 commit comments

Comments
 (0)