Skip to content
Merged
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 @@ -38,21 +38,11 @@ class JwtAuthenticationFilter(
val userId = jwtProvider.getUserIdFromAccessToken(token)
val auth = getAuthentication(userId.toString())
val context = SecurityContextImpl(auth)
return getAuthorizationToServer(userId)
.flatMap { status ->
if (status) {
val mutatedExchange = exchange.mutate()
.request(exchange.request.mutate().header("X-USER-ID", userId.toString()).build())
.build()
chain.filter(mutatedExchange)
.contextWrite(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(context)))
}
else {
val errorJson = ErrorCode.ACCESS_TOKEN_EXPIRED.toErrorResponse().toJsonBytes()
setErrorResponse(errorJson, exchange.response)
}
}

val mutatedExchange = exchange.mutate()
.request(exchange.request.mutate().header("X-USER-ID", userId.toString()).build())
.build()
chain.filter(mutatedExchange)
.contextWrite(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(context)))
} ?: run {//access 만료 or 잘못됨
jwtProvider.resolveRefreshToken(exchange.request)
?.takeIf { jwtProvider.validateRefreshToken(it) }
Expand All @@ -67,17 +57,6 @@ class JwtAuthenticationFilter(
}
}

private fun getAuthorizationToServer(userId: Long): Mono<Boolean> {
return webClient
.get()
.uri("/auth/exist/user")
.accept(MediaType.ALL)
.header("X-USER-ID", userId.toString())
.retrieve()
.bodyToMono(AuthResponse::class.java)
.map { it.existStatus }
}

private fun getAuthentication(userId: String):Authentication =
UsernamePasswordAuthenticationToken(userId, "", emptyList())

Expand Down