grpc-ecosystem / grpc-ecosystem/grpc-spring

AuthenticationContext not accessible outside of authenticated scope/early interceptors

Open
#462 11 comments 0 reactions 1 assignee Claimed by @ST-DDT View on GitHub
enhancement
Dominant language
Java
Stars
3.7k
Forks
858
PR merge metrics
No merged PRs in 30d

Description

My app is working with dynamic OAuth and all is good. I am now implementing request / response logging. One thing I need to log comes from the SecurityContext. This also works fine... in most cases.

I am using the standard Spring "throw new ResponseStatusException(...);" to return stuff like 404, etc. from rest methods. That also works fine and I wrote a server interceptor to catch those and translate to grpc errors. All good.

The bug / oversight is that in DefaultAuthenticatingServerInterceptor, if you encounter an exception, in AuthenticatingServerCallListener::detachAuthenticationContext you clear the SecurityContext before anything in my server interceptor can get it. It gets cleared within the context of the call it seems. And its not set until the call is ready to happen. With no ResponseStatusException, the SecurityContext is live when it gets to my server interceptor.

Doesn't seem to be a way to do anything about that without c&p'ing the entire DefaultAuthenticatingServerInterceptor and changing that.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.