Skip to content

Commit 4a75a9c

Browse files
authored
๐Ÿ› Bug - Token์ด ์žˆ๋Š” ๊ฒฝ์šฐ์— Authentication ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š๋Š” ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•œ๋‹ค
๐Ÿ› Bug - Token์ด ์žˆ๋Š” ๊ฒฝ์šฐ์— Authentication ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š๋Š” ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•œ๋‹ค
2 parents a8bf37b + dae5701 commit 4a75a9c

5 files changed

Lines changed: 33 additions & 13 deletions

File tree

โ€Žsrc/main/java/sopt/comfit/company/controller/CompanyController.javaโ€Ž

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package sopt.comfit.company.controller;
22

3-
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
43
import lombok.RequiredArgsConstructor;
54
import org.springframework.data.domain.PageRequest;
65
import org.springframework.data.domain.Pageable;
7-
import org.springframework.web.bind.annotation.*;
8-
9-
import java.util.List;
10-
6+
import org.springframework.web.bind.annotation.PathVariable;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RequestParam;
9+
import org.springframework.web.bind.annotation.RestController;
1110
import sopt.comfit.company.domain.EScale;
1211
import sopt.comfit.company.dto.response.*;
1312
import sopt.comfit.company.service.CompanyService;
@@ -16,6 +15,7 @@
1615
import sopt.comfit.global.enums.EIndustry;
1716
import sopt.comfit.global.enums.ESort;
1817

18+
import java.util.List;
1919
@RestController
2020
@RequestMapping("/api/v1/companies")
2121
@RequiredArgsConstructor

โ€Žsrc/main/java/sopt/comfit/global/config/WebConfig.javaโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers)
2929
public void addInterceptors(InterceptorRegistry registry) {
3030
registry.addInterceptor(new UserInterceptor())
3131
.addPathPatterns("/**")
32-
.excludePathPatterns(Constants.NO_NEED_AUTH);
32+
.excludePathPatterns(Constants.NO_NEED_AUTH_INTERCEPTOR);
3333
}
3434
}

โ€Žsrc/main/java/sopt/comfit/global/constants/Constants.javaโ€Ž

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,21 @@ public class Constants {
3030
"/.well-known/**",
3131
"/api/v1/companies/**"
3232
);
33+
34+
public static List<String> NO_NEED_AUTH_INTERCEPTOR = List.of(
35+
"/swagger",
36+
"/swagger-ui.html",
37+
"/swagger-ui/**",
38+
"/api-docs",
39+
"/api-docs/**",
40+
"/v3/api-docs/**",
41+
"/api/health",
42+
"/api/health-check",
43+
"/api/v1/login",
44+
"/api/v1/re-issued",
45+
"/actuator/**",
46+
"/api/v1/oauth/kakao/callback",
47+
"/favicon.ico",
48+
"/.well-known/**"
49+
);
3350
}

โ€Žsrc/main/java/sopt/comfit/global/interceptor/pre/UserInterceptor.javaโ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class UserInterceptor implements HandlerInterceptor {
1212
@Override
1313
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
1414
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
15+
log.info("authentication:{}",authentication.getName());
1516
request.setAttribute("USER_ID", Long.valueOf(authentication.getName()));
1617
return HandlerInterceptor.super.preHandle(request, response, handler);
1718
}

โ€Žsrc/main/java/sopt/comfit/global/security/filter/JwtAuthenticationFilter.javaโ€Ž

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
3333
protected void doFilterInternal(HttpServletRequest request,
3434
HttpServletResponse response,
3535
FilterChain filterChain) throws ServletException, IOException {
36-
log.info(request.getHeader(Constants.PREFIX_AUTH));
36+
37+
38+
String header = request.getHeader(Constants.PREFIX_AUTH);
39+
log.info("header:{}",header);
40+
41+
if (header == null || !header.startsWith("Bearer ")) {
42+
filterChain.doFilter(request, response);
43+
return;
44+
}
3745
String token = HeaderUtil.refineHeader(request, Constants.PREFIX_AUTH, Constants.BEARER);
3846
Claims claim = jwtUtil.validateToken(token);
3947
log.info("claim: getUserId() = {}", claim.get(Constants.CLAIM_USER_ID, Long.class));
@@ -54,10 +62,4 @@ protected void doFilterInternal(HttpServletRequest request,
5462
filterChain.doFilter(request, response);
5563
}
5664

57-
@Override
58-
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
59-
return Constants.NO_NEED_AUTH.stream()
60-
.anyMatch(patter -> Constants.PATH_MATCHER.match(patter, request.getRequestURI()));
61-
62-
}
6365
}

0 commit comments

Comments
ย (0)