Search in sources :

Example 11 with Security

use of io.helidon.security.Security 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 12 with Security

use of io.helidon.security.Security in project helidon by oracle.

the class InjectionTest method testInjection.

@Test
void testInjection() {
    Security security = testBean.getSecurity();
    assertThat(security, notNullValue());
}
Also used : Security(io.helidon.security.Security) Test(org.junit.jupiter.api.Test) HelidonTest(io.helidon.microprofile.tests.junit5.HelidonTest)

Example 13 with Security

use of io.helidon.security.Security in project helidon by oracle.

the class GrpcSecurityTest method shouldCreateGrpcSecurityWithDefaultHandler.

@Test
public void shouldCreateGrpcSecurityWithDefaultHandler() {
    Security security = Security.builder().build();
    GrpcSecurityHandler defaultHandler = GrpcSecurityHandler.create();
    GrpcSecurity grpcSecurity = GrpcSecurity.create(security).securityDefaults(defaultHandler);
    assertThat(grpcSecurity, is(notNullValue()));
    assertThat(grpcSecurity.getSecurity(), is(sameInstance(security)));
    assertThat(grpcSecurity.getDefaultHandler(), is(sameInstance(defaultHandler)));
}
Also used : Security(io.helidon.security.Security) Test(org.junit.jupiter.api.Test)

Example 14 with Security

use of io.helidon.security.Security in project helidon by oracle.

the class GrpcSecurityTest method shouldCreateGrpcSecurity.

@Test
public void shouldCreateGrpcSecurity() {
    Security security = Security.builder().build();
    GrpcSecurity grpcSecurity = GrpcSecurity.create(security);
    assertThat(grpcSecurity, is(notNullValue()));
    assertThat(grpcSecurity.getSecurity(), is(sameInstance(security)));
    assertThat(grpcSecurity.getDefaultHandler(), is(notNullValue()));
}
Also used : Security(io.helidon.security.Security) Test(org.junit.jupiter.api.Test)

Example 15 with Security

use of io.helidon.security.Security in project helidon by oracle.

the class WebSecurityBuilderGateDefaultsTest method initClass.

@BeforeAll
public static void initClass() throws InterruptedException {
    WebSecurityTestUtil.auditLogFinest();
    myAuditProvider = new UnitTestAuditProvider();
    Config config = Config.create();
    Security security = Security.builder(config.get("security")).addAuditProvider(myAuditProvider).build();
    Routing routing = Routing.builder().register(WebSecurity.create(security).securityDefaults(WebSecurity.rolesAllowed("admin").audit())).get("/noRoles", WebSecurity.enforce()).get("/user[/{*}]", WebSecurity.rolesAllowed("user")).get("/admin", WebSecurity.rolesAllowed("admin")).get("/deny", WebSecurity.rolesAllowed("deny")).get("/auditOnly", WebSecurity.enforce().skipAuthentication().skipAuthorization().auditEventType("unit_test").auditMessageFormat(WebSecurityTests.AUDIT_MESSAGE_FORMAT)).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();
    server = WebServer.create(routing);
    long t = System.currentTimeMillis();
    CountDownLatch cdl = new CountDownLatch(1);
    server.start().thenAccept(webServer -> {
        long time = System.currentTimeMillis() - t;
        System.out.println("Started server on localhost:" + webServer.port() + " in " + time + " millis");
        cdl.countDown();
    });
    // we must wait for server to start, so other tests are not triggered until it is ready!
    assertThat("Timeout while waiting for server to start!", cdl.await(5, TimeUnit.SECONDS), is(true));
    serverBaseUri = "http://localhost:" + server.port();
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Security(io.helidon.security.Security) WebClient(io.helidon.webclient.WebClient) WebClientResponse(io.helidon.webclient.WebClientResponse) CoreMatchers.not(org.hamcrest.CoreMatchers.not) MediaType(io.helidon.common.http.MediaType) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) AfterAll(org.junit.jupiter.api.AfterAll) AuditEvent(io.helidon.security.AuditEvent) BeforeAll(org.junit.jupiter.api.BeforeAll) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Http(io.helidon.common.http.Http) HttpBasicAuthProvider(io.helidon.security.providers.httpauth.HttpBasicAuthProvider) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Config(io.helidon.config.Config) WebClientSecurity(io.helidon.webclient.security.WebClientSecurity) Set(java.util.Set) SecurityContext(io.helidon.security.SecurityContext) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) WebServer(io.helidon.webserver.WebServer) Optional(java.util.Optional) Routing(io.helidon.webserver.Routing) Optional(java.util.Optional) Config(io.helidon.config.Config) SecurityContext(io.helidon.security.SecurityContext) Routing(io.helidon.webserver.Routing) Security(io.helidon.security.Security) WebClientSecurity(io.helidon.webclient.security.WebClientSecurity) CountDownLatch(java.util.concurrent.CountDownLatch) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

Security (io.helidon.security.Security)48 SecurityContext (io.helidon.security.SecurityContext)25 Config (io.helidon.config.Config)22 BeforeAll (org.junit.jupiter.api.BeforeAll)14 Test (org.junit.jupiter.api.Test)14 LogConfig (io.helidon.common.LogConfig)13 Routing (io.helidon.webserver.Routing)12 Optional (java.util.Optional)12 WebSecurity (io.helidon.security.integration.webserver.WebSecurity)10 WebClientSecurity (io.helidon.webclient.security.WebClientSecurity)10 WebServer (io.helidon.webserver.WebServer)10 Channel (io.grpc.Channel)7 GrpcRouting (io.helidon.grpc.server.GrpcRouting)7 GrpcServerConfiguration (io.helidon.grpc.server.GrpcServerConfiguration)7 ServiceDescriptor (io.helidon.grpc.server.ServiceDescriptor)7 Set (java.util.Set)7 CoreMatchers.is (org.hamcrest.CoreMatchers.is)7 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)7 Context (io.helidon.common.context.Context)6 AuthorizationResponse (io.helidon.security.AuthorizationResponse)6