infobip.api.config.BasicAuthConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of infobip-api-java-client Show documentation
Show all versions of infobip-api-java-client Show documentation
API client in Java for Infobip's API (http://dev.infobip.com/).
package infobip.api.config;
import javax.xml.bind.DatatypeConverter;
public class BasicAuthConfiguration extends Configuration {
private final String username;
private final String password;
public BasicAuthConfiguration(String baseUrl, String username, String password) {
this.baseUrl = baseUrl;
this.username = username;
this.password = password;
}
public BasicAuthConfiguration(String username, String password) {
this.baseUrl = "https://api.infobip.com";
this.username = username;
this.password = password;
}
@Override
public String getAuthorizationHeader() {
return "Basic " + encodeBase64();
}
private String encodeBase64() {
String userPass = username + ":" + password;
return DatatypeConverter.printBase64Binary(userPass.getBytes());
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
}