Search in sources :

Example 96 with Config

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

the class BasicExampleConfigMain method startServer.

static WebServer startServer() {
    LogConfig.initClass();
    Config config = Config.create();
    Routing routing = Routing.builder().register(WebSecurity.create(config.get("security"))).register("/static", StaticContentSupport.create("/WEB")).get("/{*}", (req, res) -> {
        Optional<SecurityContext> securityContext = req.context().get(SecurityContext.class);
        res.headers().contentType(MediaType.TEXT_PLAIN.withCharset("UTF-8"));
        res.send("Hello, you are: \n" + securityContext.map(ctx -> ctx.user().orElse(SecurityContext.ANONYMOUS).toString()).orElse("Security context is null"));
    }).build();
    return WebServer.builder().config(config.get("server")).routing(routing).build().start().await(10, TimeUnit.SECONDS);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) StaticContentSupport(io.helidon.webserver.staticcontent.StaticContentSupport) Config(io.helidon.config.Config) WebServer(io.helidon.webserver.WebServer) Optional(java.util.Optional) WebSecurity(io.helidon.security.integration.webserver.WebSecurity) SecurityContext(io.helidon.security.SecurityContext) LogConfig(io.helidon.common.LogConfig) Routing(io.helidon.webserver.Routing) MediaType(io.helidon.common.http.MediaType) Optional(java.util.Optional) Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig) SecurityContext(io.helidon.security.SecurityContext) Routing(io.helidon.webserver.Routing)

Example 97 with Config

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

the class IdcsMain method main.

/**
 * Start the example.
 *
 * @param args ignored
 */
public static void main(String[] args) {
    // load logging configuration
    LogConfig.configureRuntime();
    Config config = buildConfig();
    Security security = Security.create(config.get("security"));
    // this is needed for proper encryption/decryption of cookies
    Contexts.globalContext().register(security);
    Routing.Builder routing = Routing.builder().register(WebSecurity.create(security, config.get("security"))).register(OidcSupport.create(config)).get("/rest/profile", (req, res) -> {
        Optional<SecurityContext> securityContext = req.context().get(SecurityContext.class);
        res.headers().contentType(MediaType.TEXT_PLAIN.withCharset("UTF-8"));
        res.send("Response from config based service, you are: \n" + securityContext.flatMap(SecurityContext::user).map(Subject::toString).orElse("Security context is null"));
    }).get("/loggedout", (req, res) -> res.send("You have been logged out"));
    theServer = WebServer.create(routing, config.get("server"));
    IdcsUtil.start(theServer);
}
Also used : Security(io.helidon.security.Security) Config(io.helidon.config.Config) SecurityContext(io.helidon.security.SecurityContext) Contexts(io.helidon.common.context.Contexts) MediaType(io.helidon.common.http.MediaType) ConfigSources.file(io.helidon.config.ConfigSources.file) WebServer(io.helidon.webserver.WebServer) Optional(java.util.Optional) WebSecurity(io.helidon.security.integration.webserver.WebSecurity) Subject(io.helidon.security.Subject) OidcSupport(io.helidon.security.providers.oidc.OidcSupport) ConfigSources.classpath(io.helidon.config.ConfigSources.classpath) LogConfig(io.helidon.common.LogConfig) Routing(io.helidon.webserver.Routing) Optional(java.util.Optional) Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig) SecurityContext(io.helidon.security.SecurityContext) Routing(io.helidon.webserver.Routing) Security(io.helidon.security.Security) WebSecurity(io.helidon.security.integration.webserver.WebSecurity) Subject(io.helidon.security.Subject)

Example 98 with Config

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

the class AbacJerseyMain method startIt.

static Server startIt() {
    Config config = Config.create();
    Server server = Server.builder().config(config).port(8080).build().start();
    System.out.printf("Started server on localhost:%d%n", server.port());
    System.out.println();
    System.out.println("***********************");
    System.out.println("** Endpoints:        **");
    System.out.println("***********************");
    System.out.println("Using declarative authorization (ABAC):");
    System.out.printf("  http://localhost:%1$d/rest/attributes%n", server.port());
    System.out.println("Using explicit authorization (ABAC):");
    System.out.printf("  http://localhost:%1$d/rest/explicit%n", server.port());
    return server;
}
Also used : Server(io.helidon.microprofile.server.Server) Config(io.helidon.config.Config)

Example 99 with Config

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

the class JerseyConfigMain method buildSecurity.

private static SecurityFeature buildSecurity() {
    Config config = Config.create().get("security");
    Security security = Security.create(config);
    return SecurityFeature.builder(security).config(config.get("jersey")).build();
}
Also used : Config(io.helidon.config.Config) Security(io.helidon.security.Security)

Example 100 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(Config config) {
    // load logging configuration
    LogConfig.configureRuntime();
    // Build server using three ports:
    // default public port, admin port, private port
    WebServer server = WebServer.builder(createPublicRouting(config)).config(config.get("server")).addMediaSupport(JsonpSupport.create()).build();
    Single<WebServer> webServerSingle = 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.
    webServerSingle.thenAccept(ws -> {
        System.out.println("WEB server is up! http://localhost:" + ws.port());
        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 webServerSingle;
}
Also used : JsonpSupport(io.helidon.media.jsonp.JsonpSupport) 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) HealthSupport(io.helidon.health.HealthSupport) HealthChecks(io.helidon.health.checks.HealthChecks) WebServer(io.helidon.webserver.WebServer)

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