Search in sources :

Example 56 with Config

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

the class AtnProviderSyncTest method testFailure.

@Test
public void testFailure() {
    Config config = Config.create(ConfigSources.create(Map.of("atn-object.size", String.valueOf(SIZE))));
    SecurityContext context = mock(SecurityContext.class);
    when(context.user()).thenReturn(Optional.empty());
    when(context.service()).thenReturn(Optional.empty());
    SecurityEnvironment se = SecurityEnvironment.create();
    EndpointConfig ep = EndpointConfig.builder().config("atn-object", config).build();
    ProviderRequest request = mock(ProviderRequest.class);
    when(request.securityContext()).thenReturn(context);
    when(request.env()).thenReturn(se);
    when(request.endpointConfig()).thenReturn(ep);
    AtnProviderSync provider = new AtnProviderSync();
    AuthenticationResponse response = provider.syncAuthenticate(request);
    assertThat(response.status(), is(SecurityResponse.SecurityStatus.FAILURE));
}
Also used : Config(io.helidon.config.Config) EndpointConfig(io.helidon.security.EndpointConfig) SecurityEnvironment(io.helidon.security.SecurityEnvironment) SecurityContext(io.helidon.security.SecurityContext) AuthenticationResponse(io.helidon.security.AuthenticationResponse) EndpointConfig(io.helidon.security.EndpointConfig) ProviderRequest(io.helidon.security.ProviderRequest) Test(org.junit.jupiter.api.Test)

Example 57 with Config

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

the class AtnProviderSyncTest method testConfigSuccess.

@Test
public void testConfigSuccess() {
    Config config = Config.create(ConfigSources.create(Map.of("value", VALUE, "size", String.valueOf(SIZE))));
    SecurityContext context = mock(SecurityContext.class);
    when(context.user()).thenReturn(Optional.empty());
    when(context.service()).thenReturn(Optional.empty());
    SecurityEnvironment se = SecurityEnvironment.create();
    EndpointConfig ep = EndpointConfig.builder().config("atn-object", config).build();
    ProviderRequest request = mock(ProviderRequest.class);
    when(request.securityContext()).thenReturn(context);
    when(request.env()).thenReturn(se);
    when(request.endpointConfig()).thenReturn(ep);
    testSuccess(request);
}
Also used : Config(io.helidon.config.Config) EndpointConfig(io.helidon.security.EndpointConfig) SecurityEnvironment(io.helidon.security.SecurityEnvironment) SecurityContext(io.helidon.security.SecurityContext) EndpointConfig(io.helidon.security.EndpointConfig) ProviderRequest(io.helidon.security.ProviderRequest) Test(org.junit.jupiter.api.Test)

Example 58 with Config

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

the class OutboundOverrideExample method startServingService.

static CompletionStage<Void> startServingService(int port) {
    Config config = createConfig("serving-service");
    Routing routing = Routing.builder().register(WebSecurity.create(config.get("security"))).get("/hello", (req, res) -> {
        res.send(req.context().get(SecurityContext.class).flatMap(SecurityContext::user).map(Subject::principal).map(Principal::getName).orElse("Anonymous"));
    }).build();
    return startServer(routing, port, server -> servingPort = server.port());
}
Also used : OutboundOverrideUtil.startServer(io.helidon.security.examples.outbound.OutboundOverrideUtil.startServer) Config(io.helidon.config.Config) OutboundOverrideUtil.sendError(io.helidon.security.examples.outbound.OutboundOverrideUtil.sendError) SecurityContext(io.helidon.security.SecurityContext) Principal(io.helidon.security.Principal) ServerRequest(io.helidon.webserver.ServerRequest) OutboundOverrideUtil.getSecurityContext(io.helidon.security.examples.outbound.OutboundOverrideUtil.getSecurityContext) CompletionStage(java.util.concurrent.CompletionStage) ServerResponse(io.helidon.webserver.ServerResponse) WebSecurity(io.helidon.security.integration.webserver.WebSecurity) Subject(io.helidon.security.Subject) Routing(io.helidon.webserver.Routing) OutboundOverrideUtil.createConfig(io.helidon.security.examples.outbound.OutboundOverrideUtil.createConfig) OutboundOverrideUtil.webTarget(io.helidon.security.examples.outbound.OutboundOverrideUtil.webTarget) HttpBasicAuthProvider(io.helidon.security.providers.httpauth.HttpBasicAuthProvider) Config(io.helidon.config.Config) OutboundOverrideUtil.createConfig(io.helidon.security.examples.outbound.OutboundOverrideUtil.createConfig) Routing(io.helidon.webserver.Routing) Subject(io.helidon.security.Subject)

Example 59 with Config

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

the class OutboundOverrideExample method startClientService.

static CompletionStage<Void> startClientService(int port) {
    Config config = createConfig("client-service");
    Routing routing = Routing.builder().register(WebSecurity.create(config.get("security"))).get("/override", OutboundOverrideExample::override).get("/propagate", OutboundOverrideExample::propagate).build();
    return startServer(routing, port, server -> clientPort = server.port());
}
Also used : Config(io.helidon.config.Config) OutboundOverrideUtil.createConfig(io.helidon.security.examples.outbound.OutboundOverrideUtil.createConfig) Routing(io.helidon.webserver.Routing)

Example 60 with Config

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

the class OutboundOverrideJwtExample method startServingService.

static CompletionStage<Void> startServingService(int port) {
    Config config = createConfig("serving-service-jwt");
    Routing routing = Routing.builder().register(WebSecurity.create(config.get("security"))).get("/hello", (req, res) -> {
        // This is the token. It should be bearer <signed JWT base64 encoded>
        req.headers().first("Authorization").ifPresent(System.out::println);
        res.send(req.context().get(SecurityContext.class).flatMap(SecurityContext::user).map(Subject::principal).map(Principal::getName).orElse("Anonymous"));
    }).build();
    return startServer(routing, port, server -> servingPort = server.port());
}
Also used : OutboundOverrideUtil.startServer(io.helidon.security.examples.outbound.OutboundOverrideUtil.startServer) Config(io.helidon.config.Config) OutboundOverrideUtil.sendError(io.helidon.security.examples.outbound.OutboundOverrideUtil.sendError) SecurityContext(io.helidon.security.SecurityContext) Principal(io.helidon.security.Principal) ServerRequest(io.helidon.webserver.ServerRequest) OutboundOverrideUtil.getSecurityContext(io.helidon.security.examples.outbound.OutboundOverrideUtil.getSecurityContext) CompletionStage(java.util.concurrent.CompletionStage) ServerResponse(io.helidon.webserver.ServerResponse) WebSecurity(io.helidon.security.integration.webserver.WebSecurity) Subject(io.helidon.security.Subject) Routing(io.helidon.webserver.Routing) OutboundOverrideUtil.createConfig(io.helidon.security.examples.outbound.OutboundOverrideUtil.createConfig) OutboundOverrideUtil.webTarget(io.helidon.security.examples.outbound.OutboundOverrideUtil.webTarget) JwtProvider(io.helidon.security.providers.jwt.JwtProvider) Config(io.helidon.config.Config) OutboundOverrideUtil.createConfig(io.helidon.security.examples.outbound.OutboundOverrideUtil.createConfig) Routing(io.helidon.webserver.Routing) Subject(io.helidon.security.Subject)

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