Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket: ๐Ÿ› It Allows the Aspect Class to Return null #213

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}
Loading