use of io.helidon.security.Security in project helidon by oracle.
the class OutboundOverrideJwtExampleTest method setup.
@BeforeAll
public static void setup() {
CompletionStage<Void> first = startClientService(-1);
CompletionStage<Void> second = startServingService(-1);
first.toCompletableFuture().join();
second.toCompletableFuture().join();
Security security = Security.builder().addProvider(HttpBasicAuthProvider.builder().build()).build();
webClient = WebClient.builder().baseUri("http://localhost:" + clientPort()).addService(WebClientSecurity.create(security)).build();
}
use of io.helidon.security.Security in project helidon by oracle.
the class VaultsExampleMain method main.
/**
* Start the server.
*
* @param args ignored
*/
public static void main(String[] args) {
LogConfig.configureRuntime();
// as I cannot share my configuration of OCI, let's combine the configuration
// from my home directory with the one compiled into the jar
// when running this example, you can either update the application.yaml in resources directory
// or use the same approach
Config config = buildConfig();
System.out.println("This example requires a valid OCI Vault, Secret and keys configured. It also requires " + "a Hashicorp Vault running with preconfigured data. Please see README.md");
Security security = Security.create(config.get("security"));
WebServer server = WebServer.builder().config(config.get("server")).routing(Routing.builder().register("/secrets", new SecretsService(security)).register("/encryption", new EncryptionService(security)).register("/digests", new DigestService(security))).build().start().await(10, TimeUnit.SECONDS);
System.out.println("Server started on port: " + server.port());
String baseAddress = "http://localhost:" + server.port() + "/";
System.out.println("Secrets endpoints:");
System.out.println();
System.out.println("OCI secret:");
System.out.println("\t" + baseAddress + "secrets/password");
System.out.println("Config secret:");
System.out.println("\t" + baseAddress + "secrets/token");
System.out.println("HCP Vault secret:");
System.out.println("\t" + baseAddress + "secrets/username");
System.out.println();
System.out.println("Encryption endpoints:");
System.out.println("OCI encrypted:");
System.out.println("\t" + baseAddress + "encryption/encrypt/crypto-1/text");
System.out.println("\t" + baseAddress + "encryption/decrypt/crypto-1/cipherText");
System.out.println("Config encrypted:");
System.out.println("\t" + baseAddress + "encryption/encrypt/crypto-2/text");
System.out.println("\t" + baseAddress + "encryption/decrypt/crypto-2/cipherText");
System.out.println("HCP Vault encrypted:");
System.out.println("\t" + baseAddress + "encryption/encrypt/crypto-3/text");
System.out.println("\t" + baseAddress + "encryption/decrypt/crypto-3/cipherText");
System.out.println();
System.out.println("Signature/HMAC endpoints:");
System.out.println("OCI Signature:");
System.out.println("\t" + baseAddress + "digests/digest/sig-1/text");
System.out.println("\t" + baseAddress + "digests/verify/sig-1/text/signature");
System.out.println("HCP Vault Signature:");
System.out.println("\t" + baseAddress + "digests/digest/sig-2/text");
System.out.println("\t" + baseAddress + "digests/digest/sig-2/text/signature");
System.out.println("HCP Vault HMAC:");
System.out.println("\t" + baseAddress + "digests/digest/hmac-1/text");
System.out.println("\t" + baseAddress + "digests/digest/hmac-2/text/hmac");
}
use of io.helidon.security.Security in project helidon by oracle.
the class BasicExampleBuilderMain method startServer.
static WebServer startServer() {
LogConfig.initClass();
Routing routing = Routing.builder().register(buildWebSecurity().securityDefaults(WebSecurity.authenticate())).any("/static[/{*}]", WebSecurity.rolesAllowed("user")).register("/static", StaticContentSupport.create("/WEB")).get("/noRoles", WebSecurity.enforce()).get("/user[/{*}]", WebSecurity.rolesAllowed("user")).get("/admin", WebSecurity.rolesAllowed("admin")).get("/deny", WebSecurity.rolesAllowed("deny").audit()).any("/noAuthn", WebSecurity.rolesAllowed("admin").authenticationOptional().audit()).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().routing(routing).build().start().await(10, TimeUnit.SECONDS);
}
use of io.helidon.security.Security in project helidon by oracle.
the class GoogleBuilderMain method start.
static int start(int port) {
Security security = Security.builder().addProvider(GoogleTokenProvider.builder().clientId("your-client-id.apps.googleusercontent.com")).build();
WebSecurity ws = WebSecurity.create(security);
Routing.Builder routing = Routing.builder().register(ws).get("/rest/profile", WebSecurity.authenticate(), (req, res) -> {
Optional<SecurityContext> securityContext = req.context().get(SecurityContext.class);
res.headers().contentType(MediaType.TEXT_PLAIN.withCharset("UTF-8"));
res.send("Response from builder based service, you are: \n" + securityContext.flatMap(SecurityContext::user).map(Subject::toString).orElse("Security context is null"));
req.next();
}).register(StaticContentSupport.create("/WEB"));
theServer = GoogleUtil.startIt(port, routing);
return theServer.port();
}
use of io.helidon.security.Security 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);
}
Aggregations