Skip to content

Commit

Permalink
feat(JwtAuthenticationFilter) : 토큰이 없어도 일단 넘기고, Security에 의해 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
Due-IT committed Dec 9, 2024
1 parent cdcd190 commit 0abbc7e
Showing 1 changed file with 3 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,13 @@ class JwtAuthenticationFilter(
response: HttpServletResponse,
filterChain: FilterChain
) {
val path = request.requestURI
if (path.startsWith("/swagger-ui/") || path.startsWith("/v3") || path.startsWith("/auth")) {
filterChain.doFilter(request, response)
return
}

try {
parseBearerToken(request, HttpHeaders.AUTHORIZATION)?.let { accessToken ->
jwtTokenProvider.validateAndParseToken(accessToken)

val user = parseUserSpecification(accessToken)
val authentication = UsernamePasswordAuthenticationToken.authenticated(user, accessToken, user.authorities)
val authentication =
UsernamePasswordAuthenticationToken.authenticated(user, accessToken, user.authorities)
authentication.details = WebAuthenticationDetails(request)
SecurityContextHolder.getContext().authentication = authentication
}
Expand All @@ -45,9 +40,7 @@ class JwtAuthenticationFilter(
return // 새 토큰 발급 후 요청 종료
}
} catch (e: Exception) {
response.status = HttpServletResponse.SC_UNAUTHORIZED
response.writer.write("Invalid Token")
return
logger.info("No Token")
}

filterChain.doFilter(request, response)
Expand Down

0 comments on commit 0abbc7e

Please sign in to comment.