this.password = password;
}
public Object authenticate(Object authenticable, TransportAuthenticationContext context) throws TransportAuthenticationException {
ReplicationEndpoint endpoint = context.getAttribute("endpoint", ReplicationEndpoint.class);
if (endpoint == null) {
throw new TransportAuthenticationException("the endpoint to authenticate is missing from the context");
}
if (authenticable instanceof Executor) {
Executor executor = (Executor) authenticable;
Executor authenticated = executor.auth(new HttpHost(endpoint.getUri().getHost(), endpoint.getUri().getPort()),
username, password).authPreemptive(
new HttpHost(endpoint.getUri().getHost(), endpoint.getUri().getPort()));
log.debug("authenticated executor HTTP client with user and password");
return authenticated;
} else if (authenticable instanceof CredentialsProvider) {
CredentialsProvider credentialsProvider = (CredentialsProvider) authenticable;
credentialsProvider.setCredentials(new AuthScope(new HttpHost(endpoint.getUri().getHost(), endpoint.getUri().getPort())),
new UsernamePasswordCredentials(username, password));
log.debug("authenticated CredentialsProvider HTTP client with user and password");
return credentialsProvider;
}