From f07425b3b6aeeb186f22689429e779b9e1def359 Mon Sep 17 00:00:00 2001 From: Daybreak312 Date: Thu, 22 Aug 2024 19:46:42 +0900 Subject: [PATCH 1/4] REFACT :: ktlintFormat --- .../infrastructure/collector/bean/ListableBeanCollector.kt | 2 +- .../authentication/checker/RequireAuthenticationChecker.kt | 1 - .../security/authentication/checker/RequireRoleChecker.kt | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/kotlin/com/info/maeumgagym/infrastructure/collector/bean/ListableBeanCollector.kt b/src/main/kotlin/com/info/maeumgagym/infrastructure/collector/bean/ListableBeanCollector.kt index d7e6eb31..ec119e89 100644 --- a/src/main/kotlin/com/info/maeumgagym/infrastructure/collector/bean/ListableBeanCollector.kt +++ b/src/main/kotlin/com/info/maeumgagym/infrastructure/collector/bean/ListableBeanCollector.kt @@ -12,5 +12,5 @@ interface ListableBeanCollector { fun getBeansOfType(type: KClass): List - fun getBeansMapOfType(type: KClass): Map + fun getBeansMapOfType(type: KClass): Map } diff --git a/src/main/kotlin/com/info/maeumgagym/security/authentication/checker/RequireAuthenticationChecker.kt b/src/main/kotlin/com/info/maeumgagym/security/authentication/checker/RequireAuthenticationChecker.kt index eaf02020..2dd0d59a 100644 --- a/src/main/kotlin/com/info/maeumgagym/security/authentication/checker/RequireAuthenticationChecker.kt +++ b/src/main/kotlin/com/info/maeumgagym/security/authentication/checker/RequireAuthenticationChecker.kt @@ -18,7 +18,6 @@ class RequireAuthenticationChecker( ) : WebAdapterMethodAnnotationProcessor { override fun preProcessing(annotations: List) { - annotations.forEach { annotation -> if (annotation !is RequireAuthentication) { return@forEach diff --git a/src/main/kotlin/com/info/maeumgagym/security/authentication/checker/RequireRoleChecker.kt b/src/main/kotlin/com/info/maeumgagym/security/authentication/checker/RequireRoleChecker.kt index bfcc22c3..7a87fbe5 100644 --- a/src/main/kotlin/com/info/maeumgagym/security/authentication/checker/RequireRoleChecker.kt +++ b/src/main/kotlin/com/info/maeumgagym/security/authentication/checker/RequireRoleChecker.kt @@ -20,7 +20,6 @@ class RequireRoleChecker( ) : WebAdapterMethodAnnotationProcessor { override fun preProcessing(annotations: List) { - annotations.forEach { annotation -> if (annotation !is RequireRole) { return@forEach From fde0af5d610af31f5712c24a3054fa0967a6ccaf Mon Sep 17 00:00:00 2001 From: Daybreak312 Date: Thu, 22 Aug 2024 20:19:12 +0900 Subject: [PATCH 2/4] =?UTF-8?q?FIX=20::=20Return=20=EB=88=84=EB=9D=BD;;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../collector/annotation/HandlerAnnotationCollector.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/info/maeumgagym/infrastructure/collector/annotation/HandlerAnnotationCollector.kt b/src/main/kotlin/com/info/maeumgagym/infrastructure/collector/annotation/HandlerAnnotationCollector.kt index 17526322..b48cc3d0 100644 --- a/src/main/kotlin/com/info/maeumgagym/infrastructure/collector/annotation/HandlerAnnotationCollector.kt +++ b/src/main/kotlin/com/info/maeumgagym/infrastructure/collector/annotation/HandlerAnnotationCollector.kt @@ -56,7 +56,7 @@ class HandlerAnnotationCollector : AnnotationCollector { } is MethodParameter -> { - `object`.parameterAnnotations.toList() + return `object`.parameterAnnotations.toList() } } From 3ee7a17f82826cb5cf01546a98acad0671a59d44 Mon Sep 17 00:00:00 2001 From: Daybreak312 Date: Thu, 22 Aug 2024 20:19:40 +0900 Subject: [PATCH 3/4] =?UTF-8?q?FEAT=20::=20=EC=96=B4=EB=85=B8=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EB=AA=A9=EB=A1=9D=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=9D=BC=20=EC=9D=B8=EC=A6=9D=EC=9D=84=20=EC=A7=84=ED=96=89?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=AA=A8=EB=93=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AnnotationBasedAuthenticationChecker.kt | 6 ++++++ .../AnnotationBasedAuthenticationCheckerImpl.kt | 15 +++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/main/kotlin/com/info/maeumgagym/security/authentication/checker/AnnotationBasedAuthenticationChecker.kt create mode 100644 src/main/kotlin/com/info/maeumgagym/security/authentication/checker/AnnotationBasedAuthenticationCheckerImpl.kt diff --git a/src/main/kotlin/com/info/maeumgagym/security/authentication/checker/AnnotationBasedAuthenticationChecker.kt b/src/main/kotlin/com/info/maeumgagym/security/authentication/checker/AnnotationBasedAuthenticationChecker.kt new file mode 100644 index 00000000..a5c39258 --- /dev/null +++ b/src/main/kotlin/com/info/maeumgagym/security/authentication/checker/AnnotationBasedAuthenticationChecker.kt @@ -0,0 +1,6 @@ +package com.info.maeumgagym.security.authentication.checker + +interface AnnotationBasedAuthenticationChecker { + + fun checkAuthentication(annotations: List) +} diff --git a/src/main/kotlin/com/info/maeumgagym/security/authentication/checker/AnnotationBasedAuthenticationCheckerImpl.kt b/src/main/kotlin/com/info/maeumgagym/security/authentication/checker/AnnotationBasedAuthenticationCheckerImpl.kt new file mode 100644 index 00000000..35a0d607 --- /dev/null +++ b/src/main/kotlin/com/info/maeumgagym/security/authentication/checker/AnnotationBasedAuthenticationCheckerImpl.kt @@ -0,0 +1,15 @@ +package com.info.maeumgagym.security.authentication.checker + +import org.springframework.stereotype.Component + +@Component +class AnnotationBasedAuthenticationCheckerImpl( + private val requireAuthenticationChecker: RequireAuthenticationChecker, + private val requireRoleChecker: RequireRoleChecker +) : AnnotationBasedAuthenticationChecker { + + override fun checkAuthentication(annotations: List) { + requireAuthenticationChecker.preProcessing(annotations) + requireRoleChecker.preProcessing(annotations) + } +} From fdaffa8999baae829395745962aa12660cb73d73 Mon Sep 17 00:00:00 2001 From: Daybreak312 Date: Thu, 22 Aug 2024 20:20:27 +0900 Subject: [PATCH 4/4] =?UTF-8?q?FEAT=20::=20=EC=9D=B8=EC=A6=9D=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=EC=9D=B4=20=EB=B6=80?= =?UTF-8?q?=EC=B0=A9=EB=90=9C=20User=20=ED=83=80=EC=9E=85=EC=9D=98=20Handl?= =?UTF-8?q?erMethodParameterResolver=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resolver/UserArgumentResolver.kt | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/kotlin/com/info/maeumgagym/security/authentication/resolver/UserArgumentResolver.kt diff --git a/src/main/kotlin/com/info/maeumgagym/security/authentication/resolver/UserArgumentResolver.kt b/src/main/kotlin/com/info/maeumgagym/security/authentication/resolver/UserArgumentResolver.kt new file mode 100644 index 00000000..1ff8bc87 --- /dev/null +++ b/src/main/kotlin/com/info/maeumgagym/security/authentication/resolver/UserArgumentResolver.kt @@ -0,0 +1,28 @@ +package com.info.maeumgagym.security.authentication.resolver + +import com.info.maeumgagym.core.auth.port.out.ReadCurrentUserPort +import com.info.maeumgagym.core.user.model.User +import com.info.maeumgagym.infrastructure.processor.annotation.WebAdapterMethodArgumentAnnotationProcessor +import com.info.maeumgagym.security.authentication.checker.AnnotationBasedAuthenticationChecker +import org.springframework.stereotype.Component + +@Component +class UserArgumentResolver( + private val annotationBasedAuthenticationChecker: AnnotationBasedAuthenticationChecker, + private val readCurrentUserPort: ReadCurrentUserPort +) : WebAdapterMethodArgumentAnnotationProcessor { + + override fun supports(type: Class, annotations: List): Boolean = + type == User::class.java + + override fun processing(type: Class, annotations: List): T { + + if (type != User::class.java) { + throw RuntimeException() + } + + annotationBasedAuthenticationChecker.checkAuthentication(annotations) + + return readCurrentUserPort.readCurrentUser() as T + } +}