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
fix: allow pre-authorize-aspect execute method return null
psychology50 committed Dec 31, 2024

Verified

This commit was created on GitHub.com and signed with GitHubโ€™s verified signature. The key has expired.
commit ee33ec44576f63092ce5c2894e9dc552335f62ce
Original file line number Diff line number Diff line change
@@ -17,8 +17,6 @@ import java.security.Principal
@Aspect
@Component
class PreAuthorizeAspect(private val applicationContext: ApplicationContext) {
private val log = logger()

/**
* {@link PreAuthorize} ์–ด๋…ธํ…Œ์ด์…˜์ด ๋ถ™์€ ๋ฉ”์„œ๋“œ๋ฅผ ๊ฐ€๋กœ์ฑ„๊ณ  ์ธ์ฆ/์ธ๊ฐ€๋ฅผ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.
*
@@ -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()

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

return joinPoint.proceed()
}

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

val log = logger()
}
}