Search in sources :

Example 1 with SimpleExecutionContext

use of io.gravitee.gateway.api.context.SimpleExecutionContext in project gravitee-api-management by gravitee-io.

the class TraceContextProcessorTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    context = new SimpleExecutionContext(request, response);
    Mockito.when(request.headers()).thenReturn(HttpHeaders.create());
    Mockito.when(response.headers()).thenReturn(HttpHeaders.create());
    Mockito.when(request.metrics()).thenReturn(Metrics.on(System.currentTimeMillis()).build());
}
Also used : SimpleExecutionContext(io.gravitee.gateway.api.context.SimpleExecutionContext) Before(org.junit.Before)

Example 2 with SimpleExecutionContext

use of io.gravitee.gateway.api.context.SimpleExecutionContext in project gravitee-access-management by gravitee-io.

the class PolicyChainHandlerImpl method prepareContext.

private void prepareContext(RoutingContext routingContext, Handler<AsyncResult<ExecutionContext>> handler) {
    try {
        io.vertx.core.http.HttpServerRequest request = routingContext.request().getDelegate();
        Request serverRequest = new VertxHttpServerRequest(request);
        Response serverResponse = new VertxHttpServerResponse(request, serverRequest.metrics());
        ExecutionContext simpleExecutionContext = new SimpleExecutionContext(serverRequest, serverResponse);
        ExecutionContext executionContext = executionContextFactory.create(simpleExecutionContext);
        // add current context attributes
        executionContext.getAttributes().putAll(getEvaluableAttributes(routingContext));
        handler.handle(Future.succeededFuture(executionContext));
    } catch (Exception ex) {
        handler.handle(Future.failedFuture(ex));
    }
}
Also used : VertxHttpServerResponse(io.gravitee.am.gateway.handler.common.vertx.core.http.VertxHttpServerResponse) Response(io.gravitee.gateway.api.Response) ExecutionContext(io.gravitee.gateway.api.ExecutionContext) SimpleExecutionContext(io.gravitee.gateway.api.context.SimpleExecutionContext) Request(io.gravitee.gateway.api.Request) HttpServerRequest(io.vertx.reactivex.core.http.HttpServerRequest) VertxHttpServerRequest(io.gravitee.am.gateway.handler.common.vertx.core.http.VertxHttpServerRequest) SimpleExecutionContext(io.gravitee.gateway.api.context.SimpleExecutionContext) VertxHttpServerResponse(io.gravitee.am.gateway.handler.common.vertx.core.http.VertxHttpServerResponse) VertxHttpServerRequest(io.gravitee.am.gateway.handler.common.vertx.core.http.VertxHttpServerRequest) PolicyChainException(io.gravitee.am.gateway.policy.PolicyChainException)

Example 3 with SimpleExecutionContext

use of io.gravitee.gateway.api.context.SimpleExecutionContext in project gravitee-access-management by gravitee-io.

the class TokenServiceImpl method createExecutionContext.

private ExecutionContext createExecutionContext(OAuth2Request request, Client client, User user) {
    ExecutionContext simpleExecutionContext = new SimpleExecutionContext(request, null);
    ExecutionContext executionContext = executionContextFactory.create(simpleExecutionContext);
    executionContext.setAttribute("client", new ClientProperties(client));
    if (user != null) {
        executionContext.setAttribute("user", new UserProperties(user));
    }
    // put authorization request in context
    if (request.getResponseType() != null && !request.getResponseType().isEmpty()) {
        executionContext.setAttribute("authorizationRequest", request);
    } else {
        executionContext.setAttribute("tokenRequest", request);
    }
    Object authFlowAttributes = request.getContext().get(ConstantKeys.AUTH_FLOW_CONTEXT_ATTRIBUTES_KEY);
    if (authFlowAttributes != null) {
        executionContext.setAttribute(ConstantKeys.AUTH_FLOW_CONTEXT_ATTRIBUTES_KEY, authFlowAttributes);
        request.getContext().remove(ConstantKeys.AUTH_FLOW_CONTEXT_ATTRIBUTES_KEY);
    }
    return executionContext;
}
Also used : ClientProperties(io.gravitee.am.model.safe.ClientProperties) ExecutionContext(io.gravitee.gateway.api.ExecutionContext) SimpleExecutionContext(io.gravitee.gateway.api.context.SimpleExecutionContext) UserProperties(io.gravitee.am.model.safe.UserProperties) SimpleExecutionContext(io.gravitee.gateway.api.context.SimpleExecutionContext)

Example 4 with SimpleExecutionContext

use of io.gravitee.gateway.api.context.SimpleExecutionContext in project gravitee-gateway by gravitee-io.

the class DefaultReactor method route.

@Override
public void route(Request serverRequest, Response serverResponse, Handler<ExecutionContext> handler) {
    LOGGER.debug("Receiving a request {} for path {}", serverRequest.id(), serverRequest.path());
    // Prepare invocation execution context
    ExecutionContext context = new SimpleExecutionContext(serverRequest, serverResponse);
    // Set gateway tenant
    gatewayConfiguration.tenant().ifPresent(tenant -> serverRequest.metrics().setTenant(tenant));
    // Set gateway zone
    gatewayConfiguration.zone().ifPresent(zone -> serverRequest.metrics().setZone(zone));
    // Prepare handler chain
    requestProcessorChainFactory.create().handler(ctx -> {
        HandlerEntrypoint entrypoint = entrypointResolver.resolve(ctx);
        if (entrypoint != null) {
            entrypoint.target().handler(context1 -> {
                // Ensure that response has been ended before going further
                context1.response().endHandler(avoid -> processResponse(context1, handler)).end();
            }).handle(ctx);
        } else {
            processNotFound(ctx, handler);
        }
    }).errorHandler(__ -> processResponse(context, handler)).exitHandler(__ -> processResponse(context, handler)).handle(context);
}
Also used : EventListener(io.gravitee.common.event.EventListener) ResponseProcessorChainFactory(io.gravitee.gateway.reactor.processor.ResponseProcessorChainFactory) Logger(org.slf4j.Logger) ExecutionContext(io.gravitee.gateway.api.ExecutionContext) LoggerFactory(org.slf4j.LoggerFactory) Event(io.gravitee.common.event.Event) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractService(io.gravitee.common.service.AbstractService) EntrypointResolver(io.gravitee.gateway.reactor.handler.EntrypointResolver) Handler(io.gravitee.gateway.api.handler.Handler) HandlerEntrypoint(io.gravitee.gateway.reactor.handler.HandlerEntrypoint) NotFoundProcessorChainFactory(io.gravitee.gateway.reactor.processor.NotFoundProcessorChainFactory) RequestProcessorChainFactory(io.gravitee.gateway.reactor.processor.RequestProcessorChainFactory) Response(io.gravitee.gateway.api.Response) Reactable(io.gravitee.gateway.reactor.Reactable) ReactorHandlerRegistry(io.gravitee.gateway.reactor.handler.ReactorHandlerRegistry) EventManager(io.gravitee.common.event.EventManager) Request(io.gravitee.gateway.api.Request) Reactor(io.gravitee.gateway.reactor.Reactor) SimpleExecutionContext(io.gravitee.gateway.api.context.SimpleExecutionContext) ReactorEvent(io.gravitee.gateway.reactor.ReactorEvent) GatewayConfiguration(io.gravitee.gateway.env.GatewayConfiguration) ExecutionContext(io.gravitee.gateway.api.ExecutionContext) SimpleExecutionContext(io.gravitee.gateway.api.context.SimpleExecutionContext) SimpleExecutionContext(io.gravitee.gateway.api.context.SimpleExecutionContext) HandlerEntrypoint(io.gravitee.gateway.reactor.handler.HandlerEntrypoint)

Example 5 with SimpleExecutionContext

use of io.gravitee.gateway.api.context.SimpleExecutionContext in project gravitee-gateway by gravitee-io.

the class PathParametersProcessorBenchmark method bench_processorIndex.

@Benchmark
public void bench_processorIndex() {
    ExecutionContext context = new SimpleExecutionContext(new SimpleRequest("/store/myStore/order/190783"), null);
    processorIndex.handle(context);
}
Also used : ExecutionContext(io.gravitee.gateway.api.ExecutionContext) SimpleExecutionContext(io.gravitee.gateway.api.context.SimpleExecutionContext) SimpleExecutionContext(io.gravitee.gateway.api.context.SimpleExecutionContext)

Aggregations

SimpleExecutionContext (io.gravitee.gateway.api.context.SimpleExecutionContext)17 ExecutionContext (io.gravitee.gateway.api.ExecutionContext)8 Before (org.junit.Before)8 ClientProperties (io.gravitee.am.model.safe.ClientProperties)3 UserProperties (io.gravitee.am.model.safe.UserProperties)3 HttpHeaders (io.gravitee.common.http.HttpHeaders)3 Event (io.gravitee.common.event.Event)2 EventListener (io.gravitee.common.event.EventListener)2 Request (io.gravitee.gateway.api.Request)2 Response (io.gravitee.gateway.api.Response)2 Metrics (io.gravitee.reporter.api.http.Metrics)2 InvalidTokenException (io.gravitee.am.common.exception.oauth2.InvalidTokenException)1 RequiredClaims (io.gravitee.am.common.exception.uma.RequiredClaims)1 UmaException (io.gravitee.am.common.exception.uma.UmaException)1 JWT (io.gravitee.am.common.jwt.JWT)1 GrantType (io.gravitee.am.common.oauth2.GrantType)1 Parameters (io.gravitee.am.common.oauth2.Parameters)1 TokenType (io.gravitee.am.common.oauth2.TokenType)1 UserAuthenticationManager (io.gravitee.am.gateway.handler.common.auth.user.UserAuthenticationManager)1 JWTService (io.gravitee.am.gateway.handler.common.jwt.JWTService)1