Search in sources :

Example 46 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class SecureServer method main.

/**
 * Program entry point.
 *
 * @param args the program command line 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();
    grpcServer = createGrpcServer(config.get("grpc"), security);
    webServer = createWebServer(config.get("webserver"), security);
}
Also used : LogConfig(io.helidon.common.LogConfig) Config(io.helidon.config.Config) Security(io.helidon.security.Security) WebSecurity(io.helidon.security.integration.webserver.WebSecurity) GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity) WebClientSecurity(io.helidon.webclient.security.WebClientSecurity) GrpcSecurity(io.helidon.security.integration.grpc.GrpcSecurity)

Example 47 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class AbacServerFromConfig 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.create(config.get("security"));
    GrpcRouting grpcRouting = GrpcRouting.builder().intercept(GrpcSecurity.create(security, config.get("security"))).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;
    });
}
Also used : StringService(io.helidon.grpc.examples.common.StringService) GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) Security(io.helidon.security.Security) Config(io.helidon.config.Config) GrpcServer(io.helidon.grpc.server.GrpcServer) LogConfig(io.helidon.common.LogConfig) GrpcRouting(io.helidon.grpc.server.GrpcRouting) GrpcSecurity(io.helidon.security.integration.grpc.GrpcSecurity) GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig) StringService(io.helidon.grpc.examples.common.StringService) GrpcServer(io.helidon.grpc.server.GrpcServer) Security(io.helidon.security.Security) GrpcSecurity(io.helidon.security.integration.grpc.GrpcSecurity) GrpcRouting(io.helidon.grpc.server.GrpcRouting)

Example 48 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class SecureStringClient method main.

/**
 * Program entry point.
 *
 * @param args  the program arguments - {@code arg[0]} is the user name
 *              and {@code arg[1] is the password}
 */
public static void main(String[] args) {
    Channel channel = ManagedChannelBuilder.forAddress("localhost", 1408).usePlaintext().build();
    // Obtain the user name and password from the program arguments
    String user = args.length >= 2 ? args[0] : "Ted";
    String password = args.length >= 2 ? args[1] : "secret";
    Config config = Config.create();
    // configure Helidon security and add the basic auth provider
    Security security = Security.builder().addProvider(HttpBasicAuthProvider.create(config.get("http-basic-auth"))).build();
    // create the gRPC client security call credentials
    // setting the properties used by the basic auth provider for user name and password
    GrpcClientSecurity clientSecurity = GrpcClientSecurity.builder(security.createContext("test.client")).property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_USER, user).property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_PASSWORD, password).build();
    // Create the client service descriptor and add the call credentials
    ClientServiceDescriptor descriptor = ClientServiceDescriptor.builder(StringServiceGrpc.getServiceDescriptor()).callCredentials(clientSecurity).build();
    // create the client for the service
    GrpcServiceClient client = GrpcServiceClient.create(channel, descriptor);
    Strings.StringMessage request = Strings.StringMessage.newBuilder().setText("ABCDE").build();
    Strings.StringMessage response = client.blockingUnary("Lower", request);
    System.out.println("Response from Lower method call is '" + response.getText() + "'");
}
Also used : GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity) Config(io.helidon.config.Config) Channel(io.grpc.Channel) ClientServiceDescriptor(io.helidon.grpc.client.ClientServiceDescriptor) GrpcServiceClient(io.helidon.grpc.client.GrpcServiceClient) Security(io.helidon.security.Security) GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity) Strings(io.helidon.grpc.examples.common.Strings)

Example 49 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class Main method startServer.

/**
 * Start the server.
 * @return the created {@link WebServer} instance
 */
static Single<WebServer> startServer() {
    // load logging configuration
    LogConfig.configureRuntime();
    // By default this will pick up application.yaml from the classpath
    Config config = Config.create();
    WebServer server = WebServer.builder().routing(createRouting(config)).config(config.get("server")).addMediaSupport(JsonpSupport.create()).build();
    Single<WebServer> webserver = server.start();
    // Try to start the server. If successful, print some info and arrange to
    // print a message at shutdown. If unsuccessful, print the exception.
    webserver.thenAccept(ws -> {
        System.out.println("WEB server is up! http://localhost:" + ws.port() + "/greet");
        ws.whenShutdown().thenRun(() -> System.out.println("WEB server is DOWN. Good bye!"));
    }).exceptionallyAccept(t -> {
        System.err.println("Startup failed: " + t.getMessage());
        t.printStackTrace(System.err);
    });
    return webserver;
}
Also used : JsonpSupport(io.helidon.media.jsonp.JsonpSupport) KeyPerformanceIndicatorMetricsSettings(io.helidon.metrics.KeyPerformanceIndicatorMetricsSettings) Config(io.helidon.config.Config) WebServer(io.helidon.webserver.WebServer) Single(io.helidon.common.reactive.Single) MetricsSupport(io.helidon.metrics.MetricsSupport) LogConfig(io.helidon.common.LogConfig) Routing(io.helidon.webserver.Routing) WebServer(io.helidon.webserver.WebServer) Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig)

Example 50 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class Main method startServer.

/**
 * Start the server.
 *
 * @return the created {@link WebServer} instance
 */
static WebServer startServer() {
    // load logging configuration
    LogConfig.configureRuntime();
    // By default this will pick up application.yaml from the classpath
    Config config = Config.create();
    SendingService sendingService = new SendingService(config);
    WebServer server = WebServer.builder(createRouting(sendingService)).config(config.get("server")).build();
    server.start().thenAccept(ws -> {
        System.out.println("WEB server is up! http://localhost:" + ws.port());
        ws.whenShutdown().thenRun(() -> {
            // Stop messaging properly
            sendingService.shutdown();
            System.out.println("WEB server is DOWN. Good bye!");
        });
    }).exceptionally(t -> {
        System.err.println("Startup failed: " + t.getMessage());
        t.printStackTrace(System.err);
        return null;
    });
    // Server threads are not daemon. No need to block. Just react.
    return server;
}
Also used : ServerEndpointConfig(jakarta.websocket.server.ServerEndpointConfig) StaticContentSupport(io.helidon.webserver.staticcontent.StaticContentSupport) Config(io.helidon.config.Config) WebServer(io.helidon.webserver.WebServer) TyrusSupport(io.helidon.webserver.tyrus.TyrusSupport) LogConfig(io.helidon.common.LogConfig) Routing(io.helidon.webserver.Routing) WebServer(io.helidon.webserver.WebServer) ServerEndpointConfig(jakarta.websocket.server.ServerEndpointConfig) Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig)

Aggregations

Config (io.helidon.config.Config)329 Test (org.junit.jupiter.api.Test)169 LogConfig (io.helidon.common.LogConfig)56 WebServer (io.helidon.webserver.WebServer)54 Routing (io.helidon.webserver.Routing)51 BeforeAll (org.junit.jupiter.api.BeforeAll)24 Security (io.helidon.security.Security)20 HealthSupport (io.helidon.health.HealthSupport)18 Single (io.helidon.common.reactive.Single)17 MetricsSupport (io.helidon.metrics.MetricsSupport)16 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)16 ConfigSources (io.helidon.config.ConfigSources)15 JsonpSupport (io.helidon.media.jsonp.JsonpSupport)15 SecurityContext (io.helidon.security.SecurityContext)15 Optional (java.util.Optional)15 TimeUnit (java.util.concurrent.TimeUnit)15 WebSecurity (io.helidon.security.integration.webserver.WebSecurity)13 HealthChecks (io.helidon.health.checks.HealthChecks)12 WebClient (io.helidon.webclient.WebClient)12 GrpcRouting (io.helidon.grpc.server.GrpcRouting)11