Skip to content

Issues with SpringSecurity - AOP final issue vs missing interface proxying #4970

@ST-DDT

Description

@ST-DDT

What version of gRPC are you using?

1.15.0


I would like to use SpringSecurity to secure my grpc service.

public class TestService extends TestServiceGrpc.TestServiceImplBase {

    @Override
    @Secured("ROLE_USER")
    public void getVersion(Empty request, StreamObserver<Version> responseObserver) {
        responseObserver.onNext(Version.newBuilder().setVersion("1337.42").build());
        responseObserver.onCompleted();
    }

}

(The authentication and exception handling is done via interceptors.)

However if I do that I get one of two issues.

  1. First, the default way of Spring to apply the value is using an interface based proxy. This will cause

    io.grpc.StatusRuntimeException: UNIMPLEMENTED: Method not found: TestService/getVersion

    errors because the actual methods aren't present in any interface.

  2. I can avoid that error by using an AOP based proxy, but if I do that, then I get a warning in the logs:

    WARN  CglibAopProxy - Unable to proxy interface-implementing method [public final io.grpc.ServerServiceDefinition TestServiceGrpc$TestServiceImplBase.bindService()] because it is marked as final: Consider using interface-based JDK proxies instead!

The error was introduced by: #2552 / #2553

Possible solutions:

  1. Manually create an interface for that 😒 .
  2. Remove final modifier from that method 😐 .
  3. Let grpc-java create an interface for that 👍 . (Used as a proxy or to be implemented via ImplBase)
  4. Switch to java 8 (or later) and convert the ImplBase to an interface (combines 2+3) 👍 😄 .

PS: I used Spring-Security as an example, but the same issues apply for any kind of annotation based runtime code injection. Such as method call parameter logging, timing/metrics...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions