use of io.helidon.grpc.server.GrpcRouting in project helidon by oracle.
the class ServiceAndMethodLevelSecurityIT method startServer.
@BeforeAll
public static void startServer() throws Exception {
LogConfig.configureRuntime();
Config config = Config.create();
Security security = Security.builder().addProvider(HttpBasicAuthProvider.create(config.get("http-basic-auth"))).build();
ServiceDescriptor echoService = ServiceDescriptor.builder(new EchoService()).intercept(GrpcSecurity.rolesAllowed("admin")).build();
ServiceDescriptor stringService = ServiceDescriptor.builder(new StringService()).intercept("Upper", GrpcSecurity.rolesAllowed("admin")).intercept("Split", GrpcSecurity.rolesAllowed("admin")).build();
// Add the EchoService
GrpcRouting routing = GrpcRouting.builder().intercept(GrpcSecurity.create(security).securityDefaults(GrpcSecurity.authenticate())).register(echoService).register(stringService).build();
// Run the server on port 0 so that it picks a free ephemeral port
GrpcServerConfiguration serverConfig = GrpcServerConfiguration.builder().port(0).build();
grpcServer = GrpcServer.create(serverConfig, routing).start().toCompletableFuture().get(10, TimeUnit.SECONDS);
Channel channel = InProcessChannelBuilder.forName(grpcServer.configuration().name()).build();
adminEchoStub = EchoServiceGrpc.newBlockingStub(channel).withCallCredentials(adminCreds);
userEchoStub = EchoServiceGrpc.newBlockingStub(channel).withCallCredentials(userCreds);
adminStringStub = StringServiceGrpc.newBlockingStub(channel).withCallCredentials(adminCreds);
userStringStub = StringServiceGrpc.newBlockingStub(channel).withCallCredentials(userCreds);
noCredsEchoStub = StringServiceGrpc.newBlockingStub(channel);
}
use of io.helidon.grpc.server.GrpcRouting in project helidon by oracle.
the class AnnotatedServiceTest method startServer.
@BeforeAll
public static void startServer() throws Exception {
LogConfig.configureRuntime();
GrpcRouting routing = GrpcRouting.builder().register(descriptor(UnaryService.class)).register(descriptor(ServerStreamingService.class)).register(descriptor(ClientStreamingService.class)).register(descriptor(BidiService.class)).build();
GrpcServerConfiguration serverConfig = GrpcServerConfiguration.builder().port(0).build();
grpcServer = GrpcServer.create(serverConfig, routing).start().toCompletableFuture().get(10, TimeUnit.SECONDS);
channel = InProcessChannelBuilder.forName(grpcServer.configuration().name()).build();
}
use of io.helidon.grpc.server.GrpcRouting in project helidon by oracle.
the class SecureServer method createGrpcServer.
/**
* Create the gRPC server.
*/
private static GrpcServer createGrpcServer(Config config, Security security) {
GrpcRouting grpcRouting = GrpcRouting.builder().intercept(GrpcSecurity.create(security).securityDefaults(GrpcSecurity.authenticate())).register(new StringService(), GrpcSecurity.rolesAllowed("admin")).register(new GreetService()).build();
GrpcServer grpcServer = GrpcServer.create(GrpcServerConfiguration.create(config), grpcRouting);
grpcServer.start().thenAccept(s -> {
System.out.println("gRPC server is UP! http://localhost:" + s.port());
s.whenShutdown().thenRun(() -> System.out.println("gRPC server is DOWN. Good bye!"));
}).exceptionally(t -> {
System.err.println("gRPC server startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
return grpcServer;
}
use of io.helidon.grpc.server.GrpcRouting in project helidon by oracle.
the class SecureServer method main.
/**
* Main entry point.
*
* @param args the program arguments
*/
public static void main(String[] args) {
LogConfig.configureRuntime();
Config config = Config.create();
Security security = Security.builder().addProvider(HttpBasicAuthProvider.create(config.get("http-basic-auth"))).build();
ServiceDescriptor greetService1 = ServiceDescriptor.builder(new GreetService(config)).name("GreetService").intercept(GrpcSecurity.rolesAllowed("user")).intercept("SetGreeting", GrpcSecurity.rolesAllowed("admin")).build();
GrpcRouting grpcRouting = GrpcRouting.builder().intercept(GrpcSecurity.create(security).securityDefaults(GrpcSecurity.authenticate())).register(greetService1).register(new StringService()).build();
GrpcServerConfiguration serverConfig = GrpcServerConfiguration.create(config.get("grpc"));
GrpcServer grpcServer = GrpcServer.create(serverConfig, grpcRouting);
grpcServer.start().thenAccept(s -> {
System.out.println("gRPC server is UP! http://localhost:" + s.port());
s.whenShutdown().thenRun(() -> System.out.println("gRPC server is DOWN. Good bye!"));
}).exceptionally(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
}
use of io.helidon.grpc.server.GrpcRouting in project helidon by oracle.
the class GrpcChannelsProviderIT method startGrpcServer.
/**
* Start a gRPC server listening on the specified port and with ssl enabled (if sslEnabled is true).
*
* @param nPort The server port where the server will listen.
* @param sslEnabled true if ssl enabled.
* @param mutual if true then 2 way (mutual) or just one way ssl.
* @return A reference to a {@link io.helidon.grpc.server.GrpcServer}.
*/
private static GrpcServer startGrpcServer(int nPort, boolean sslEnabled, boolean mutual) throws Exception {
Resource tlsCert = Resource.create(SERVER_CERT);
Resource tlsKey = Resource.create(SERVER_KEY);
Resource tlsCaCert = Resource.create(CA_CERT);
GrpcTlsDescriptor sslConfig = null;
String name = "grpc.server";
if (!sslEnabled) {
name = name + 1;
} else if (mutual) {
name = name + 2;
sslConfig = GrpcTlsDescriptor.builder().jdkSSL(false).tlsCert(tlsCert).tlsKey(tlsKey).tlsCaCert(tlsCaCert).build();
} else {
name = name + 3;
sslConfig = GrpcTlsDescriptor.builder().jdkSSL(false).tlsCert(tlsCert).tlsKey(tlsKey).build();
}
// Add the EchoService
GrpcRouting routing = GrpcRouting.builder().register(new TreeMapService()).build();
GrpcServerConfiguration.Builder bldr = GrpcServerConfiguration.builder().name(name).port(nPort);
if (sslEnabled) {
bldr.tlsConfig(sslConfig);
}
return GrpcServer.create(bldr.build(), routing).start().toCompletableFuture().get(10, TimeUnit.SECONDS);
}
Aggregations