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