Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard: custom authorization header #336

Merged
merged 1 commit into from
Dec 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ public ProxyStreamServlet() {
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String origin = request.getParameter("origin");
String authorization = request.getParameter("authorization");
if (origin == null) {
response.setStatus(500);
response.getWriter().println("Required parameter 'origin' missing. Example: 107.20.175.135:7001");
return;
}
origin = origin.trim();

HttpGet httpget = null;
InputStream is = null;
boolean hasFirstParameter = false;
Expand All @@ -60,7 +61,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
@SuppressWarnings("unchecked")
Map<String, String[]> params = request.getParameterMap();
for (String key : params.keySet()) {
if (!key.equals("origin")) {
if (!key.equals("origin") && !key.equals("authorization")) {
String[] values = params.get(key);
String value = values[0].trim();
if (hasFirstParameter) {
Expand All @@ -76,6 +77,9 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
logger.info("\n\nProxy opening connection to: " + proxyUrl + "\n\n");
try {
httpget = new HttpGet(proxyUrl);
if (authorization != null) {
httpget.addHeader("Authorization", authorization);
}
HttpClient client = ProxyConnectionManager.httpClient;
HttpResponse httpResponse = client.execute(httpget);
int statusCode = httpResponse.getStatusLine().getStatusCode();
Expand Down
6 changes: 5 additions & 1 deletion hystrix-dashboard/src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
if($('#title').val().length > 0) {
url += "&title=" + encodeURIComponent($('#title').val());
}
if($('#authorization').val().length > 0) {
url += "&authorization=" + encodeURIComponent($('#authorization').val());
}
location.href= url;
} else {
$('#message').html("The 'stream' value is required.");
Expand All @@ -44,7 +47,8 @@ <h2>Hystrix Dashboard</h2>
<br><br>
Delay: <input id="delay" type="textfield" size="10" placeholder="2000"></input>ms
&nbsp;&nbsp;&nbsp;&nbsp;
Title: <input id="title" type="textfield" size="60" placeholder="Example Hystrix App"></input><br>
Title: <input id="title" type="textfield" size="60" placeholder="Example Hystrix App"></input><br><br>
Authorization: <input id="authorization" type="textfield" size="60" placeholder="Basic Zm9vOmJhcg=="></input><br>
<br>
<button onclick="sendToMonitor()">Monitor Stream</button>
<br><br>
Expand Down
13 changes: 9 additions & 4 deletions hystrix-dashboard/src/main/webapp/monitor/monitor.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,20 @@ <h2><span id="title_name"></span></h2>
if(getUrlVars()["delay"] != undefined) {
stream = stream + "&delay=" + getUrlVars()["delay"];
}

var commandStream = "../proxy.stream?origin=" + stream;
var poolStream = "../proxy.stream?origin=" + stream;


if(getUrlVars()["title"] != undefined) {
$('#title_name').html("Hystrix Stream: " + decodeURIComponent(getUrlVars()["title"]))
} else {
$('#title_name').html("Hystrix Stream: " + decodeURIComponent(stream))
}

//do not show authorization in stream title
if(getUrlVars()["authorization"] != undefined) {
stream = stream + "&authorization=" + getUrlVars()["authorization"];
}

var commandStream = "../proxy.stream?origin=" + stream;
var poolStream = "../proxy.stream?origin=" + stream;
}

$(window).load(function() { // within load with a setTimeout to prevent the infinite spinner
Expand Down