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);
}
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);
}
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()));
}
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()));
}
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()));
}
Aggregations