Skip to content

Commit

Permalink
🐛fix : 사용자 인증로직 변경
Browse files Browse the repository at this point in the history
 - 사용자 등록시 사용자 인증로직 제외처리
  • Loading branch information
ParkYunHo committed Aug 23, 2023
1 parent 816938d commit c8cbf73
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,6 @@ class KakaoAuthAdapter(

val userId = CipherUtils.encode(str = "${CommCode.Social.KAKAO.code}:${claims.subject}")

// 회원정보 등록여부 체크
val existsMember = memberRepository.findMember(userId = userId)
if(existsMember == null) {
return Mono.error(UnAuthorizedException("등록된 회원이 아닙니다 - userId: $userId"))
}

return Mono.just(userId)
} catch (uae: UnAuthorizedException) {
return Mono.error(uae)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package com.john.lotto.common.filter

import com.john.lotto.auth.application.port.out.AuthPort
import com.john.lotto.common.exception.UnAuthorizedException
import com.john.lotto.member.MemberRepository
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpMethod
import org.springframework.stereotype.Component
import org.springframework.web.reactive.function.server.ServerRequest
import org.springframework.web.server.ServerWebExchange
Expand All @@ -23,6 +25,7 @@ private const val USER_ID_ATTRIBUTE = "userId"
@Component
class AuthorizationFilter(
private val authPort: AuthPort,
private val memberRepository: MemberRepository
): WebFilter {
private val log = LoggerFactory.getLogger(this::class.java)

Expand All @@ -41,7 +44,7 @@ class AuthorizationFilter(
val authorization = exchange.request.headers.getFirst(HttpHeaders.AUTHORIZATION)
?: throw UnAuthorizedException("Authorization 헤더가 존재하지 않습니다.")

// 개발자테스트인 경우 인증제외처리
// 개발용 토큰인 경우 인증제외처리
if(DEV_PREFIX in authorization) {
exchange.attributes[USER_ID_ATTRIBUTE] = "TEST_USER_ID"
return chain.filter(exchange)
Expand All @@ -54,6 +57,19 @@ class AuthorizationFilter(
return authPort.keys()
.flatMap { jwtInfo ->
authPort.validate(idToken, jwtInfo)
.flatMap {
// 사용자등록 API의 경우 회원체크로직 제외
if(path == "/api/member" && exchange.request.method.matches(HttpMethod.POST.name())) {
return@flatMap Mono.just(it)
}

// 회원정보 등록여부 체크
val existsMember = memberRepository.findMember(userId = it)
if(existsMember == null) {
return@flatMap Mono.error(UnAuthorizedException("등록된 회원이 아닙니다 - userId: $it"))
}
return@flatMap Mono.just(it)
}
.flatMap {
exchange.attributes[USER_ID_ATTRIBUTE] = it
chain.filter(exchange)
Expand Down

0 comments on commit c8cbf73

Please sign in to comment.