From c6dd8a977c949661123dc192701533a1769a3e67 Mon Sep 17 00:00:00 2001 From: pricelees Date: Sun, 14 Sep 2025 21:27:53 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EA=B4=80=EB=A6=AC=EC=9E=90=20/=20?= =?UTF-8?q?=ED=9A=8C=EC=9B=90=20=EB=B6=84=EB=A6=AC=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=EA=B3=B5=ED=86=B5=20API=EC=97=90=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9=EB=90=98=EB=8A=94=20Authenticated=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EB=B0=8F=20=EC=9D=B8?= =?UTF-8?q?=ED=84=B0=EC=85=89=ED=84=B0=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../roomescape/auth/business/AuthService.kt | 18 -------- .../auth/web/support/AuthAnnotations.kt | 4 -- .../interceptors/AuthenticatedInterceptor.kt | 44 ------------------- .../roomescape/common/config/WebMvcConfig.kt | 3 -- .../reservation/docs/ReservationAPI.kt | 4 +- 5 files changed, 1 insertion(+), 72 deletions(-) delete mode 100644 src/main/kotlin/roomescape/auth/web/support/interceptors/AuthenticatedInterceptor.kt diff --git a/src/main/kotlin/roomescape/auth/business/AuthService.kt b/src/main/kotlin/roomescape/auth/business/AuthService.kt index 96a1fb93..5366af04 100644 --- a/src/main/kotlin/roomescape/auth/business/AuthService.kt +++ b/src/main/kotlin/roomescape/auth/business/AuthService.kt @@ -11,7 +11,6 @@ import roomescape.auth.infrastructure.jwt.JwtUtils import roomescape.auth.web.LoginContext import roomescape.auth.web.LoginRequest import roomescape.auth.web.LoginSuccessResponse -import roomescape.common.dto.CurrentUserContext import roomescape.common.dto.LoginCredentials import roomescape.common.dto.PrincipalType import roomescape.user.business.UserService @@ -65,23 +64,6 @@ class AuthService( } } - @Transactional(readOnly = true) - fun findContextById(id: Long, type: PrincipalType): CurrentUserContext { - log.info { "[AuthService.checkLogin] 로그인 확인 시작: id=${id}, type=${type}" } - - return when (type) { - PrincipalType.ADMIN -> { - adminService.findContextById(id) - } - - PrincipalType.USER -> { - userService.findContextById(id) - } - }.also { - log.info { "[AuthService.checkLogin] 로그인 확인 완료: id=${id}, type=${type}" } - } - } - private fun verifyPasswordOrThrow( request: LoginRequest, credentials: LoginCredentials diff --git a/src/main/kotlin/roomescape/auth/web/support/AuthAnnotations.kt b/src/main/kotlin/roomescape/auth/web/support/AuthAnnotations.kt index bc3ac597..003e4261 100644 --- a/src/main/kotlin/roomescape/auth/web/support/AuthAnnotations.kt +++ b/src/main/kotlin/roomescape/auth/web/support/AuthAnnotations.kt @@ -12,10 +12,6 @@ annotation class AdminOnly( @Retention(AnnotationRetention.RUNTIME) annotation class UserOnly -@Target(AnnotationTarget.FUNCTION) -@Retention(AnnotationRetention.RUNTIME) -annotation class Authenticated - @Target(AnnotationTarget.FUNCTION) @Retention(AnnotationRetention.RUNTIME) annotation class Public diff --git a/src/main/kotlin/roomescape/auth/web/support/interceptors/AuthenticatedInterceptor.kt b/src/main/kotlin/roomescape/auth/web/support/interceptors/AuthenticatedInterceptor.kt deleted file mode 100644 index f69629bc..00000000 --- a/src/main/kotlin/roomescape/auth/web/support/interceptors/AuthenticatedInterceptor.kt +++ /dev/null @@ -1,44 +0,0 @@ -package roomescape.auth.web.support.interceptors - -import io.github.oshai.kotlinlogging.KLogger -import io.github.oshai.kotlinlogging.KotlinLogging -import jakarta.servlet.http.HttpServletRequest -import jakarta.servlet.http.HttpServletResponse -import org.springframework.stereotype.Component -import org.springframework.web.method.HandlerMethod -import org.springframework.web.servlet.HandlerInterceptor -import roomescape.auth.business.AuthService -import roomescape.auth.infrastructure.jwt.JwtUtils -import roomescape.auth.web.support.Authenticated -import roomescape.auth.web.support.accessToken - -private val log: KLogger = KotlinLogging.logger {} - -@Component -class AuthenticatedInterceptor( - private val jwtUtils: JwtUtils, - private val authService: AuthService -) : HandlerInterceptor { - - override fun preHandle( - request: HttpServletRequest, - response: HttpServletResponse, - handler: Any - ): Boolean { - if ((handler !is HandlerMethod) || (handler.getMethodAnnotation(Authenticated::class.java) == null)) { - return true - } - - val token: String? = request.accessToken() - val (id, type) = jwtUtils.extractIdAndType(token) - - try { - authService.findContextById(id, type) - log.info { "[AuthenticatedInterceptor] 인증 완료. id=$id, type=${type}" } - - return true - } catch (e: Exception) { - throw e - } - } -} diff --git a/src/main/kotlin/roomescape/common/config/WebMvcConfig.kt b/src/main/kotlin/roomescape/common/config/WebMvcConfig.kt index df4e8398..3fe6bec6 100644 --- a/src/main/kotlin/roomescape/common/config/WebMvcConfig.kt +++ b/src/main/kotlin/roomescape/common/config/WebMvcConfig.kt @@ -5,7 +5,6 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver import org.springframework.web.servlet.config.annotation.InterceptorRegistry import org.springframework.web.servlet.config.annotation.WebMvcConfigurer import roomescape.auth.web.support.interceptors.AdminInterceptor -import roomescape.auth.web.support.interceptors.AuthenticatedInterceptor import roomescape.auth.web.support.interceptors.UserInterceptor import roomescape.auth.web.support.resolver.UserContextResolver @@ -13,7 +12,6 @@ import roomescape.auth.web.support.resolver.UserContextResolver class WebMvcConfig( private val adminInterceptor: AdminInterceptor, private val userInterceptor: UserInterceptor, - private val authenticatedInterceptor: AuthenticatedInterceptor, private val userContextResolver: UserContextResolver ) : WebMvcConfigurer { @@ -24,6 +22,5 @@ class WebMvcConfig( override fun addInterceptors(registry: InterceptorRegistry) { registry.addInterceptor(adminInterceptor) registry.addInterceptor(userInterceptor) - registry.addInterceptor(authenticatedInterceptor) } } diff --git a/src/main/kotlin/roomescape/reservation/docs/ReservationAPI.kt b/src/main/kotlin/roomescape/reservation/docs/ReservationAPI.kt index ef3e9535..66a8589f 100644 --- a/src/main/kotlin/roomescape/reservation/docs/ReservationAPI.kt +++ b/src/main/kotlin/roomescape/reservation/docs/ReservationAPI.kt @@ -8,9 +8,8 @@ import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestParam -import roomescape.auth.web.support.Authenticated -import roomescape.auth.web.support.User import roomescape.auth.web.support.Public +import roomescape.auth.web.support.User import roomescape.auth.web.support.UserOnly import roomescape.common.dto.CurrentUserContext import roomescape.common.dto.response.CommonApiResponse @@ -40,7 +39,6 @@ interface ReservationAPI { @PathVariable("id") id: Long ): ResponseEntity> - @Authenticated @Operation(summary = "예약 취소", tags = ["로그인이 필요한 API"]) @ApiResponses(ApiResponse(responseCode = "200", description = "성공", useReturnTypeSchema = true)) fun cancelReservation(