Skip to content

Commit

Permalink
chore :: 수정본 복구
Browse files Browse the repository at this point in the history
  • Loading branch information
4mjeo committed Feb 28, 2024
1 parent 85a23fd commit a9ce680
Showing 1 changed file with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrinci
import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication
import org.springframework.stereotype.Component
import org.springframework.web.filter.OncePerRequestFilter
import java.util.*

@Component
@Order(-100)
Expand Down Expand Up @@ -52,16 +51,14 @@ class AuthenticationFilter(
}

private fun setAuthenticationByHeader(request: HttpServletRequest) {
var requestUserId = request.getHeader("Request-User-Id") ?: UUID.randomUUID().toString()
var requestUserAuthority = request.getHeader("Request-User-Authorities") ?: "STU"
var requestUserRole = request.getHeader("Request-User-Role") ?: "STU"

val authorityList = requestUserAuthority.toList()
val simpleGrantedAuthorities = if(authorityList.isNotEmpty()) {
buildRequestAuthoritiesAndRole(requestUserRole, authorityList)
val requestUserId = request.getHeader("Request-User-Id")
val requestUserAuthority = request.getHeader("Request-User-Authorities")
val requestUserRole = request.getHeader("Request-User-Role")

val simpleGrantedAuthorities = requestUserAuthority.toList().let { authorities ->
buildRequestAuthoritiesAndRole(requestUserRole, authorities)
.map { SimpleGrantedAuthority(it) }
} else {
listOf<SimpleGrantedAuthority>()
}

if (simpleGrantedAuthorities.isNotEmpty()) {
Expand All @@ -76,15 +73,6 @@ class AuthenticationFilter(
}
}

private fun buildRequestAuthoritiesAndRole(
requestUserRole: String,
requestUserAuthorities: List<String>
): List<String> {
val authoritiesAndRoles = mutableListOf("ROLE_$requestUserRole")
requestUserAuthorities.forEach { authoritiesAndRoles.add(it) }
return authoritiesAndRoles
}

private fun setAuthenticationByAccessToken(accessToken: String) {
val tokenEntity = accessTokenEntityRepository.findByTokenValue(accessToken)
?: throw AccessTokenNotFoundException(ACCESS_TOKEN_NOT_FOUND)
Expand All @@ -102,6 +90,15 @@ class AuthenticationFilter(
)
}

private fun buildRequestAuthoritiesAndRole(
requestUserRole: String,
requestUserAuthorities: List<String>
): List<String> {
val authoritiesAndRoles = mutableListOf("ROLE_$requestUserRole")
requestUserAuthorities.forEach { authoritiesAndRoles.add(it) }
return requestUserAuthorities
}

private fun String.toList(): List<String> {
return this.removeSurrounding("[", "]")
.replace(" ", "")
Expand Down

0 comments on commit a9ce680

Please sign in to comment.