Skip to content

Commit

Permalink
Merge branch 'authentication-checkerr-refactor' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Daybreak312 committed Jun 20, 2024
2 parents 0e72e0e + 024989e commit fd47ad5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.info.maeumgagym.security.access.checker
import com.info.maeumgagym.common.exception.AuthenticationException
import org.springframework.security.authentication.AnonymousAuthenticationToken
import org.springframework.security.core.context.SecurityContextHolder
import kotlin.reflect.KClass

/**
* [AnnotationBasedUserAuthenticationChecker]의 구현체에서 사용되는 일부 중복 코드에 대해 추출된 함수 집합의 추상화
Expand All @@ -13,15 +12,8 @@ import kotlin.reflect.KClass
* @author Daybreak312
* @since 20-04-2024
*/
abstract class AbstractAnnotationBasedUserAuthenticationChecker : AnnotationBasedUserAuthenticationChecker {

protected fun <A : Annotation> Any.getAnnotationOrNull(annotation: KClass<A>): A? {
this::class.annotations.forEach {
if (it.annotationClass == annotation) return it as A
}

return null
}
abstract class AbstractAnnotationBasedUserAuthenticationChecker
: AnnotationBasedUserAuthenticationChecker {

protected fun checkInvalidAuthentication() {
if (SecurityContextHolder.getContext().authentication == null ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ class RequireRoleChecker(

checkInvalidAuthentication()

readCurrentUserPort.readCurrentUser().roles.forEach {
if (it == annotation.role) return
if (!readCurrentUserPort.readCurrentUser().roles.contains(annotation.role)) {
throw AuthenticationException.ROLE_REQUIRED
}

throw AuthenticationException.ROLE_REQUIRED
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UserModelAuthenticationFactoryImpl(
UserModelAuthentication(
userSubject = username,
user = readUserPort.readByOAuthId(username)
?: throw CriticalException("Cannot Find User By username : $username")
?: throw CriticalException("Cannot Find User By username : $username, user was deleted but token did not revoked.")
)

override fun createEmptyAuthentication(username: String): UserModelAuthentication =
Expand Down

0 comments on commit fd47ad5

Please sign in to comment.