Skip to content

Commit

Permalink
Merge branch 'apply-annotation-processer' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Daybreak312 committed Aug 22, 2024
2 parents 0dc7e60 + fdaffa8 commit 5b3e94b
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class HandlerAnnotationCollector : AnnotationCollector {
}

is MethodParameter -> {
`object`.parameterAnnotations.toList()
return `object`.parameterAnnotations.toList()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ interface ListableBeanCollector {

fun <T : Any> getBeansOfType(type: KClass<T>): List<T>

fun <T: Any> getBeansMapOfType(type: KClass<T>): Map<String, T>
fun <T : Any> getBeansMapOfType(type: KClass<T>): Map<String, T>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.info.maeumgagym.security.authentication.checker

interface AnnotationBasedAuthenticationChecker {

fun checkAuthentication(annotations: List<Annotation>)
}
Original file line number Diff line number Diff line change
@@ -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<Annotation>) {
requireAuthenticationChecker.preProcessing(annotations)
requireRoleChecker.preProcessing(annotations)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class RequireAuthenticationChecker(
) : WebAdapterMethodAnnotationProcessor {

override fun preProcessing(annotations: List<Annotation>) {

annotations.forEach { annotation ->
if (annotation !is RequireAuthentication) {
return@forEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class RequireRoleChecker(
) : WebAdapterMethodAnnotationProcessor {

override fun preProcessing(annotations: List<Annotation>) {

annotations.forEach { annotation ->
if (annotation !is RequireRole) {
return@forEach
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <T> supports(type: Class<T>, annotations: List<Annotation>): Boolean =
type == User::class.java

override fun <T> processing(type: Class<T>, annotations: List<Annotation>): T {

if (type != User::class.java) {
throw RuntimeException()
}

annotationBasedAuthenticationChecker.checkAuthentication(annotations)

return readCurrentUserPort.readCurrentUser() as T
}
}

0 comments on commit 5b3e94b

Please sign in to comment.