Search in sources :

Example 6 with RequestContext

use of com.netflix.zuul.context.RequestContext in project micro-service by Lovnx.

the class AccessFilter method run.

@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();
    log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString()));
    Object accessToken = request.getParameter("accessToken");
    if (accessToken == null) {
        log.warn("access token is empty");
        ctx.setSendZuulResponse(false);
        ctx.setResponseStatusCode(401);
        return null;
    }
    log.info("access token ok");
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RequestContext(com.netflix.zuul.context.RequestContext)

Example 7 with RequestContext

use of com.netflix.zuul.context.RequestContext in project jhipster-registry by jhipster.

the class JWTTokenRelayFilter method run.

@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    Set<String> headers = (Set<String>) ctx.get("ignoredHeaders");
    // JWT tokens should be relayed to the resource servers
    headers.remove("authorization");
    return null;
}
Also used : Set(java.util.Set) RequestContext(com.netflix.zuul.context.RequestContext)

Example 8 with RequestContext

use of com.netflix.zuul.context.RequestContext in project jhipster-registry by jhipster.

the class OAuth2TokenRelayFilter method run.

@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    // Add specific authorization headers for OAuth2
    ctx.addZuulRequestHeader(AUTHORIZATION_HEADER, AuthorizationHeaderUtil.getAuthorizationHeader());
    return null;
}
Also used : RequestContext(com.netflix.zuul.context.RequestContext)

Example 9 with RequestContext

use of com.netflix.zuul.context.RequestContext in project jhipster-registry by jhipster.

the class AccessControlFilter method run.

@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    ctx.setResponseStatusCode(HttpStatus.FORBIDDEN.value());
    if (ctx.getResponseBody() == null && !ctx.getResponseGZipped()) {
        ctx.setSendZuulResponse(false);
    }
    log.debug("Access Control: filtered unauthorized access on endpoint {}", ctx.getRequest().getRequestURI());
    return null;
}
Also used : RequestContext(com.netflix.zuul.context.RequestContext)

Example 10 with RequestContext

use of com.netflix.zuul.context.RequestContext in project jhipster-registry by jhipster.

the class SwaggerBasePathRewritingFilterTest method run_on_valid_response.

@Test
public void run_on_valid_response() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/service1" + DEFAULT_URL);
    RequestContext context = RequestContext.getCurrentContext();
    context.setRequest(request);
    MockHttpServletResponse response = new MockHttpServletResponse();
    context.setResponseGZipped(false);
    context.setResponse(response);
    InputStream in = IOUtils.toInputStream("{\"basePath\":\"/\"}", StandardCharsets.UTF_8);
    context.setResponseDataStream(in);
    filter.run();
    assertEquals("UTF-8", response.getCharacterEncoding());
    assertEquals("{\"basePath\":\"/service1\"}", context.getResponseBody());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) InputStream(java.io.InputStream) RequestContext(com.netflix.zuul.context.RequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

RequestContext (com.netflix.zuul.context.RequestContext)163 Test (org.junit.Test)59 HttpServletRequest (javax.servlet.http.HttpServletRequest)27 ZuulRoute (org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute)24 Before (org.junit.Before)23 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)22 Set (java.util.Set)10 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)9 ZuulException (com.netflix.zuul.exception.ZuulException)7 InputStream (java.io.InputStream)7 HashSet (java.util.HashSet)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 Route (org.springframework.cloud.netflix.zuul.filters.Route)7 ZuulProperties (org.springframework.cloud.netflix.zuul.filters.ZuulProperties)7 IOException (java.io.IOException)6 HttpServletRequestWrapper (com.netflix.zuul.http.HttpServletRequestWrapper)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 List (java.util.List)4 HttpHeaders (org.springframework.http.HttpHeaders)4 RateLimitCheck (com.giffing.bucket4j.spring.boot.starter.context.RateLimitCheck)3