Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ› Fix : jwt 인증 흐름 μˆ˜μ • #191

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading