
com.marklogic.client.impl.okhttp.DigestAuthenticationConfigurer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of marklogic-client-api Show documentation
Show all versions of marklogic-client-api Show documentation
The official MarkLogic Java client API.
The newest version!
/*
* Copyright © 2024 MarkLogic Corporation. All Rights Reserved.
*/
package com.marklogic.client.impl.okhttp;
import com.burgstaller.okhttp.AuthenticationCacheInterceptor;
import com.burgstaller.okhttp.CachingAuthenticatorDecorator;
import com.burgstaller.okhttp.digest.CachingAuthenticator;
import com.burgstaller.okhttp.digest.Credentials;
import com.burgstaller.okhttp.digest.DigestAuthenticator;
import com.marklogic.client.DatabaseClientFactory;
import okhttp3.OkHttpClient;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
class DigestAuthenticationConfigurer implements AuthenticationConfigurer {
@Override
public void configureAuthentication(OkHttpClient.Builder clientBuilder, DatabaseClientFactory.DigestAuthContext securityContext) {
String user = securityContext.getUser();
String password = securityContext.getPassword();
if (user == null)
throw new IllegalArgumentException("No user provided");
if (password == null)
throw new IllegalArgumentException("No password provided");
final Map authCache = new ConcurrentHashMap<>();
CachingAuthenticator authenticator = new DigestAuthenticator(new Credentials(user, password));
clientBuilder.authenticator(new CachingAuthenticatorDecorator(authenticator, authCache));
clientBuilder.addInterceptor(new AuthenticationCacheInterceptor(authCache));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy