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(