Skip to content

Commit

Permalink
update :: stackTrace 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
4mjeo committed Mar 2, 2024
1 parent c739e8d commit 1d1c417
Showing 1 changed file with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,46 +46,54 @@ class AuthenticationFilter(
}

private fun setAuthenticationByHeader(request: HttpServletRequest) {
try {
val requestUserId = request.getHeader("Request-User-Id")
val requestUserAuthority = request.getHeader("Request-User-Authorities")
val requestUserRole = request.getHeader("Request-User-Role")

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) }
}

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

if (!simpleGrantedAuthorities.isNullOrEmpty()) {
val user = User(
requestUserId,
"",
simpleGrantedAuthorities
)
val authentication = UsernamePasswordAuthenticationToken(user, "", user.authorities)
if (!simpleGrantedAuthorities.isNullOrEmpty()) {
val user = User(
requestUserId,
"",
simpleGrantedAuthorities
)
val authentication = UsernamePasswordAuthenticationToken(user, "", user.authorities)

SecurityContextHolder.getContext().authentication = authentication
SecurityContextHolder.getContext().authentication = authentication
}
} catch (e: Exception) {
e.printStackTrace()
}
}


private fun setAuthenticationByAccessToken(accessToken: String) {
val tokenEntity = accessTokenEntityRepository.findByTokenValue(accessToken)
?: throw AccessTokenNotFoundException(ACCESS_TOKEN_NOT_FOUND)
try {
val tokenEntity = accessTokenEntityRepository.findByTokenValue(accessToken)
?: throw AccessTokenNotFoundException(ACCESS_TOKEN_NOT_FOUND)

val authorization = authenticationEntityRepository.findByIdOrNull(tokenEntity.authorization.id)
?: throw AuthorizationNotFoundException(AUTHORIZATION_NOT_FOUND)
val authorization = authenticationEntityRepository.findByIdOrNull(tokenEntity.authorization.id)
?: throw AuthorizationNotFoundException(AUTHORIZATION_NOT_FOUND)

val attributes = authorizationAttributeEntityRepository.findByAuthorizationId(authorization.id!!).associate { it.attributeKey to it.attributeValue }
val authorities = listOf<GrantedAuthority>()
val attributes = authorizationAttributeEntityRepository.findByAuthorizationId(authorization.id!!).associate { it.attributeKey to it.attributeValue }
val authorities = listOf<GrantedAuthority>()

SecurityContextHolder.getContext().authentication = BearerTokenAuthentication(
DefaultOAuth2AuthenticatedPrincipal(attributes, authorities),
tokenEntity.toOAuth2AccessToken(),
authorities
)
SecurityContextHolder.getContext().authentication = BearerTokenAuthentication(
DefaultOAuth2AuthenticatedPrincipal(attributes, authorities),
tokenEntity.toOAuth2AccessToken(),
authorities
)
} catch (e: Exception) {
e.printStackTrace()
}
}


private fun buildRequestAuthoritiesAndRole(
requestUserRole: String,
requestUserAuthorities: List<String>
Expand Down

0 comments on commit 1d1c417

Please sign in to comment.