use of org.eclipse.jetty.util.Attributes in project druid by druid-io.
the class KerberosJettyHttpClientProvider method get.
@Override
public HttpClient get() {
final HttpClient httpClient = delegateProvider.get();
httpClient.getAuthenticationStore().addAuthentication(new Authentication() {
@Override
public boolean matches(String type, URI uri, String realm) {
return true;
}
@Override
public Result authenticate(final Request request, ContentResponse response, Authentication.HeaderInfo headerInfo, Attributes context) {
return new Result() {
@Override
public URI getURI() {
return request.getURI();
}
@Override
public void apply(Request request) {
try {
// No need to set cookies as they are handled by Jetty Http Client itself.
URI uri = request.getURI();
if (DruidKerberosUtil.needToSendCredentials(httpClient.getCookieStore(), uri)) {
log.debug("No Auth Cookie found for URI[%s]. Existing Cookies[%s] Authenticating... ", uri, httpClient.getCookieStore().getCookies());
final String host = request.getHost();
DruidKerberosUtil.authenticateIfRequired(config);
UserGroupInformation currentUser = UserGroupInformation.getCurrentUser();
String challenge = currentUser.doAs(new PrivilegedExceptionAction<String>() {
@Override
public String run() throws Exception {
return DruidKerberosUtil.kerberosChallenge(host);
}
});
request.getHeaders().add(HttpHeaders.Names.AUTHORIZATION, "Negotiate " + challenge);
} else {
log.debug("Found Auth Cookie found for URI[%s].", uri);
}
} catch (Throwable e) {
Throwables.propagate(e);
}
}
};
}
});
return httpClient;
}
use of org.eclipse.jetty.util.Attributes in project jetty.project by eclipse.
the class ContextHandlerMBean method setContextAttribute.
@ManagedOperation(value = "Set context attribute", impact = "ACTION")
public void setContextAttribute(@Name(value = "name", description = "attribute name") String name, @Name(value = "value", description = "attribute value") Object value) {
Attributes attrs = ((ContextHandler) _managed).getAttributes();
attrs.setAttribute(name, value);
}
use of org.eclipse.jetty.util.Attributes in project jetty.project by eclipse.
the class Dispatcher method include.
@Override
public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException {
Request baseRequest = Request.getBaseRequest(request);
if (!(request instanceof HttpServletRequest))
request = new ServletRequestHttpWrapper(request);
if (!(response instanceof HttpServletResponse))
response = new ServletResponseHttpWrapper(response);
final DispatcherType old_type = baseRequest.getDispatcherType();
final Attributes old_attr = baseRequest.getAttributes();
final MultiMap<String> old_query_params = baseRequest.getQueryParameters();
try {
baseRequest.setDispatcherType(DispatcherType.INCLUDE);
baseRequest.getResponse().include();
if (_named != null) {
_contextHandler.handle(_named, baseRequest, (HttpServletRequest) request, (HttpServletResponse) response);
} else {
IncludeAttributes attr = new IncludeAttributes(old_attr);
attr._requestURI = _uri.getPath();
attr._contextPath = _contextHandler.getContextPath();
// set by ServletHandler
attr._servletPath = null;
attr._pathInfo = _pathInContext;
attr._query = _uri.getQuery();
if (attr._query != null)
baseRequest.mergeQueryParameters(baseRequest.getQueryString(), attr._query, false);
baseRequest.setAttributes(attr);
_contextHandler.handle(_pathInContext, baseRequest, (HttpServletRequest) request, (HttpServletResponse) response);
}
} finally {
baseRequest.setAttributes(old_attr);
baseRequest.getResponse().included();
baseRequest.setQueryParameters(old_query_params);
baseRequest.resetParameters();
baseRequest.setDispatcherType(old_type);
}
}
use of org.eclipse.jetty.util.Attributes in project jetty.project by eclipse.
the class Dispatcher method forward.
protected void forward(ServletRequest request, ServletResponse response, DispatcherType dispatch) throws ServletException, IOException {
Request baseRequest = Request.getBaseRequest(request);
Response base_response = baseRequest.getResponse();
base_response.resetForForward();
if (!(request instanceof HttpServletRequest))
request = new ServletRequestHttpWrapper(request);
if (!(response instanceof HttpServletResponse))
response = new ServletResponseHttpWrapper(response);
final HttpURI old_uri = baseRequest.getHttpURI();
final String old_context_path = baseRequest.getContextPath();
final String old_servlet_path = baseRequest.getServletPath();
final String old_path_info = baseRequest.getPathInfo();
final MultiMap<String> old_query_params = baseRequest.getQueryParameters();
final Attributes old_attr = baseRequest.getAttributes();
final DispatcherType old_type = baseRequest.getDispatcherType();
try {
baseRequest.setDispatcherType(dispatch);
if (_named != null) {
_contextHandler.handle(_named, baseRequest, (HttpServletRequest) request, (HttpServletResponse) response);
} else {
ForwardAttributes attr = new ForwardAttributes(old_attr);
//for queryString is allowed to be null, but cannot be null for the other values.
if (old_attr.getAttribute(FORWARD_REQUEST_URI) != null) {
attr._pathInfo = (String) old_attr.getAttribute(FORWARD_PATH_INFO);
attr._query = (String) old_attr.getAttribute(FORWARD_QUERY_STRING);
attr._requestURI = (String) old_attr.getAttribute(FORWARD_REQUEST_URI);
attr._contextPath = (String) old_attr.getAttribute(FORWARD_CONTEXT_PATH);
attr._servletPath = (String) old_attr.getAttribute(FORWARD_SERVLET_PATH);
} else {
attr._pathInfo = old_path_info;
attr._query = old_uri.getQuery();
attr._requestURI = old_uri.getPath();
attr._contextPath = old_context_path;
attr._servletPath = old_servlet_path;
}
HttpURI uri = new HttpURI(old_uri.getScheme(), old_uri.getHost(), old_uri.getPort(), _uri.getPath(), _uri.getParam(), _uri.getQuery(), _uri.getFragment());
baseRequest.setHttpURI(uri);
baseRequest.setContextPath(_contextHandler.getContextPath());
baseRequest.setServletPath(null);
baseRequest.setPathInfo(_pathInContext);
if (_uri.getQuery() != null || old_uri.getQuery() != null)
baseRequest.mergeQueryParameters(old_uri.getQuery(), _uri.getQuery(), true);
baseRequest.setAttributes(attr);
_contextHandler.handle(_pathInContext, baseRequest, (HttpServletRequest) request, (HttpServletResponse) response);
if (!baseRequest.getHttpChannelState().isAsync())
commitResponse(response, baseRequest);
}
} finally {
baseRequest.setHttpURI(old_uri);
baseRequest.setContextPath(old_context_path);
baseRequest.setServletPath(old_servlet_path);
baseRequest.setPathInfo(old_path_info);
baseRequest.setQueryParameters(old_query_params);
baseRequest.resetParameters();
baseRequest.setAttributes(old_attr);
baseRequest.setDispatcherType(old_type);
}
}
use of org.eclipse.jetty.util.Attributes in project jetty.project by eclipse.
the class ContextHandlerMBean method removeContextAttribute.
@ManagedOperation(value = "Remove context attribute", impact = "ACTION")
public void removeContextAttribute(@Name(value = "name", description = "attribute name") String name) {
Attributes attrs = ((ContextHandler) _managed).getAttributes();
attrs.removeAttribute(name);
}
Aggregations