generated from pricelees/issue-pr-template
[#44] 매장 기능 도입 #45
@ -11,7 +11,6 @@ import roomescape.auth.infrastructure.jwt.JwtUtils
|
|||||||
import roomescape.auth.web.LoginContext
|
import roomescape.auth.web.LoginContext
|
||||||
import roomescape.auth.web.LoginRequest
|
import roomescape.auth.web.LoginRequest
|
||||||
import roomescape.auth.web.LoginSuccessResponse
|
import roomescape.auth.web.LoginSuccessResponse
|
||||||
import roomescape.common.dto.CurrentUserContext
|
|
||||||
import roomescape.common.dto.LoginCredentials
|
import roomescape.common.dto.LoginCredentials
|
||||||
import roomescape.common.dto.PrincipalType
|
import roomescape.common.dto.PrincipalType
|
||||||
import roomescape.user.business.UserService
|
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(
|
private fun verifyPasswordOrThrow(
|
||||||
request: LoginRequest,
|
request: LoginRequest,
|
||||||
credentials: LoginCredentials
|
credentials: LoginCredentials
|
||||||
|
|||||||
@ -12,10 +12,6 @@ annotation class AdminOnly(
|
|||||||
@Retention(AnnotationRetention.RUNTIME)
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
annotation class UserOnly
|
annotation class UserOnly
|
||||||
|
|
||||||
@Target(AnnotationTarget.FUNCTION)
|
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
|
||||||
annotation class Authenticated
|
|
||||||
|
|
||||||
@Target(AnnotationTarget.FUNCTION)
|
@Target(AnnotationTarget.FUNCTION)
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
annotation class Public
|
annotation class Public
|
||||||
|
|||||||
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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.InterceptorRegistry
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
|
||||||
import roomescape.auth.web.support.interceptors.AdminInterceptor
|
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.interceptors.UserInterceptor
|
||||||
import roomescape.auth.web.support.resolver.UserContextResolver
|
import roomescape.auth.web.support.resolver.UserContextResolver
|
||||||
|
|
||||||
@ -13,7 +12,6 @@ import roomescape.auth.web.support.resolver.UserContextResolver
|
|||||||
class WebMvcConfig(
|
class WebMvcConfig(
|
||||||
private val adminInterceptor: AdminInterceptor,
|
private val adminInterceptor: AdminInterceptor,
|
||||||
private val userInterceptor: UserInterceptor,
|
private val userInterceptor: UserInterceptor,
|
||||||
private val authenticatedInterceptor: AuthenticatedInterceptor,
|
|
||||||
private val userContextResolver: UserContextResolver
|
private val userContextResolver: UserContextResolver
|
||||||
) : WebMvcConfigurer {
|
) : WebMvcConfigurer {
|
||||||
|
|
||||||
@ -24,6 +22,5 @@ class WebMvcConfig(
|
|||||||
override fun addInterceptors(registry: InterceptorRegistry) {
|
override fun addInterceptors(registry: InterceptorRegistry) {
|
||||||
registry.addInterceptor(adminInterceptor)
|
registry.addInterceptor(adminInterceptor)
|
||||||
registry.addInterceptor(userInterceptor)
|
registry.addInterceptor(userInterceptor)
|
||||||
registry.addInterceptor(authenticatedInterceptor)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,9 +8,8 @@ import org.springframework.http.ResponseEntity
|
|||||||
import org.springframework.web.bind.annotation.PathVariable
|
import org.springframework.web.bind.annotation.PathVariable
|
||||||
import org.springframework.web.bind.annotation.RequestBody
|
import org.springframework.web.bind.annotation.RequestBody
|
||||||
import org.springframework.web.bind.annotation.RequestParam
|
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.Public
|
||||||
|
import roomescape.auth.web.support.User
|
||||||
import roomescape.auth.web.support.UserOnly
|
import roomescape.auth.web.support.UserOnly
|
||||||
import roomescape.common.dto.CurrentUserContext
|
import roomescape.common.dto.CurrentUserContext
|
||||||
import roomescape.common.dto.response.CommonApiResponse
|
import roomescape.common.dto.response.CommonApiResponse
|
||||||
@ -40,7 +39,6 @@ interface ReservationAPI {
|
|||||||
@PathVariable("id") id: Long
|
@PathVariable("id") id: Long
|
||||||
): ResponseEntity<CommonApiResponse<Unit>>
|
): ResponseEntity<CommonApiResponse<Unit>>
|
||||||
|
|
||||||
@Authenticated
|
|
||||||
@Operation(summary = "예약 취소", tags = ["로그인이 필요한 API"])
|
@Operation(summary = "예약 취소", tags = ["로그인이 필요한 API"])
|
||||||
@ApiResponses(ApiResponse(responseCode = "200", description = "성공", useReturnTypeSchema = true))
|
@ApiResponses(ApiResponse(responseCode = "200", description = "성공", useReturnTypeSchema = true))
|
||||||
fun cancelReservation(
|
fun cancelReservation(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user