eclipse-vertx / eclipse-vertx/vertx-grpc

Ability to intercept incoming outcoming request

Open
#200 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
53
Forks
36
Avg merge
7h 37m
Merged PRs (30d)
64

Description

### Describe the feature

Going forward, we should probably have the ability to intercept or pipe through messages on both client and server. This would have various uses for authorization on both server and client, and it would also allow users to easily extend the functionality with their own code. I think we should allow for potential chaining, the ability to set context, etc. We need to put the interception probably between the message being properly decoded, as there are many variants/forms the message can come through.

Potentional example:

```java
public interface MessageInterceptor {
String getName();
int getPriority();
Future process(MessageContext context) throws InterceptorException;
}

public class MessageContext {
private GrpcMessage message;
private Map attributes;
private UserContext user;
private Direction direction; // INBOUND/OUTBOUND
}
```

Examples:
```java
public class AuthInterceptor implements MessageInterceptor {
public Future process(MessageContext ctx) {
if (!hasPermission(ctx.getUser(), ctx.getMessage())) {
throw new UnauthorizedException();
}
return Future.succededFuture(ctx);
}
}

public class TransformInterceptor implements MessageInterceptor {
public Future process(MessageContext ctx) {
ctx.setMessage(transform(ctx.getMessage()));
return Future.succededFuture(ctx);
}
}
```

### Contribution

_No response_

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.