aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSmokowski, Kevin (ks6305) <kevin.smokowski@att.com>2019-10-29 15:54:42 +0000
committerKevin Smokowski <kevin.smokowski@att.com>2019-10-30 13:04:59 +0000
commita4e98021b301f4146fd45e7089d8749f3b8448b9 (patch)
tree96a6df9b323014e97f393770e96a22c7998387aa
parent53b6e1a6cea267a6ad48c1accc3371dd6dab4112 (diff)
update getBasicAuthUserName
prevent excess error throwing in getBasicAuthUserName Issue-ID: LOG-1184 Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com> Change-Id: I226185ef19525095dbb9e5f480e43bd7b087bf8f
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java2
-rw-r--r--reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java12
2 files changed, 13 insertions, 1 deletions
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java
index d0caa46..a900968 100644
--- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java
@@ -248,7 +248,7 @@ public class MDCSetup {
protected String getBasicAuthUserName(SimpleMap headers) {
String encodedAuthorizationValue = headers.get(HttpHeaders.AUTHORIZATION);
- if (encodedAuthorizationValue != null) {
+ if (encodedAuthorizationValue != null && encodedAuthorizationValue.startsWith("Basic")) {
try {
// This will strip the word Basic and single space
encodedAuthorizationValue = encodedAuthorizationValue.substring(6);
diff --git a/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java
index 22ab9c3..bdf8bd0 100644
--- a/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java
+++ b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java
@@ -191,6 +191,18 @@ public class MDCSetupTest extends MDCSetup {
}
@Test
+ public void setMDCPartnerNameBearerToken() {
+ MultivaluedMap<String, String> headerMap = new MultivaluedHashMap<>();
+ String value = "Bearer some-compex-token";
+ headerMap.putSingle(HttpHeaders.AUTHORIZATION, value);
+ SimpleMap headers = new SimpleJaxrsHeadersMap(headerMap);
+
+ setMDCPartnerName(headers);
+
+ assertEquals(Constants.DefaultValues.UNKNOWN, MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME));
+ }
+
+ @Test
public void setMDCPartnerNameFromBasicAuth() {
MultivaluedMap<String, String> headerMap = new MultivaluedHashMap<>();
String value = "Basic dXNlcjpwYXNz"; // decodes to user:pass