Search in sources :

Example 1 with SecuredOutboundEchoService

use of services.SecuredOutboundEchoService 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)

Aggregations

Channel (io.grpc.Channel)1 LogConfig (io.helidon.common.LogConfig)1 Config (io.helidon.config.Config)1 GrpcRouting (io.helidon.grpc.server.GrpcRouting)1 GrpcServerConfiguration (io.helidon.grpc.server.GrpcServerConfiguration)1 ServiceDescriptor (io.helidon.grpc.server.ServiceDescriptor)1 Security (io.helidon.security.Security)1 WebSecurity (io.helidon.security.integration.webserver.WebSecurity)1 Routing (io.helidon.webserver.Routing)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 SecuredOutboundEchoService (services.SecuredOutboundEchoService)1