Skip to content

Commit 80ea8f1

Browse files
authored
Merge pull request #283 from 7-umc-GrowIT/feat/#254
[#254] Feat : 인증 필터 기능 수정
2 parents b444f9b + 231f8d6 commit 80ea8f1

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/main/java/umc/GrowIT/Server/filter/JwtAuthenticationFilter.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.io.IOException;
1717
import io.jsonwebtoken.SignatureException;
1818
import umc.GrowIT.Server.apiPayload.exception.JwtAuthenticationException;
19+
import umc.GrowIT.Server.repository.UserRepository;
1920
import umc.GrowIT.Server.util.JwtTokenUtil;
2021

2122
import static umc.GrowIT.Server.apiPayload.code.status.ErrorStatus.*;
@@ -25,6 +26,7 @@
2526
public class JwtAuthenticationFilter extends OncePerRequestFilter {
2627

2728
private final JwtTokenUtil jwtTokenUtil;
29+
private final UserRepository userRepository;
2830

2931
@Override
3032
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
@@ -39,8 +41,13 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
3941
}
4042

4143
// 토큰에서 사용자 정보 읽어서 탈퇴한 회원인지 확인
42-
if (jwtTokenUtil.isUserInactive(token))
43-
throw new JwtAuthenticationException(USER_STATUS_INACTIVE);
44+
// if (jwtTokenUtil.isUserInactive(token))
45+
// throw new JwtAuthenticationException(USER_STATUS_INACTIVE);
46+
47+
// 사용자 정보 확인
48+
Long userId = jwtTokenUtil.getUserId(token);
49+
userRepository.findById(userId)
50+
.orElseThrow(() -> new JwtAuthenticationException(USER_NOT_FOUND));
4451

4552
//토큰이 유효한지 확인
4653
if (jwtTokenUtil.validateToken(token)) {

src/main/java/umc/GrowIT/Server/util/JwtTokenUtil.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,14 @@ public Authentication getAuthentication(String token) {
115115
);
116116
}
117117

118-
public boolean isUserInactive(String token){
118+
public boolean isUserInactive(String token) {
119119
Claims claims = parseClaims(token);
120120
Long userId = claims.get("userId", Long.class);
121121
return userQueryService.isUserInactive(userId);
122122
}
123+
124+
public Long getUserId(String token) {
125+
Claims claims = parseClaims(token);
126+
return claims.get("userId", Long.class);
127+
}
123128
}

0 commit comments

Comments
 (0)