diff --git a/client/src/main/java/io/confluent/kafka/schemaregistry/client/rest/RestService.java b/client/src/main/java/io/confluent/kafka/schemaregistry/client/rest/RestService.java index c0b4637f939..25ac000ff4d 100644 --- a/client/src/main/java/io/confluent/kafka/schemaregistry/client/rest/RestService.java +++ b/client/src/main/java/io/confluent/kafka/schemaregistry/client/rest/RestService.java @@ -43,6 +43,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.xml.bind.DatatypeConverter; /** * Rest access layer for sending requests to the schema registry. @@ -132,9 +133,13 @@ private T sendHttpRequest(String requestUrl, String method, byte[] requestBo HttpURLConnection connection = null; try { URL url = new URL(requestUrl); + String userInfo = url.getUserInfo(); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod(method); - + if (userInfo != null) { + String authHeader = DatatypeConverter.printBase64Binary(userInfo.getBytes()); + connection.setRequestProperty("Authorization", "Basic " + authHeader); + } // connection.getResponseCode() implicitly calls getInputStream, so always set to true. // On the other hand, leaving this out breaks nothing. connection.setDoInput(true);