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