All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.marklogic.client.impl.okhttp.DigestAuthenticationConfigurer Maven / Gradle / Ivy

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