Skip to content

Commit

Permalink
♻️ [Refactor] health check 로그 발생 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
chanmin-00 committed Jul 24, 2024
1 parent a0cec65 commit 2cfde7d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/main/java/WatchWithMe/global/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf(c -> c.disable())
.addFilterBefore(corsFilter, UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(customJwtFilter, UsernamePasswordAuthenticationFilter.class)
.sessionManagement(c -> c.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.exceptionHandling(c -> {
c.authenticationEntryPoint(jwtAuthenticationEntryPoint).accessDeniedHandler(jwtAccessDeniedHandler);
Expand All @@ -58,6 +56,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers("/api/v1/admin/**").hasAuthority("ADMIN")
.anyRequest().authenticated();
});
http.addFilterBefore(customJwtFilter, UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(corsFilter, UsernamePasswordAuthenticationFilter.class);

return http.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public CorsFilter corsFilter() {
config.addAllowedMethod("*");

source.registerCorsConfiguration("/api/**", config);
source.registerCorsConfiguration("/health", config);

return new CorsFilter((CorsConfigurationSource) source);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,14 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
String jwt = resolveToken(req);
String requestURI = req.getRequestURI();

// health check 제외
if (requestURI.startsWith("/health")) {
chain.doFilter(request, response);
return;
}

// 토큰 유효성 검사
if (StringUtils.hasText(jwt) && tokenProvider.validateToken(jwt)) { // 토큰에 이상이 없는 경우
// 토큰에서 사용자명, 권한을 추출하여 스프링 시큐리티 사용자를 만들어 Authentication 반환
Authentication authentication = tokenProvider.getAuthentication(jwt);
SecurityContextHolder.getContext().setAuthentication(authentication);
log.info("Security Context에 " + authentication.getName() + "인증 정보를 저장했습니다. URI : " + requestURI);
} else {
log.info("유효한 JWT 토큰이 없습니다. URI: " + requestURI);
log.info("유효한 JWT 토큰이 없습니다. URI : " + requestURI);
}

chain.doFilter(request, response);
Expand Down

0 comments on commit 2cfde7d

Please sign in to comment.