Allow omitting username/password for HTTP basic auth

This commit is contained in:
xhh
2015-05-29 11:55:48 +08:00
parent e10e1f5249
commit 6a6473ede3
3 changed files with 20 additions and 3 deletions

View File

@@ -27,8 +27,9 @@ public class HttpBasicAuth implements Authentication {
@Override
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
try {
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary((username + ":" + password).getBytes("UTF-8")));
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}