forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#34520 from michalvavrik/feature/grpc-che…
…ck-event-loop-with-updated-value Invoke secured blocking Grpc methods on worker thread
- Loading branch information
Showing
6 changed files
with
158 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
extensions/grpc/runtime/src/main/java/io/quarkus/grpc/auth/GrpcSecurityRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.quarkus.grpc.auth; | ||
|
||
import static io.quarkus.grpc.runtime.GrpcServerRecorder.GrpcServiceDefinition.getImplementationClassName; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import io.grpc.BindableService; | ||
import io.grpc.ServerMethodDefinition; | ||
import io.quarkus.arc.runtime.BeanContainer; | ||
import io.quarkus.grpc.runtime.GrpcContainer; | ||
import io.quarkus.runtime.annotations.Recorder; | ||
|
||
@Recorder | ||
public class GrpcSecurityRecorder { | ||
|
||
public void initGrpcSecurityInterceptor(Map<String, List<String>> serviceClassToBlockingMethod, | ||
BeanContainer container) { | ||
|
||
// service to full method names | ||
var svcToMethods = new HashMap<String, List<String>>(); | ||
var services = container.beanInstance(GrpcContainer.class).getServices(); | ||
for (BindableService service : services) { | ||
var className = getImplementationClassName(service); | ||
var blockingMethods = serviceClassToBlockingMethod.get(className); | ||
if (blockingMethods != null && !blockingMethods.isEmpty()) { | ||
var svcName = service.bindService().getServiceDescriptor().getName(); | ||
var methods = new ArrayList<String>(); | ||
for (String blockingMethod : blockingMethods) { | ||
for (ServerMethodDefinition<?, ?> method : service.bindService().getMethods()) { | ||
if (blockingMethod.equals(method.getMethodDescriptor().getBareMethodName())) { | ||
methods.add(method.getMethodDescriptor().getFullMethodName()); | ||
break; | ||
} | ||
} | ||
} | ||
svcToMethods.put(svcName, methods); | ||
} | ||
} | ||
|
||
container.beanInstance(GrpcSecurityInterceptor.class).init(svcToMethods); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters