Skip to content

Commit

Permalink
fix: It Allows the Aspect Class to Return null (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
psychology50 authored Dec 31, 2024
1 parent 6cb496d commit 7303258
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import java.security.Principal
@Aspect
@Component
class PreAuthorizeAspect(private val applicationContext: ApplicationContext) {
private val log = logger()

/**
* {@link PreAuthorize} ์–ด๋…ธํ…Œ์ด์…˜์ด ๋ถ™์€ ๋ฉ”์„œ๋“œ๋ฅผ ๊ฐ€๋กœ์ฑ„๊ณ  ์ธ์ฆ/์ธ๊ฐ€๋ฅผ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.
*
Expand All @@ -27,14 +25,17 @@ class PreAuthorizeAspect(private val applicationContext: ApplicationContext) {
* @throws Throwable ๋ฉ”์„œ๋“œ ์‹คํ–‰ ์ค‘ ๋ฐœ์ƒํ•œ ์˜ˆ์™ธ
*/
@Around("@annotation(kr.co.pennyway.socket.common.annotation.PreAuthorize)")
fun execute(joinPoint: ProceedingJoinPoint): Any = with(joinPoint) {
(signature as? MethodSignature)
?.method
?.let { method -> validateAccess(method, this) }
fun execute(joinPoint: ProceedingJoinPoint): Any? {
val methodSignature = joinPoint.signature as? MethodSignature
?: throw IllegalStateException("PreAuthorize๋Š” ๋ฉ”์„œ๋“œ์—๋งŒ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค")

val method = methodSignature.method
validateAccess(method, joinPoint)

return joinPoint.proceed()
}

private fun validateAccess(method: Method, joinPoint: ProceedingJoinPoint): Any {
private fun validateAccess(method: Method, joinPoint: ProceedingJoinPoint) {
val preAuthorize = method.requireAnnotation<PreAuthorize>()
val principal = joinPoint.args.findPrincipal()

Expand All @@ -44,8 +45,6 @@ class PreAuthorizeAspect(private val applicationContext: ApplicationContext) {
method = method,
args = joinPoint.args
)

return joinPoint.proceed()
}

private fun evaluateAccess(
Expand Down Expand Up @@ -86,5 +85,7 @@ class PreAuthorizeAspect(private val applicationContext: ApplicationContext) {
fun Array<Any>.findPrincipal(): Principal? = asSequence()
.filterIsInstance<Principal>()
.firstOrNull()

val log = logger()
}
}

0 comments on commit 7303258

Please sign in to comment.