Added support for basic authentication

Closes #93
This commit is contained in:
Boaz Leskes 2014-02-03 16:07:24 +01:00
parent a5a22018f2
commit 6b13499e78
4 changed files with 24 additions and 5 deletions

View file

@ -27,6 +27,7 @@ import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.action.admin.indices.stats.ShardStats;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.Base64;
import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.io.Streams;
@ -288,23 +289,27 @@ public class ESExporter extends AbstractLifecycleComponent<ESExporter> implement
}
private HttpURLConnection openConnection(String method, String uri) {
return openConnection(method, uri, null);
private HttpURLConnection openConnection(String method, String path) {
return openConnection(method, path, null);
}
private HttpURLConnection openConnection(String method, String uri, String contentType) {
private HttpURLConnection openConnection(String method, String path, String contentType) {
int hostIndex = 0;
try {
for (; hostIndex < hosts.length; hostIndex++) {
String host = hosts[hostIndex];
try {
URL templateUrl = new URL("http://" + host + "/" + uri);
HttpURLConnection conn = (HttpURLConnection) templateUrl.openConnection();
URL url = new URL("http://" + host + "/" + path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod(method);
conn.setConnectTimeout(timeout);
if (contentType != null) {
conn.setRequestProperty("Content-Type", XContentType.SMILE.restContentType());
}
if (url.getUserInfo() != null) {
String basicAuth = "Basic " + Base64.encodeBytes(url.getUserInfo().getBytes("ISO-8859-1"));
conn.setRequestProperty("Authorization", basicAuth);
}
conn.setUseCaches(false);
if (method.equalsIgnoreCase("POST") || method.equalsIgnoreCase("PUT")) {
conn.setDoOutput(true);

9
docs/changes.asciidoc Normal file
View file

@ -0,0 +1,9 @@
== Change list
=== 1.0.2
- Kibana uses `window.location.protocol` (http or https) to make ES calls.
- Added support for basic authentication when sending data from agent. See <<configuration>>.
=== 1.0.1
- fixed an issue with usage statistics report.
- improve logging message when running on old Elasticsearch versions.

View file

@ -9,6 +9,10 @@
A list of hosts in `hostname:port` format to which statistics and events will
be sent. Data will be sent to the first host, but will failover to the next
host(s) if the first is not reachable. Defaults to `["localhost:9200"]`.
+
added[1.0.2] - HTTP Basic authentication credentials can be specified as part of the host name,
i.e., ["user:pwd@host:9200"]
`marvel.agent.enabled`::

View file

@ -23,3 +23,4 @@ include::install.asciidoc[]
include::configuration.asciidoc[]
include::changes.asciidoc[]