Skip to content

Commit

Permalink
🐛 Fix : jwt 인증 흐름 수정 (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
CYY1007 authored Feb 20, 2024
1 parent 63b3648 commit ed2135e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
@EnableWebSecurity
@EnableWebSecurity(debug = true)
@RequiredArgsConstructor
@Configuration
public class SecurityConfig {
Expand All @@ -62,6 +62,12 @@ public class SecurityConfig {
@Value("${swagger.login.password}")
private String swaggerPass;

private static final String[] JWT_WHITE_LIST ={
"/pushs","/members/auth","/v2/members/auth",
"briefings", "/v2/briefings","/chattings",
"/briefings/temp"
};

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
Expand All @@ -77,13 +83,11 @@ public WebSecurityCustomizer webSecurityCustomizer() {
return (web) ->
web.ignoring()
.requestMatchers(
"",
"/",
"","/",
"/schedule",
"/v3/api-docs",
"/v3/api-docs/**",
"/docs/**","/fcms/**","/members/auth/**","/v2/members/auth/**",
"/briefings/temp");
"/docs/**");
}

@Bean
Expand Down Expand Up @@ -147,7 +151,7 @@ public SecurityFilterChain JwtFilterChain(HttpSecurity http) throws Exception {
.authenticationEntryPoint(jwtAuthenticationEntryPoint)
.accessDeniedHandler(jwtAccessDeniedHandler))
.addFilterBefore(
new JwtRequestFilter(tokenProvider),
new JwtRequestFilter(tokenProvider,JWT_WHITE_LIST),
UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(jwtAuthenticationExceptionHandler, JwtRequestFilter.class)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.briefingapi.security.filter;

import java.io.IOException;
import java.util.Arrays;

import com.example.briefingapi.security.provider.TokenProvider;
import jakarta.servlet.FilterChain;
Expand All @@ -22,6 +23,7 @@
public class JwtRequestFilter extends OncePerRequestFilter {
private final TokenProvider tokenProvider;

private final String[] whiteList;
@Override
protected void doFilterInternal(
HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
Expand All @@ -39,4 +41,17 @@ protected void doFilterInternal(
}
filterChain.doFilter(httpServletRequest, response);
}

/**
* 필터를 무시할 대상 지정
* @param request current HTTP request
* @return 화이트 리스트 포함 여부
* @throws ServletException
*/

@Override
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
String path = request.getRequestURI();
return Arrays.stream(whiteList).anyMatch(path::startsWith);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import jakarta.servlet.http.HttpServletRequest;

import org.springframework.core.MethodParameter;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.support.WebDataBinderFactory;
Expand Down
5 changes: 4 additions & 1 deletion Briefing-Api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ fcm:
topic:
daily-push : dailyPush
---
logging:
level:
org.springframework.security.web.FilterChainProxy: DEBUG
spring:
config:
activate:
Expand Down Expand Up @@ -66,7 +69,7 @@ jwt:
# dev server
secret: ${JWT_SECRET}
authorities-key: authoritiesKey
access-token-validity-in-seconds: 1200000
access-token-validity-in-seconds: 3000
refresh-token-validity-in-seconds: 1210000000 # 14 d

openai:
Expand Down

0 comments on commit ed2135e

Please sign in to comment.