com.bandwidth.WebRtcBasicAuthManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bandwidth-sdk Show documentation
Show all versions of bandwidth-sdk Show documentation
The official client SDK for Bandwidth's Voice, Messaging, MFA, and WebRTC APIs
/*
* BandwidthLib
*
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
package com.bandwidth;
import com.bandwidth.http.request.HttpRequest;
import java.util.Base64;
import java.util.concurrent.CompletableFuture;
/**
* Utility class for authorization and token management.
*/
public class WebRtcBasicAuthManager implements AuthManager, WebRtcBasicAuthCredentials {
private String basicAuthUserName;
private String basicAuthPassword;
/**
* Constructor.
* @param username String value for username.
* @param password String value for password.
*/
public WebRtcBasicAuthManager(String username, String password) {
this.basicAuthUserName = username;
this.basicAuthPassword = password;
}
/**
* String value for basicAuthUserName.
* @return basicAuthUserName
*/
public String getBasicAuthUserName() {
return basicAuthUserName;
}
/**
* String value for basicAuthPassword.
* @return basicAuthPassword
*/
public String getBasicAuthPassword() {
return basicAuthPassword;
}
/**
* Checks if provided credentials matched with existing ones.
* @param basicAuthUserName String value for credentials.
* @param basicAuthPassword String value for credentials.
* @return true if credentials matched.
*/
public boolean equals(String basicAuthUserName, String basicAuthPassword) {
return basicAuthUserName.equals(getBasicAuthUserName())
&& basicAuthPassword.equals(getBasicAuthPassword());
}
/**
* Converts this WebRtcBasicAuthManager into string format.
* @return String representation of this class
*/
@Override
public String toString() {
return "WebRtcBasicAuthManager [" + "basicAuthUserName=" + basicAuthUserName
+ ", basicAuthPassword=" + basicAuthPassword + "]";
}
/**
* Adds authentication to the given HttpRequest.
*/
public HttpRequest apply(HttpRequest httpRequest) {
String authCredentials = basicAuthUserName + ":" + basicAuthPassword;
httpRequest.getHeaders().add("Authorization", "Basic " + Base64.getEncoder().encodeToString(authCredentials.getBytes()));
return httpRequest;
}
/**
* Asynchronously adds authentication to the given HttpRequest.
*/
public CompletableFuture applyAsync(HttpRequest httpRequest) {
String authCredentials = basicAuthUserName + ":" + basicAuthPassword;
httpRequest.getHeaders().add("Authorization", "Basic " + Base64.getEncoder().encodeToString(authCredentials.getBytes()));
return CompletableFuture.completedFuture(httpRequest);
}
}