mirror of https://github.com/usbharu/Hideout.git
feat: ログインユーザー取得部分を共通化
This commit is contained in:
parent
a60b58daef
commit
e2365c632b
|
@ -0,0 +1,5 @@
|
|||
package dev.usbharu.hideout.core.infrastructure.springframework.security
|
||||
|
||||
interface LoginUserContextHolder {
|
||||
fun getLoginUserId(): Long
|
||||
}
|
|
@ -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<String>("uid").toLong()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue