Search in sources :

Example 1 with HttpChannel

use of org.eclipse.jetty.server.HttpChannel in project jetty.project by eclipse.

the class IPAccessHandler method handle.

/* ------------------------------------------------------------ */
/**
     * Checks the incoming request against the whitelist and blacklist
     *
     * @see org.eclipse.jetty.server.handler.HandlerWrapper#handle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    // Get the real remote IP (not the one set by the forwarded headers (which may be forged))
    HttpChannel channel = baseRequest.getHttpChannel();
    if (channel != null) {
        EndPoint endp = channel.getEndPoint();
        if (endp != null) {
            InetSocketAddress address = endp.getRemoteAddress();
            if (address != null && !isAddrUriAllowed(address.getHostString(), baseRequest.getPathInfo())) {
                response.sendError(HttpStatus.FORBIDDEN_403);
                baseRequest.setHandled(true);
                return;
            }
        }
    }
    getHandler().handle(target, baseRequest, request, response);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) HttpChannel(org.eclipse.jetty.server.HttpChannel) EndPoint(org.eclipse.jetty.io.EndPoint)

Example 2 with HttpChannel

use of org.eclipse.jetty.server.HttpChannel in project jetty.project by eclipse.

the class SecuredRedirectHandler method handle.

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    HttpChannel channel = baseRequest.getHttpChannel();
    if (baseRequest.isSecure() || (channel == null)) {
        // nothing to do
        return;
    }
    HttpConfiguration httpConfig = channel.getHttpConfiguration();
    if (httpConfig == null) {
        // no config, show error
        response.sendError(HttpStatus.FORBIDDEN_403, "No http configuration available");
        return;
    }
    if (httpConfig.getSecurePort() > 0) {
        String scheme = httpConfig.getSecureScheme();
        int port = httpConfig.getSecurePort();
        String url = URIUtil.newURI(scheme, baseRequest.getServerName(), port, baseRequest.getRequestURI(), baseRequest.getQueryString());
        response.setContentLength(0);
        response.sendRedirect(url);
    } else {
        response.sendError(HttpStatus.FORBIDDEN_403, "Not Secure");
    }
    baseRequest.setHandled(true);
}
Also used : HttpChannel(org.eclipse.jetty.server.HttpChannel) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 3 with HttpChannel

use of org.eclipse.jetty.server.HttpChannel in project incubator-skywalking by apache.

the class HandleInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    HttpChannel httpChannel = (HttpChannel) allArguments[0];
    HttpServletRequest servletRequest = httpChannel.getRequest();
    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue(servletRequest.getHeader(next.getHeadKey()));
    }
    AbstractSpan span = ContextManager.createEntrySpan(servletRequest.getRequestURI(), contextCarrier);
    Tags.URL.set(span, servletRequest.getRequestURL().toString());
    Tags.HTTP.METHOD.set(span, servletRequest.getMethod());
    span.setComponent(ComponentsDefine.JETTY_SERVER);
    SpanLayer.asHttp(span);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) HttpChannel(org.eclipse.jetty.server.HttpChannel) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 4 with HttpChannel

use of org.eclipse.jetty.server.HttpChannel in project incubator-skywalking by apache.

the class HandleInterceptor method afterMethod.

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
    HttpChannel httpChannel = (HttpChannel) allArguments[0];
    HttpServletResponse servletResponse = httpChannel.getResponse();
    AbstractSpan span = ContextManager.activeSpan();
    if (servletResponse.getStatus() >= 400) {
        span.errorOccurred();
        Tags.STATUS_CODE.set(span, Integer.toString(servletResponse.getStatus()));
    }
    ContextManager.stopSpan();
    return ret;
}
Also used : HttpChannel(org.eclipse.jetty.server.HttpChannel) HttpServletResponse(javax.servlet.http.HttpServletResponse) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 5 with HttpChannel

use of org.eclipse.jetty.server.HttpChannel in project neo4j by neo4j.

the class HttpsRequestCustomizerTest method newRequest.

private static Request newRequest() {
    HttpChannel channel = mock(HttpChannel.class);
    Response response = new Response(channel, mock(HttpOutput.class));
    Request request = new Request(channel, mock(HttpInput.class));
    when(channel.getRequest()).thenReturn(request);
    when(channel.getResponse()).thenReturn(response);
    return request;
}
Also used : Response(org.eclipse.jetty.server.Response) HttpInput(org.eclipse.jetty.server.HttpInput) HttpChannel(org.eclipse.jetty.server.HttpChannel) Request(org.eclipse.jetty.server.Request) HttpOutput(org.eclipse.jetty.server.HttpOutput)

Aggregations

HttpChannel (org.eclipse.jetty.server.HttpChannel)11 Request (org.eclipse.jetty.server.Request)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)2 EndPoint (org.eclipse.jetty.io.EndPoint)2 Response (org.eclipse.jetty.server.Response)2 AsyncEvent (javax.servlet.AsyncEvent)1 AsyncListener (javax.servlet.AsyncListener)1 ServletRequest (javax.servlet.ServletRequest)1 ServletResponse (javax.servlet.ServletResponse)1 HttpSession (javax.servlet.http.HttpSession)1 CarrierItem (org.apache.skywalking.apm.agent.core.context.CarrierItem)1 ContextCarrier (org.apache.skywalking.apm.agent.core.context.ContextCarrier)1 ServerAuthException (org.eclipse.jetty.security.ServerAuthException)1 UserAuthentication (org.eclipse.jetty.security.UserAuthentication)1 DeferredAuthentication (org.eclipse.jetty.security.authentication.DeferredAuthentication)1 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)1