Search in sources :

Example 11 with ServiceDescriptor

use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.

the class OutboundSecurityIT method startServers.

// ----- test lifecycle methods -----------------------------------------
@BeforeAll
public static void startServers() throws Exception {
    LogConfig.configureRuntime();
    Config config = Config.create();
    Security security = Security.builder().addProvider(HttpBasicAuthProvider.create(config.get("http-basic-auth"))).build();
    // secured web server's Routing
    Routing webRouting = Routing.builder().register(WebSecurity.create(security).securityDefaults(WebSecurity.authenticate())).get("/test", WebSecurity.rolesAllowed("admin"), OutboundSecurityIT::echoWebRequest).get("/propagate", WebSecurity.rolesAllowed("user"), OutboundSecurityIT::propagateCredentialsWebRequest).get("/override", WebSecurity.rolesAllowed("user"), OutboundSecurityIT::overrideCredentialsWebRequest).build();
    webServer = WebServer.create(webRouting).start().toCompletableFuture().get(10, TimeUnit.SECONDS);
    webServerURL = "http://127.0.0.1:" + webServer.port();
    client = ClientBuilder.newBuilder().build().register(HttpAuthenticationFeature.basicBuilder().build());
    ServiceDescriptor echoService = ServiceDescriptor.builder(new SecuredOutboundEchoService(webServerURL)).intercept(GrpcSecurity.rolesAllowed("admin")).build();
    // Add the EchoService
    GrpcRouting grpcRouting = GrpcRouting.builder().intercept(GrpcSecurity.create(security).securityDefaults(GrpcSecurity.authenticate())).register(echoService).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, grpcRouting).start().toCompletableFuture().get(10, TimeUnit.SECONDS);
    Channel channel = InProcessChannelBuilder.forName(grpcServer.configuration().name()).build();
    adminEchoStub = EchoServiceGrpc.newBlockingStub(channel).withCallCredentials(adminCreds);
    noCredsEchoStub = EchoServiceGrpc.newBlockingStub(channel);
}
Also used : GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) LogConfig(io.helidon.common.LogConfig) Config(io.helidon.config.Config) Channel(io.grpc.Channel) GrpcRouting(io.helidon.grpc.server.GrpcRouting) Routing(io.helidon.webserver.Routing) Security(io.helidon.security.Security) WebSecurity(io.helidon.security.integration.webserver.WebSecurity) SecuredOutboundEchoService(services.SecuredOutboundEchoService) GrpcRouting(io.helidon.grpc.server.GrpcRouting) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 12 with ServiceDescriptor

use of io.helidon.grpc.server.ServiceDescriptor 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);
}
Also used : GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) LogConfig(io.helidon.common.LogConfig) Config(io.helidon.config.Config) EchoService(services.EchoService) Channel(io.grpc.Channel) StringService(services.StringService) Security(io.helidon.security.Security) GrpcRouting(io.helidon.grpc.server.GrpcRouting) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 13 with ServiceDescriptor

use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.

the class MetricsConfigurerTest method shouldAddSimpleTimerMetricFromClassAnnotation.

@Test
public void shouldAddSimpleTimerMetricFromClassAnnotation() {
    Class<?> serviceClass = ServiceOne.class;
    Class<?> annotatedClass = ServiceOne.class;
    ServiceDescriptor.Builder builder = ServiceDescriptor.builder(new ServiceOne());
    MetricsConfigurer configurer = new MetricsConfigurer();
    configurer.accept(serviceClass, annotatedClass, builder);
    ServiceDescriptor descriptor = builder.build();
    List<ServerInterceptor> serviceInterceptors = descriptor.interceptors().stream().collect(Collectors.toList());
    MethodDescriptor<?, ?> methodDescriptor = descriptor.method("simplyTimed");
    List<ServerInterceptor> methodInterceptors = methodDescriptor.interceptors().stream().collect(Collectors.toList());
    assertThat(serviceInterceptors, is(emptyIterable()));
    assertThat(methodInterceptors.size(), is(1));
    assertThat(methodInterceptors.get(0), is(instanceOf(GrpcMetrics.class)));
    assertThat(((GrpcMetrics) methodInterceptors.get(0)).metricType(), is(MetricType.SIMPLE_TIMER));
    assertThat(updReg().getSimpleTimers().get(new MetricID(ServiceOne.class.getName() + ".simplyTimed")), is(notNullValue()));
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) ServerInterceptor(io.grpc.ServerInterceptor) Test(org.junit.jupiter.api.Test)

Example 14 with ServiceDescriptor

use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.

the class MetricsConfigurerTest method shouldIgnoreMeterMetricFromInterfaceAnnotation.

@Test
public void shouldIgnoreMeterMetricFromInterfaceAnnotation() {
    Class<?> serviceClass = ServiceTwoImpl.class;
    Class<?> annotatedClass = ServiceTwo.class;
    ServiceDescriptor.Builder builder = ServiceDescriptor.builder(new ServiceTwoImpl());
    MetricsConfigurer configurer = new MetricsConfigurer();
    configurer.accept(serviceClass, annotatedClass, builder);
    ServiceDescriptor descriptor = builder.build();
    List<ServerInterceptor> serviceInterceptors = descriptor.interceptors().stream().collect(Collectors.toList());
    MethodDescriptor<?, ?> methodDescriptor = descriptor.method("metered");
    List<ServerInterceptor> methodInterceptors = methodDescriptor.interceptors().stream().collect(Collectors.toList());
    assertThat(serviceInterceptors, is(emptyIterable()));
    assertThat(methodInterceptors, is(emptyIterable()));
}
Also used : ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) ServerInterceptor(io.grpc.ServerInterceptor) Test(org.junit.jupiter.api.Test)

Example 15 with ServiceDescriptor

use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.

the class MetricsConfigurerTest method shouldIgnoreConcurrentGaugeMetricFromInterfaceAnnotation.

@Test
public void shouldIgnoreConcurrentGaugeMetricFromInterfaceAnnotation() {
    Class<?> serviceClass = ServiceTwoImpl.class;
    Class<?> annotatedClass = ServiceTwo.class;
    ServiceDescriptor.Builder builder = ServiceDescriptor.builder(new ServiceTwoImpl());
    MetricsConfigurer configurer = new MetricsConfigurer();
    configurer.accept(serviceClass, annotatedClass, builder);
    ServiceDescriptor descriptor = builder.build();
    List<ServerInterceptor> serviceInterceptors = descriptor.interceptors().stream().collect(Collectors.toList());
    MethodDescriptor<?, ?> methodDescriptor = descriptor.method("concurrentGauge");
    List<ServerInterceptor> methodInterceptors = methodDescriptor.interceptors().stream().collect(Collectors.toList());
    assertThat(serviceInterceptors, is(emptyIterable()));
    assertThat(methodInterceptors, is(emptyIterable()));
}
Also used : ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) ServerInterceptor(io.grpc.ServerInterceptor) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceDescriptor (io.helidon.grpc.server.ServiceDescriptor)45 Test (org.junit.jupiter.api.Test)37 ServerInterceptor (io.grpc.ServerInterceptor)17 MethodDescriptor (io.helidon.grpc.server.MethodDescriptor)14 Metadata (io.grpc.Metadata)12 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)11 BeanManager (jakarta.enterprise.inject.spi.BeanManager)8 MetricID (org.eclipse.microprofile.metrics.MetricID)7 Counter (org.eclipse.microprofile.metrics.Counter)6 LogConfig (io.helidon.common.LogConfig)4 GrpcRouting (io.helidon.grpc.server.GrpcRouting)4 GrpcServerConfiguration (io.helidon.grpc.server.GrpcServerConfiguration)4 Security (io.helidon.security.Security)4 Config (io.helidon.config.Config)3 GrpcServer (io.helidon.grpc.server.GrpcServer)3 SimpleTimer (org.eclipse.microprofile.metrics.SimpleTimer)3 BeforeAll (org.junit.jupiter.api.BeforeAll)3 Channel (io.grpc.Channel)2 ServerCall (io.grpc.ServerCall)2 ServerCallHandler (io.grpc.ServerCallHandler)2