From 3544cdd5a19fed7382968a7609623a04e24b8a65 Mon Sep 17 00:00:00 2001 From: Alexander Wilhelmer Date: Mon, 19 Mar 2018 15:44:21 +0100 Subject: [PATCH 1/2] Add authorization to http sender --- .../logging/gelf/intern/sender/GelfHTTPSender.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfHTTPSender.java b/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfHTTPSender.java index 019e9e6f9..e6fa1587b 100644 --- a/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfHTTPSender.java +++ b/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfHTTPSender.java @@ -1,14 +1,15 @@ package biz.paluch.logging.gelf.intern.sender; +import biz.paluch.logging.gelf.intern.ErrorReporter; +import biz.paluch.logging.gelf.intern.GelfMessage; +import biz.paluch.logging.gelf.intern.GelfSender; +import com.sun.xml.internal.messaging.saaj.util.Base64; + import java.io.IOException; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; -import biz.paluch.logging.gelf.intern.ErrorReporter; -import biz.paluch.logging.gelf.intern.GelfMessage; -import biz.paluch.logging.gelf.intern.GelfSender; - /** * HTTP-based Gelf sender. This sender uses Java's HTTP client to {@code POST} JSON Gelf messages to an endpoint. * @@ -51,6 +52,10 @@ public boolean sendMessage(GelfMessage message) { try { connection = (HttpURLConnection) url.openConnection(); + if (url.getUserInfo() != null) { + String basicAuth = "Basic " + new String(Base64.encode(url.getUserInfo().getBytes())); + connection.setRequestProperty("Authorization", basicAuth); + } connection.setConnectTimeout(connectTimeoutMs); connection.setReadTimeout(readTimeoutMs); connection.setDoOutput(true); From 238804a62aef9913d04c27197bf72bc0ed77b60b Mon Sep 17 00:00:00 2001 From: Alexander Wilhelmer Date: Mon, 26 Mar 2018 09:43:58 +0200 Subject: [PATCH 2/2] Fixed Base64 HTTP with Apache commons --- pom.xml | 7 +++++++ .../paluch/logging/gelf/intern/sender/GelfHTTPSender.java | 4 +--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index c35e0cdd6..2768d6590 100644 --- a/pom.xml +++ b/pom.xml @@ -435,6 +435,13 @@ shrinkwrap-descriptors-impl-javaee test + + + commons-codec + commons-codec + 1.9 + + diff --git a/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfHTTPSender.java b/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfHTTPSender.java index e6fa1587b..43289d31a 100644 --- a/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfHTTPSender.java +++ b/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfHTTPSender.java @@ -3,13 +3,11 @@ import biz.paluch.logging.gelf.intern.ErrorReporter; import biz.paluch.logging.gelf.intern.GelfMessage; import biz.paluch.logging.gelf.intern.GelfSender; -import com.sun.xml.internal.messaging.saaj.util.Base64; import java.io.IOException; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; - /** * HTTP-based Gelf sender. This sender uses Java's HTTP client to {@code POST} JSON Gelf messages to an endpoint. * @@ -53,7 +51,7 @@ public boolean sendMessage(GelfMessage message) { connection = (HttpURLConnection) url.openConnection(); if (url.getUserInfo() != null) { - String basicAuth = "Basic " + new String(Base64.encode(url.getUserInfo().getBytes())); + String basicAuth = "Basic " + org.apache.commons.codec.binary.Base64.encodeBase64String(url.getUserInfo().getBytes()); connection.setRequestProperty("Authorization", basicAuth); } connection.setConnectTimeout(connectTimeoutMs);