Skip to content

Commit

Permalink
HOTFIX :: JwtFilter에서 Authentication Header가 필수가 아니도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Daybreak312 committed Mar 20, 2024
1 parent 3abc1be commit 079d7c0
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.info.maeumgagym.security.jwt

import com.info.maeumgagym.common.exception.AuthenticationException
import com.info.maeumgagym.security.config.RequestPermitConfig
import com.info.maeumgagym.security.jwt.env.JwtProperties
import org.springframework.security.core.context.SecurityContextHolder
Expand Down Expand Up @@ -32,19 +31,20 @@ class JwtFilter(
response: HttpServletResponse,
filterChain: FilterChain
) {
// 헤더에 토큰이 존재하는지 확인, 아닐 경우 Exception 반환
// 헤더에 토큰이 존재하는지 확인
val header = request.getHeader(jwtProperties.header)
?: throw AuthenticationException.UNAUTHORIZED

// 토큰이 유효한지 확인, 유효하다면 ->
jwtResolver(header)?.let {
// security context holder에 Authentication 저장
SecurityContextHolder.getContext().authentication =
if (needRole(request)) { // Role 인증이 필요하다면 User Eager Loading
authenticationProvider.getAuthentication(it)
} else { // 필요하지 않다면 User Lazy Loading
authenticationProvider.getEmptyAuthentication(it)
}
if (header != null) {
// 토큰이 유효한지 확인, 유효하다면 ->
jwtResolver(header)?.let {
// security context holder에 Authentication 저장
SecurityContextHolder.getContext().authentication =
if (needRole(request)) { // Role 인증이 필요하다면 User Eager Loading
authenticationProvider.getAuthentication(it)
} else { // 필요하지 않다면 User Lazy Loading
authenticationProvider.getEmptyAuthentication(it)
}
}
}

// 다음 필터로 넘기기
Expand Down

0 comments on commit 079d7c0

Please sign in to comment.