Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.apache.http.HttpStatus;
import org.apache.http.auth.AuthSchemeProvider;
import org.apache.http.auth.AuthScope;
import org.apache.http.client.AuthCache;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.HttpResponseException;
Expand Down Expand Up @@ -72,6 +73,7 @@
import org.apache.http.impl.auth.KerberosSchemeFactory;
import org.apache.http.impl.auth.NTLMSchemeFactory;
import org.apache.http.impl.auth.SPNegoSchemeFactory;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClientBuilder;
Expand All @@ -95,6 +97,7 @@
import org.eclipse.aether.transfer.NoTransporterException;
import org.eclipse.aether.transfer.TransferCancelledException;
import org.eclipse.aether.util.ConfigUtils;
import org.eclipse.aether.util.StringDigestUtil;
import org.eclipse.aether.util.connector.transport.http.HttpTransporterUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -145,6 +148,8 @@ final class ApacheTransporter extends AbstractTransporter implements HttpTranspo

private final boolean supportWebDav;

private final AuthCache authCache;

@SuppressWarnings("checkstyle:methodlength")
ApacheTransporter(
RemoteRepository repository,
Expand Down Expand Up @@ -281,6 +286,13 @@ final class ApacheTransporter extends AbstractTransporter implements HttpTranspo
builder.setConnectionReuseStrategy(NoConnectionReuseStrategy.INSTANCE);
}

if (session.getCache() != null) {
String authCacheKey = getClass().getSimpleName() + "-" + repository.getId() + "-"
+ StringDigestUtil.sha1(repository.toString());
this.authCache = (AuthCache) session.getCache().computeIfAbsent(session, authCacheKey, BasicAuthCache::new);
} else {
this.authCache = new BasicAuthCache();
}
this.client = builder.build();
}

Expand Down Expand Up @@ -382,10 +394,10 @@ protected void implPut(PutTask task) throws Exception {
private void execute(HttpUriRequest request, EntityGetter getter) throws Exception {
try {
SharingHttpContext context = new SharingHttpContext(state);
context.setAuthCache(authCache);
prepare(request, context);
try (CloseableHttpResponse response = client.execute(server, request, context)) {
try {
context.close();
handleStatus(response);
if (getter != null) {
getter.handle(response);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;

import org.apache.http.HttpHost;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.conn.socket.ConnectionSocketFactory;
Expand Down Expand Up @@ -96,8 +95,6 @@ public String toString() {

private final ConcurrentMap<CompoundKey, Object> userTokens;

private final ConcurrentMap<HttpHost, AuthSchemePool> authSchemePools;

private final ConcurrentMap<CompoundKey, Boolean> expectContinues;

public static GlobalState get(RepositorySystemSession session) {
Expand Down Expand Up @@ -127,7 +124,6 @@ public static GlobalState get(RepositorySystemSession session) {
private GlobalState() {
connectionManagers = new ConcurrentHashMap<>();
userTokens = new ConcurrentHashMap<>();
authSchemePools = new ConcurrentHashMap<>();
expectContinues = new ConcurrentHashMap<>();
}

Expand Down Expand Up @@ -217,10 +213,6 @@ public void setUserToken(CompoundKey key, Object userToken) {
}
}

public ConcurrentMap<HttpHost, AuthSchemePool> getAuthSchemePools() {
return authSchemePools;
}

public Boolean getExpectContinue(CompoundKey key) {
return expectContinues.get(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
package org.eclipse.aether.transport.apache;

import java.io.Closeable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScheme;
import org.apache.http.conn.HttpClientConnectionManager;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
Expand All @@ -47,22 +43,18 @@ final class LocalState implements Closeable {

private volatile Boolean webDav;

private final ConcurrentMap<HttpHost, AuthSchemePool> authSchemePools;

LocalState(RepositorySystemSession session, RemoteRepository repo, ConnMgrConfig connMgrConfig) {
global = GlobalState.get(session);
userToken = this;
if (global == null) {
connMgr = GlobalState.newConnectionManager(connMgrConfig);
userTokenKey = null;
expectContinueKey = null;
authSchemePools = new ConcurrentHashMap<>();
} else {
connMgr = global.getConnectionManager(connMgrConfig);
userTokenKey =
new GlobalState.CompoundKey(repo.getId(), repo.getUrl(), repo.getAuthentication(), repo.getProxy());
expectContinueKey = new GlobalState.CompoundKey(repo.getUrl(), repo.getProxy());
authSchemePools = global.getAuthSchemePools();
}
}

Expand Down Expand Up @@ -107,26 +99,6 @@ public void setWebDav(boolean webDav) {
this.webDav = webDav;
}

public AuthScheme getAuthScheme(HttpHost host) {
AuthSchemePool pool = authSchemePools.get(host);
if (pool != null) {
return pool.get();
}
return null;
}

public void setAuthScheme(HttpHost host, AuthScheme authScheme) {
AuthSchemePool pool = authSchemePools.get(host);
if (pool == null) {
AuthSchemePool p = new AuthSchemePool();
pool = authSchemePools.putIfAbsent(host, p);
if (pool == null) {
pool = p;
}
}
pool.put(authScheme);
}

@Override
public void close() {
if (global == null) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
package org.eclipse.aether.transport.apache;

import java.io.Closeable;

import org.apache.http.client.protocol.HttpClientContext;

/**
Expand All @@ -28,16 +26,12 @@
* @see <a href="http://hc.apache.org/httpcomponents-client-ga/tutorial/html/advanced.html#stateful_conn">Stateful HTTP
* connections</a>
*/
final class SharingHttpContext extends HttpClientContext implements Closeable {
final class SharingHttpContext extends HttpClientContext {

private final LocalState state;

private final SharingAuthCache authCache;

SharingHttpContext(LocalState state) {
this.state = state;
authCache = new SharingAuthCache(state);
super.setAttribute(HttpClientContext.AUTH_CACHE, authCache);
}

@Override
Expand Down Expand Up @@ -65,9 +59,4 @@ public Object removeAttribute(String id) {
}
return super.removeAttribute(id);
}

@Override
public void close() {
authCache.clear();
}
}