diff --git a/gooddata-server-oauth2-autoconfigure/src/main/kotlin/CallContextAuthenticationProcessor.kt b/gooddata-server-oauth2-autoconfigure/src/main/kotlin/CallContextAuthenticationProcessor.kt index d4606cd..c27346d 100644 --- a/gooddata-server-oauth2-autoconfigure/src/main/kotlin/CallContextAuthenticationProcessor.kt +++ b/gooddata-server-oauth2-autoconfigure/src/main/kotlin/CallContextAuthenticationProcessor.kt @@ -87,7 +87,7 @@ class CallContextAuthenticationProcessor( val userContextData = UserContextData( organizationId = authDetails.organizationId, userId = authDetails.userId, - userName = null, + userName = authDetails.userName, tokenId = authDetails.tokenId, authMethod = authMethod, accessToken = null diff --git a/gooddata-server-oauth2-autoconfigure/src/main/kotlin/CallContextHeaderProcessor.kt b/gooddata-server-oauth2-autoconfigure/src/main/kotlin/CallContextHeaderProcessor.kt index f03dcf5..c812222 100644 --- a/gooddata-server-oauth2-autoconfigure/src/main/kotlin/CallContextHeaderProcessor.kt +++ b/gooddata-server-oauth2-autoconfigure/src/main/kotlin/CallContextHeaderProcessor.kt @@ -54,5 +54,6 @@ data class CallContextAuth( val organizationId: String, val userId: String, val authMethod: String, - val tokenId: String? = null + val tokenId: String? = null, + val userName: String? = null, ) diff --git a/gooddata-server-oauth2-autoconfigure/src/test/kotlin/CallContextAuthenticationProcessorTest.kt b/gooddata-server-oauth2-autoconfigure/src/test/kotlin/CallContextAuthenticationProcessorTest.kt index 95706fe..5cd1045 100644 --- a/gooddata-server-oauth2-autoconfigure/src/test/kotlin/CallContextAuthenticationProcessorTest.kt +++ b/gooddata-server-oauth2-autoconfigure/src/test/kotlin/CallContextAuthenticationProcessorTest.kt @@ -128,6 +128,36 @@ class CallContextAuthenticationProcessorTest { } } + @Test + fun `propagates userName from CallContextAuth to user context`() { + val authToken = CallContextAuthenticationToken("base64-encoded-header") + val authDetails = CallContextAuth( + organizationId = "org123", + userId = "user456", + authMethod = "OIDC", + tokenId = "token789", + userName = "John Smith" + ) + + every { headerProcessor.parseCallContextHeader("base64-encoded-header") } returns authDetails + coEvery { + userContextProvider.getContextView(any(), any(), any(), any(), any(), any()) + } returns Context.empty() + + processor.authenticate(authToken, webExchange, webFilterChain).block() + + coVerify(exactly = 1) { + userContextProvider.getContextView( + organizationId = "org123", + userId = "user456", + userName = "John Smith", + tokenId = "token789", + authMethod = AuthMethod.OIDC, + accessToken = null + ) + } + } + @Test fun `null call context throws exception`() { val authToken = CallContextAuthenticationToken("header-value")