Search in sources :

Example 11 with HttpChannel

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

the class ServerHandleInterceptor method getRequest.

@Override
protected Request getRequest(Object[] args) {
    final Object httpChannelObject = args[0];
    if (!(httpChannelObject instanceof HttpChannel)) {
        return null;
    }
    final HttpChannel<?> channel = (HttpChannel<?>) httpChannelObject;
    final Request request = channel.getRequest();
    return request;
}
Also used : HttpChannel(org.eclipse.jetty.server.HttpChannel) Request(org.eclipse.jetty.server.Request)

Example 12 with HttpChannel

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

the class DrillSpnegoAuthenticator method authenticateSession.

/**
 * Method to authenticate a user session using the SPNEGO token passed in AUTHORIZATION header of request.
 * @param request
 * @param response
 * @param mandatory
 * @return
 * @throws ServerAuthException
 */
private Authentication authenticateSession(ServletRequest request, ServletResponse response, boolean mandatory) throws ServerAuthException {
    final HttpServletRequest req = (HttpServletRequest) request;
    final HttpServletResponse res = (HttpServletResponse) response;
    final HttpSession session = req.getSession(true);
    // Defer the authentication if not mandatory.
    if (!mandatory) {
        return new DeferredAuthentication(this);
    }
    // Authentication is mandatory, get the Authorization header
    final String header = req.getHeader(HttpHeader.AUTHORIZATION.asString());
    // Authorization header is null, so send the 401 error code to client along with negotiate header
    if (header == null) {
        try {
            if (DeferredAuthentication.isDeferred(res)) {
                return Authentication.UNAUTHENTICATED;
            } else {
                res.setHeader(HttpHeader.WWW_AUTHENTICATE.asString(), HttpHeader.NEGOTIATE.asString());
                res.sendError(401);
                logger.debug("DrillSpnegoAuthenticator: Sending challenge to client {}", req.getRemoteAddr());
                return Authentication.SEND_CONTINUE;
            }
        } catch (IOException e) {
            logger.error("DrillSpnegoAuthenticator: Failed while sending challenge to client {}", req.getRemoteAddr(), e);
            throw new ServerAuthException(e);
        }
    }
    // Valid Authorization header received. Get the SPNEGO token sent by client and try to authenticate
    logger.debug("DrillSpnegoAuthenticator: Received NEGOTIATE Response back from client {}", req.getRemoteAddr());
    final String negotiateString = HttpHeader.NEGOTIATE.asString();
    if (header.startsWith(negotiateString)) {
        final String spnegoToken = header.substring(negotiateString.length() + 1);
        final UserIdentity user = this.login(null, spnegoToken, request);
        // redirect the request to the desired page after successful login
        if (user != null) {
            String newUri = (String) session.getAttribute("org.eclipse.jetty.security.form_URI");
            if (Strings.isNullOrEmpty(newUri)) {
                newUri = req.getContextPath();
                if (Strings.isNullOrEmpty(newUri)) {
                    newUri = WebServerConstants.WEBSERVER_ROOT_PATH;
                }
            }
            response.setContentLength(0);
            final HttpChannel channel = HttpChannel.getCurrentHttpChannel();
            final Response base_response = channel.getResponse();
            final Request base_request = channel.getRequest();
            final int redirectCode = base_request.getHttpVersion().getVersion() < HttpVersion.HTTP_1_1.getVersion() ? 302 : 303;
            try {
                base_response.sendRedirect(redirectCode, res.encodeRedirectURL(newUri));
            } catch (IOException e) {
                logger.error("DrillSpnegoAuthenticator: Failed while using the redirect URL {} from client {}", newUri, req.getRemoteAddr(), e);
                throw new ServerAuthException(e);
            }
            logger.debug("DrillSpnegoAuthenticator: Successfully authenticated this client session: {}", user.getUserPrincipal().getName());
            return new UserAuthentication(this.getAuthMethod(), user);
        }
    }
    logger.debug("DrillSpnegoAuthenticator: Authentication failed for client session: {}", req.getRemoteAddr());
    return Authentication.UNAUTHENTICATED;
}
Also used : HttpSession(javax.servlet.http.HttpSession) UserIdentity(org.eclipse.jetty.server.UserIdentity) Request(org.eclipse.jetty.server.Request) ServletRequest(javax.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) DeferredAuthentication(org.eclipse.jetty.security.authentication.DeferredAuthentication) IOException(java.io.IOException) ServerAuthException(org.eclipse.jetty.security.ServerAuthException) UserAuthentication(org.eclipse.jetty.security.UserAuthentication) HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(org.eclipse.jetty.server.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) HttpChannel(org.eclipse.jetty.server.HttpChannel)

Example 13 with HttpChannel

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

the class JettyHTTPDestination method getCurrentRequest.

private Request getCurrentRequest() {
    try {
        HttpConnection con = HttpConnection.getCurrentConnection();
        HttpChannel channel = con.getHttpChannel();
        return channel.getRequest();
    } catch (Throwable t) {
    // 
    }
    return null;
}
Also used : HttpConnection(org.eclipse.jetty.server.HttpConnection) HttpChannel(org.eclipse.jetty.server.HttpChannel)

Example 14 with HttpChannel

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

the class AthenzRequestLogTest method testAthenzRequestLogNullFields.

@Test
public void testAthenzRequestLogNullFields() throws Exception {
    AthenzRequestLog athenzRequestLog = new AthenzRequestLog(TEST_FILE);
    assertNotNull(athenzRequestLog);
    athenzRequestLog.start();
    Request request = Mockito.mock(Request.class);
    Response response = Mockito.mock(Response.class);
    // invalid ip so it should be ignored
    Mockito.when(request.getHeader(HttpHeader.X_FORWARDED_FOR.toString())).thenReturn("invalid-ip");
    Mockito.when(request.getRemoteAddr()).thenReturn("10.10.11.12");
    Mockito.when(request.getMethod()).thenReturn("GET");
    Mockito.when(request.getOriginalURI()).thenReturn("/original-uri");
    Mockito.when(request.getProtocol()).thenReturn("HTTP/1.1");
    Mockito.when(request.getContentLengthLong()).thenReturn(-1L);
    MetaData.Response metaResponse = Mockito.mock(MetaData.Response.class);
    Mockito.when(metaResponse.getStatus()).thenReturn(-1);
    Mockito.when(response.getCommittedMetaData()).thenReturn(metaResponse);
    HttpChannel httpChannel = Mockito.mock(HttpChannel.class);
    Mockito.when(httpChannel.getBytesWritten()).thenReturn(1234L);
    Mockito.when(response.getHttpChannel()).thenReturn(httpChannel);
    athenzRequestLog.log(request, response);
    athenzRequestLog.stop();
    File file = new File(TEST_FILE);
    final String data = new String(Files.readAllBytes(file.toPath()));
    assertTrue(data.startsWith("10.10.11.12 - - [01/Jan/1970:00:00:00 +0000] \"GET /original-uri HTTP/1.1\" -1 1234 \"-\" \"-\" -"), data);
    assertTrue(data.endsWith("Auth-None - -\n"), data);
    Files.delete(file.toPath());
}
Also used : Response(org.eclipse.jetty.server.Response) MetaData(org.eclipse.jetty.http.MetaData) Request(org.eclipse.jetty.server.Request) HttpChannel(org.eclipse.jetty.server.HttpChannel) File(java.io.File) Test(org.testng.annotations.Test)

Example 15 with HttpChannel

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

the class RoutingHandlerTest method routesRequestsToTheConnectorSpecificHandler.

@Test
void routesRequestsToTheConnectorSpecificHandler() throws Exception {
    final HttpChannel channel = mock(HttpChannel.class);
    when(channel.getConnector()).thenReturn(connector1);
    final Request baseRequest = mock(Request.class);
    when(baseRequest.getHttpChannel()).thenReturn(channel);
    final HttpServletRequest request = mock(HttpServletRequest.class);
    final HttpServletResponse response = mock(HttpServletResponse.class);
    handler.handle("target", baseRequest, request, response);
    verify(handler1).handle("target", baseRequest, request, response);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpChannel(org.eclipse.jetty.server.HttpChannel) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.jupiter.api.Test)

Aggregations

HttpChannel (org.eclipse.jetty.server.HttpChannel)15 Request (org.eclipse.jetty.server.Request)8 Response (org.eclipse.jetty.server.Response)6 File (java.io.File)4 MetaData (org.eclipse.jetty.http.MetaData)4 Test (org.testng.annotations.Test)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 SSLSession (javax.net.ssl.SSLSession)1 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