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