mirror of https://github.com/apache/nifi.git
NIFI-4528 The ref attribute in the request to view content sent by the client will now be inspected for the proxy context path. If found, it will be removed so the request can be successfully made within the cluster.
This closes #2228. Signed-off-by: Bryan Bende <bbende@apache.org>
This commit is contained in:
parent
e3482cc772
commit
d6744b9ee5
|
@ -56,7 +56,10 @@ public class ContentViewerController extends HttpServlet {
|
||||||
// 1.5kb - multiple of 12 (3 bytes = 4 base 64 encoded chars)
|
// 1.5kb - multiple of 12 (3 bytes = 4 base 64 encoded chars)
|
||||||
private final static int BUFFER_LENGTH = 1536;
|
private final static int BUFFER_LENGTH = 1536;
|
||||||
|
|
||||||
/**
|
private static final String PROXY_CONTEXT_PATH_HTTP_HEADER = "X-ProxyContextPath";
|
||||||
|
private static final String FORWARDED_CONTEXT_HTTP_HEADER = "X-Forwarded-Context";
|
||||||
|
|
||||||
|
/**
|
||||||
* Gets the content and defers to registered viewers to generate the markup.
|
* Gets the content and defers to registered viewers to generate the markup.
|
||||||
*
|
*
|
||||||
* @param request servlet request
|
* @param request servlet request
|
||||||
|
@ -301,11 +304,19 @@ public class ContentViewerController extends HttpServlet {
|
||||||
final String ref = request.getParameter("ref");
|
final String ref = request.getParameter("ref");
|
||||||
final String clientId = request.getParameter("clientId");
|
final String clientId = request.getParameter("clientId");
|
||||||
|
|
||||||
|
final UriBuilder refUriBuilder = UriBuilder.fromUri(ref);
|
||||||
|
|
||||||
// base the data ref on the request parameter but ensure the scheme is based off the incoming request...
|
// base the data ref on the request parameter but ensure the scheme is based off the incoming request...
|
||||||
// this is necessary for scenario's where the NiFi instance is behind a proxy running a different scheme
|
// this is necessary for scenario's where the NiFi instance is behind a proxy running a different scheme
|
||||||
final URI refUri = UriBuilder.fromUri(ref)
|
refUriBuilder.scheme(request.getScheme());
|
||||||
.scheme(request.getScheme())
|
|
||||||
.build();
|
// If there is path context from a proxy, remove it since this request will be used inside the cluster
|
||||||
|
final String proxyContextPath = getFirstHeaderValue(request, PROXY_CONTEXT_PATH_HTTP_HEADER, FORWARDED_CONTEXT_HTTP_HEADER);
|
||||||
|
if (StringUtils.isNotBlank(proxyContextPath)) {
|
||||||
|
refUriBuilder.replacePath(StringUtils.substringAfter(UriBuilder.fromUri(ref).build().getPath(), proxyContextPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
final URI refUri = refUriBuilder.build();
|
||||||
|
|
||||||
final String query = refUri.getQuery();
|
final String query = refUri.getQuery();
|
||||||
|
|
||||||
|
@ -343,4 +354,29 @@ public class ContentViewerController extends HttpServlet {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value for the first key discovered when inspecting the current request. Will
|
||||||
|
* return null if there are no keys specified or if none of the specified keys are found.
|
||||||
|
*
|
||||||
|
* @param keys http header keys
|
||||||
|
* @return the value for the first key found
|
||||||
|
*/
|
||||||
|
private String getFirstHeaderValue(HttpServletRequest httpServletRequest, final String... keys) {
|
||||||
|
if (keys == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (final String key : keys) {
|
||||||
|
final String value = httpServletRequest.getHeader(key);
|
||||||
|
|
||||||
|
// if we found an entry for this key, return the value
|
||||||
|
if (value != null) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// unable to find any matching keys
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue