From a089ab7a0474647eff1bd98c14af44e32be713e3 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:52:38 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E5=8C=BF=E5=90=8D=E8=AA=8D?= =?UTF-8?q?=E8=A8=BC=E6=99=82=E3=81=AB=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=E3=82=92=E5=8F=96=E5=BE=97?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=81=AA=E3=81=84=E5=A0=B4=E5=90=88=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E3=81=A7=E3=81=AF=E3=81=AA=E3=81=8Fnull?= =?UTF-8?q?=E3=82=92=E8=BF=94=E3=81=99=E9=96=A2=E6=95=B0=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springframework/security/LoginUserContextHolder.kt | 2 ++ .../security/OAuth2JwtLoginUserContextHolder.kt | 9 +++++++++ 2 files changed, 11 insertions(+) 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 index e86dc2b0..1090757e 100644 --- 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 @@ -2,4 +2,6 @@ package dev.usbharu.hideout.core.infrastructure.springframework.security interface LoginUserContextHolder { fun getLoginUserId(): Long + + fun getLoginUserIdOrNull(): 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 index 0369fda6..2c77a9f9 100644 --- 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 @@ -11,4 +11,13 @@ class OAuth2JwtLoginUserContextHolder : LoginUserContextHolder { return principal.getClaim("uid").toLong() } + + override fun getLoginUserIdOrNull(): Long? { + val principal = SecurityContextHolder.getContext()?.authentication?.principal + if (principal !is Jwt) { + return null + } + + return principal.getClaim("uid").toLongOrNull() + } } From a062d0b9c3d380f706983f46a768affa92594219 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:53:18 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E3=82=A2=E3=82=AB=E3=82=A6=E3=83=B3?= =?UTF-8?q?=E3=83=88=E3=81=AE=E6=8A=95=E7=A8=BF=E4=B8=80=E8=A6=A7=E3=81=8C?= =?UTF-8?q?=E6=9C=AA=E3=83=AD=E3=82=B0=E3=82=A4=E3=83=B3=E6=99=82=E3=81=AB?= =?UTF-8?q?=E8=A6=8B=E3=82=8C=E3=81=AA=E3=81=8F=E3=81=AA=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=9F=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interfaces/api/account/MastodonAccountApiController.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/account/MastodonAccountApiController.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/account/MastodonAccountApiController.kt index 650199ad..f577f48d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/account/MastodonAccountApiController.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/account/MastodonAccountApiController.kt @@ -71,7 +71,7 @@ class MastodonAccountApiController( pinned: Boolean, tagged: String? ): ResponseEntity> = runBlocking { - val userid = loginUserContextHolder.getLoginUserId() + val userid = loginUserContextHolder.getLoginUserIdOrNull() val statuses = accountApiService.accountsStatuses( userid = id.toLong(), onlyMedia = onlyMedia, From 9b0d37722cb5140919f07107ba0eb8a9623e8edb Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:54:10 +0900 Subject: [PATCH 3/3] =?UTF-8?q?test:=20=E5=8C=BF=E5=90=8D=E8=AA=8D?= =?UTF-8?q?=E8=A8=BC=E6=99=82=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/mastodon/account/AccountApiTest.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/intTest/kotlin/mastodon/account/AccountApiTest.kt b/src/intTest/kotlin/mastodon/account/AccountApiTest.kt index 666d3d57..189d5834 100644 --- a/src/intTest/kotlin/mastodon/account/AccountApiTest.kt +++ b/src/intTest/kotlin/mastodon/account/AccountApiTest.kt @@ -424,6 +424,23 @@ class AccountApiTest { .andExpect { status { isUnauthorized() } } } + @Test + fun `apiV1AccountsIdStatusesGet read権限で取得できる`() { + mockMvc + .get("/api/v1/accounts/1/statuses") + .asyncDispatch() + .andExpect { status { isOk() } } + } + + @Test + @WithAnonymousUser + fun `apiV1AccountsIdStatusesGet 匿名でもpublic投稿を取得できる`() { + mockMvc + .get("/api/v1/accounts/1/statuses") + .asyncDispatch() + .andExpect { status { isOk() } } + } + companion object { @JvmStatic @AfterAll