Skip to content

Grpc Kotlin stubs do not support SecurityContextHolder.getContext() #322

@mckernant1

Description

@mckernant1

Hello again,

Another kotlin specific problem around the spring SecurityContextHolder.getContext().

I have made a sample commit here with a failing test case

Essentially, SecurityContextHolder.getContext().authentication is null in suspend functions generated by the grpc kotlin stubs. I'm not super familiar with how spring stores this, I believe its threadLocal? Kotlin suspend probably messes this up with how it handles coroutines.

I have added the following block to both sample java grpc-oauth2 and grpc-server-kotlin, and this only fails in grpc-server-kotlin which should confirm its a kotlin stubs issue

if (SecurityContextHolder.getContext().authentication != null) {
    throw RuntimeException(" SecurityContextHolder Authentication not set")
}

I will hopefully have some time to look into this over winter break.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions