diff --git a/src/main/kotlin/com/example/v1oauthauthorizationservice/infrastructure/configuration/AuthenticationFilter.kt b/src/main/kotlin/com/example/v1oauthauthorizationservice/infrastructure/configuration/AuthenticationFilter.kt index 8c91d69..7167b96 100644 --- a/src/main/kotlin/com/example/v1oauthauthorizationservice/infrastructure/configuration/AuthenticationFilter.kt +++ b/src/main/kotlin/com/example/v1oauthauthorizationservice/infrastructure/configuration/AuthenticationFilter.kt @@ -56,9 +56,12 @@ class AuthenticationFilter( var requestUserAuthority = request.getHeader("Request-User-Authorities") ?: "STU" var requestUserRole = request.getHeader("Request-User-Role") ?: "STU" - val simpleGrantedAuthorities = requestUserAuthority.toList().let { authorities -> - buildRequestAuthoritiesAndRole(requestUserRole, authorities) + val authorityList = requestUserAuthority.toList() + val simpleGrantedAuthorities = if(authorityList.isNotEmpty()) { + buildRequestAuthoritiesAndRole(requestUserRole, authorityList) .map { SimpleGrantedAuthority(it) } + } else { + listOf() } if (simpleGrantedAuthorities.isNotEmpty()) { @@ -73,6 +76,15 @@ class AuthenticationFilter( } } + private fun buildRequestAuthoritiesAndRole( + requestUserRole: String, + requestUserAuthorities: List + ): List { + 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) @@ -90,15 +102,6 @@ class AuthenticationFilter( ) } - private fun buildRequestAuthoritiesAndRole( - requestUserRole: String, - requestUserAuthorities: List - ): List { - val authoritiesAndRoles = mutableListOf("ROLE_$requestUserRole") - requestUserAuthorities.forEach { authoritiesAndRoles.add(it) } - return requestUserAuthorities - } - private fun String.toList(): List { return this.removeSurrounding("[", "]") .replace(" ", "")