public class BasicAuthenticationInterceptor extends Object implements ClientHttpRequestInterceptor
ClientHttpRequestInterceptor
to apply a given HTTP Basic Authentication
username/password pair, unless a custom Authorization
header has
already been set.HttpHeaders.setBasicAuth(java.lang.String, java.lang.String)
,
HttpHeaders.AUTHORIZATION
Constructor and Description |
---|
BasicAuthenticationInterceptor(String username,
String password)
Create a new interceptor which adds Basic Authentication for the
given username and password.
|
BasicAuthenticationInterceptor(String username,
String password,
Charset charset)
Create a new interceptor which adds Basic Authentication for the
given username and password, encoded using the specified charset.
|
Modifier and Type | Method and Description |
---|---|
ClientHttpResponse |
intercept(HttpRequest request,
byte[] body,
ClientHttpRequestExecution execution)
Intercept the given request, and return a response.
|
public BasicAuthenticationInterceptor(String username, String password)
username
- the username to usepassword
- the password to useHttpHeaders.setBasicAuth(String, String)
,
HttpHeaders.encodeBasicAuth(String, String, Charset)
public BasicAuthenticationInterceptor(String username, String password, @Nullable Charset charset)
username
- the username to usepassword
- the password to usecharset
- the charset to useHttpHeaders.setBasicAuth(String, String, Charset)
,
HttpHeaders.encodeBasicAuth(String, String, Charset)
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException
ClientHttpRequestInterceptor
ClientHttpRequestExecution
allows the interceptor to pass on the
request and response to the next entity in the chain.
A typical implementation of this method would follow the following pattern:
ClientHttpRequestExecution.execute(org.springframework.http.HttpRequest, byte[])
,intercept
in interface ClientHttpRequestInterceptor
request
- the request, containing method, URI, and headersbody
- the body of the requestexecution
- the request executionIOException
- in case of I/O errors