Search in sources :

Example 1 with ServerRequest

use of io.helidon.webserver.ServerRequest in project helidon by oracle.

the class OutboundOverrideExample method propagate.

private static void propagate(ServerRequest req, ServerResponse res) {
    SecurityContext context = getSecurityContext(req);
    webTarget(servingPort).request(String.class).thenAccept(result -> res.send("You are: " + context.userName() + ", backend service returned: " + result + "\n")).exceptionally(throwable -> sendError(throwable, res));
}
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) SecurityContext(io.helidon.security.SecurityContext) OutboundOverrideUtil.getSecurityContext(io.helidon.security.examples.outbound.OutboundOverrideUtil.getSecurityContext)

Example 2 with ServerRequest

use of io.helidon.webserver.ServerRequest in project helidon by oracle.

the class OutboundOverrideJwtExample method propagate.

private static void propagate(ServerRequest req, ServerResponse res) {
    SecurityContext context = getSecurityContext(req);
    webTarget(servingPort).request(String.class).thenAccept(result -> res.send("You are: " + context.userName() + ", backend service returned: " + result)).exceptionally(throwable -> sendError(throwable, res));
}
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) SecurityContext(io.helidon.security.SecurityContext) OutboundOverrideUtil.getSecurityContext(io.helidon.security.examples.outbound.OutboundOverrideUtil.getSecurityContext)

Example 3 with ServerRequest

use of io.helidon.webserver.ServerRequest in project helidon by oracle.

the class OutboundOverrideJwtExample method override.

private static void override(ServerRequest req, ServerResponse res) {
    SecurityContext context = getSecurityContext(req);
    webTarget(servingPort).property(JwtProvider.EP_PROPERTY_OUTBOUND_USER, "jill").request(String.class).thenAccept(result -> res.send("You are: " + context.userName() + ", backend service returned: " + result)).exceptionally(throwable -> sendError(throwable, res));
}
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) SecurityContext(io.helidon.security.SecurityContext) OutboundOverrideUtil.getSecurityContext(io.helidon.security.examples.outbound.OutboundOverrideUtil.getSecurityContext)

Example 4 with ServerRequest

use of io.helidon.webserver.ServerRequest in project helidon by oracle.

the class ObjectStorageService method upload.

private void upload(ServerRequest req, ServerResponse res) {
    OptionalLong contentLength = req.headers().contentLength();
    if (contentLength.isEmpty()) {
        req.content().forEach(DataChunk::release);
        res.status(Http.Status.BAD_REQUEST_400).send("Content length must be defined");
        return;
    }
    String objectName = req.path().param("file-name");
    PutObject.Request request = PutObject.Request.builder().objectName(objectName).bucket(bucketName).contentLength(contentLength.getAsLong());
    req.headers().contentType().ifPresent(request::requestMediaType);
    objectStorage.putObject(request, req.content()).forSingle(response -> res.send(response.requestId())).exceptionally(res::send);
}
Also used : DeleteObject(io.helidon.integrations.oci.objectstorage.DeleteObject) DataChunk(io.helidon.common.http.DataChunk) RenameObject(io.helidon.integrations.oci.objectstorage.RenameObject) ServerRequest(io.helidon.webserver.ServerRequest) GetObject(io.helidon.integrations.oci.objectstorage.GetObject) OptionalLong(java.util.OptionalLong) PutObject(io.helidon.integrations.oci.objectstorage.PutObject) GetObjectRx(io.helidon.integrations.oci.objectstorage.GetObjectRx) OciObjectStorageRx(io.helidon.integrations.oci.objectstorage.OciObjectStorageRx) ServerResponse(io.helidon.webserver.ServerResponse) Optional(java.util.Optional) Service(io.helidon.webserver.Service) Http(io.helidon.common.http.Http) Routing(io.helidon.webserver.Routing) OptionalLong(java.util.OptionalLong) DataChunk(io.helidon.common.http.DataChunk) PutObject(io.helidon.integrations.oci.objectstorage.PutObject)

Example 5 with ServerRequest

use of io.helidon.webserver.ServerRequest in project helidon by oracle.

the class MpTracingContextFilter method filter.

@Override
public void filter(ContainerRequestContext requestContext) {
    ServerRequest serverRequest = this.request.get();
    Tracer tracer = serverRequest.tracer();
    Optional<SpanContext> parentSpan = serverRequest.spanContext();
    boolean clientEnabled = config.getOptionalValue("tracing.client.enabled", Boolean.class).orElse(true);
    TracingContext tracingContext = TracingContext.create(tracer, serverRequest.headers().toMap(), clientEnabled);
    parentSpan.ifPresent(tracingContext::parentSpan);
    Contexts.context().ifPresent(ctx -> ctx.register(tracingContext));
}
Also used : TracingContext(io.helidon.tracing.jersey.client.internal.TracingContext) SpanContext(io.opentracing.SpanContext) Tracer(io.opentracing.Tracer) ServerRequest(io.helidon.webserver.ServerRequest)

Aggregations

ServerRequest (io.helidon.webserver.ServerRequest)38 ServerResponse (io.helidon.webserver.ServerResponse)35 Routing (io.helidon.webserver.Routing)23 Logger (java.util.logging.Logger)17 JsonObject (jakarta.json.JsonObject)13 Config (io.helidon.config.Config)12 Map (java.util.Map)12 Service (io.helidon.webserver.Service)11 Json (jakarta.json.Json)11 Optional (java.util.Optional)11 Test (org.junit.jupiter.api.Test)11 Single (io.helidon.common.reactive.Single)10 DbClient (io.helidon.dbclient.DbClient)10 SecurityContext (io.helidon.security.SecurityContext)9 Pokemon (io.helidon.tests.integration.dbclient.appl.model.Pokemon)9 AppResponse (io.helidon.tests.integration.tools.service.AppResponse)9 RemoteTestException (io.helidon.tests.integration.tools.service.RemoteTestException)9 List (java.util.List)9 Http (io.helidon.common.http.Http)8 AbstractService (io.helidon.tests.integration.dbclient.appl.AbstractService)8