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