diff options
author | Steffen Pingel | 2011-12-23 17:11:24 +0000 |
---|---|---|
committer | Steffen Pingel | 2011-12-23 17:11:24 +0000 |
commit | aad2b6949bd5903d85a30c16366a700eb107e1f8 (patch) | |
tree | bec2b59bcd08b6ba37afffe3363ac673280bd34d /org.eclipse.mylyn.commons.repositories.http.core | |
parent | 3b1f5eb4a5487469283a60c903f0b87d33816462 (diff) | |
download | org.eclipse.mylyn.commons-aad2b6949bd5903d85a30c16366a700eb107e1f8.tar.gz org.eclipse.mylyn.commons-aad2b6949bd5903d85a30c16366a700eb107e1f8.tar.xz org.eclipse.mylyn.commons-aad2b6949bd5903d85a30c16366a700eb107e1f8.zip |
NEW - bug 356788: Support for form-based login to Hudson/Jenkins
https://bugs.eclipse.org/bugs/show_bug.cgi?id=356788
Diffstat (limited to 'org.eclipse.mylyn.commons.repositories.http.core')
3 files changed, 44 insertions, 29 deletions
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpClient.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpClient.java index 49ad279b..87404aa5 100644 --- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpClient.java +++ b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpClient.java @@ -32,6 +32,8 @@ import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType; */ public class CommonHttpClient { + private boolean authenticated; + private final SyncBasicHttpContext context; private AbstractHttpClient httpClient; @@ -59,12 +61,15 @@ public class CommonHttpClient { return location; } - protected void authenticate(IOperationMonitor monitor) throws IOException { + public boolean isAuthenticated() { + return authenticated; } - protected ClientConnectionManager createHttpClientConnectionManager() { - // FIXME handle certificate authentication - return HttpUtil.getConnectionManager(); + public void setAuthenticated(boolean authenticated) { + this.authenticated = authenticated; + } + + protected void authenticate(IOperationMonitor monitor) throws IOException { } protected AbstractHttpClient createHttpClient(String userAgent) { @@ -74,10 +79,22 @@ public class CommonHttpClient { return CommonHttpClient.this.createHttpClientConnectionManager(); } }; +// client.setTargetAuthenticationHandler(new DefaultTargetAuthenticationHandler() { +// @Override +// public boolean isAuthenticationRequested(HttpResponse response, HttpContext context) { +// int statusCode = response.getStatusLine().getStatusCode(); +// return statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_FORBIDDEN; +// } +// }); HttpUtil.configureClient(client, userAgent); return client; } + protected ClientConnectionManager createHttpClientConnectionManager() { + // FIXME handle certificate authentication + return HttpUtil.getConnectionManager(); + } + protected boolean needsReauthentication(HttpResponse response, IProgressMonitor monitor) throws IOException { int statusCode = response.getStatusLine().getStatusCode(); final AuthenticationType authenticationType; diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpOperation.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpOperation.java index 7725bc5d..775a6e93 100644 --- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpOperation.java +++ b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpOperation.java @@ -20,7 +20,6 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpRequestBase; import org.eclipse.mylyn.commons.core.operations.IOperationMonitor; import org.eclipse.mylyn.commons.core.operations.OperationUtil; -import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationCredentials; /** * @author Steffen Pingel @@ -33,8 +32,8 @@ public abstract class CommonHttpOperation<T> { this.client = client; } - private boolean needsReauthentication(HttpResponse response, IOperationMonitor monitor) throws IOException { - return client.needsReauthentication(response, monitor); + protected void authenticate(IOperationMonitor monitor) throws IOException { + client.authenticate(monitor); } protected HttpGet createGetRequest(String requestPath) { @@ -54,34 +53,44 @@ public abstract class CommonHttpOperation<T> { // force authentication if (needsAuthentication()) { - client.authenticate(monitor); + authenticate(monitor); } // first attempt HttpResponse response = client.execute(request, monitor); - if (!needsReauthentication(response, monitor)) { - return new CommonHttpResponse(request, response); - } else { + boolean repeat = false; + try { + if (needsReauthentication(response, monitor)) { + HttpUtil.release(request, response, monitor); + repeat = true; + } + } catch (IOException e) { HttpUtil.release(request, response, monitor); + throw e; + } catch (RuntimeException e) { + HttpUtil.release(request, response, monitor); + throw e; + } - client.authenticate(monitor); - + if (repeat) { // second attempt + authenticate(monitor); response = client.execute(request, monitor); - return new CommonHttpResponse(request, response); } + + return new CommonHttpResponse(request, response); } protected final CommonHttpClient getClient() { return client; } - protected boolean hasCredentials(AuthenticationCredentials credentials) { - return credentials != null; - } - protected boolean needsAuthentication() { return false; } + protected boolean needsReauthentication(HttpResponse response, IOperationMonitor monitor) throws IOException { + return client.needsReauthentication(response, monitor); + } + } diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java index 088dfab4..2dd31c96 100644 --- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java +++ b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java @@ -138,12 +138,6 @@ public class HttpUtil { int port = NetUtil.getPort(url); Credentials credentials = getHttpClientCredentials(authCreds, host, false); if (credentials instanceof NTCredentials) { - List<String> authpref = new ArrayList<String>(); - authpref.add(AuthPolicy.NTLM); - authpref.add(AuthPolicy.BASIC); - authpref.add(AuthPolicy.DIGEST); - client.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref); - AuthScope authScopeNTLM = new AuthScope(host, port, AuthScope.ANY_REALM, AuthPolicy.NTLM); client.getCredentialsProvider().setCredentials(authScopeNTLM, credentials); @@ -151,11 +145,6 @@ public class HttpUtil { Credentials usernamePasswordCredentials = getHttpClientCredentials(authCreds, host, true); client.getCredentialsProvider().setCredentials(authScopeAny, usernamePasswordCredentials); } else { - List<String> authpref = new ArrayList<String>(); - authpref.add(AuthPolicy.BASIC); - authpref.add(AuthPolicy.DIGEST); - authpref.add(AuthPolicy.NTLM); - client.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref); AuthScope authScope = new AuthScope(host, port, AuthScope.ANY_REALM); client.getCredentialsProvider().setCredentials(authScope, credentials); } |