From e2365c632b1a32b0e0ba6f25eb5381568daa7d65 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Fri, 26 Jan 2024 12:06:34 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=AD=E3=82=B0=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC=E5=8F=96=E5=BE=97=E9=83=A8?= =?UTF-8?q?=E5=88=86=E3=82=92=E5=85=B1=E9=80=9A=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/LoginUserContextHolder.kt | 5 +++++ .../security/OAuth2JwtLoginUserContextHolder.kt | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/security/LoginUserContextHolder.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/security/OAuth2JwtLoginUserContextHolder.kt diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/security/LoginUserContextHolder.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/security/LoginUserContextHolder.kt new file mode 100644 index 00000000..e86dc2b0 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/security/LoginUserContextHolder.kt @@ -0,0 +1,5 @@ +package dev.usbharu.hideout.core.infrastructure.springframework.security + +interface LoginUserContextHolder { + fun getLoginUserId(): Long +} diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/security/OAuth2JwtLoginUserContextHolder.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/security/OAuth2JwtLoginUserContextHolder.kt new file mode 100644 index 00000000..0369fda6 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/springframework/security/OAuth2JwtLoginUserContextHolder.kt @@ -0,0 +1,14 @@ +package dev.usbharu.hideout.core.infrastructure.springframework.security + +import org.springframework.security.core.context.SecurityContextHolder +import org.springframework.security.oauth2.jwt.Jwt +import org.springframework.stereotype.Component + +@Component +class OAuth2JwtLoginUserContextHolder : LoginUserContextHolder { + override fun getLoginUserId(): Long { + val principal = SecurityContextHolder.getContext().getAuthentication().principal as Jwt + + return principal.getClaim("uid").toLong() + } +}