Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2008-10-13 21:27:57 +0000
committerspingel2008-10-13 21:27:57 +0000
commit838236c89cafaae2d6c26a1afec054eb312ede3c (patch)
treed8e676b2ce8e73b79bffcda5e1b5416f12a7617a /org.eclipse.mylyn.trac.core
parentf543f0985301bbe1831a089a45a4bfcea4e65ff7 (diff)
downloadorg.eclipse.mylyn.tasks-838236c89cafaae2d6c26a1afec054eb312ede3c.tar.gz
org.eclipse.mylyn.tasks-838236c89cafaae2d6c26a1afec054eb312ede3c.tar.xz
org.eclipse.mylyn.tasks-838236c89cafaae2d6c26a1afec054eb312ede3c.zip
NEW - bug 214341: Large XML-RPC requests fail when using digest authentication and tracd
https://bugs.eclipse.org/bugs/show_bug.cgi?id=214341
Diffstat (limited to 'org.eclipse.mylyn.trac.core')
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracXmlRpcClient.java105
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/HttpMethodInterceptor.java (renamed from org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/HttpRequestInterceptor.java)6
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/TracHttpClientTransportFactory.java15
3 files changed, 77 insertions, 49 deletions
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracXmlRpcClient.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracXmlRpcClient.java
index 68f9e96de..86166c819 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracXmlRpcClient.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/client/TracXmlRpcClient.java
@@ -32,12 +32,13 @@ import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScheme;
import org.apache.commons.httpclient.auth.AuthScope;
-import org.apache.commons.httpclient.auth.AuthenticationException;
+import org.apache.commons.httpclient.auth.BasicScheme;
import org.apache.commons.httpclient.auth.DigestScheme;
-import org.apache.commons.httpclient.auth.MalformedChallengeException;
import org.apache.commons.httpclient.methods.HeadMethod;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
@@ -71,7 +72,7 @@ import org.eclipse.mylyn.internal.trac.core.model.TracVersion;
import org.eclipse.mylyn.internal.trac.core.model.TracWikiPage;
import org.eclipse.mylyn.internal.trac.core.model.TracWikiPageInfo;
import org.eclipse.mylyn.internal.trac.core.model.TracTicket.Key;
-import org.eclipse.mylyn.internal.trac.core.util.HttpRequestInterceptor;
+import org.eclipse.mylyn.internal.trac.core.util.HttpMethodInterceptor;
import org.eclipse.mylyn.internal.trac.core.util.TracHttpClientTransportFactory;
import org.eclipse.mylyn.internal.trac.core.util.TracUtil;
import org.eclipse.mylyn.internal.trac.core.util.TracXmlRpcClientRequest;
@@ -143,6 +144,10 @@ public class TracXmlRpcClient extends AbstractTracClient implements ITracWikiCli
private Object executeCallInternal(IProgressMonitor monitor) throws TracException {
try {
+ if (isTracd && digestScheme != null) {
+ probeAuthenticationScheme(monitor);
+ }
+
TracXmlRpcClientRequest request = new TracXmlRpcClientRequest(xmlrpc.getClientConfig(), method,
parameters, monitor);
return xmlrpc.execute(request);
@@ -211,6 +216,8 @@ public class TracXmlRpcClient extends AbstractTracClient implements ITracWikiCli
private final AuthScope authScope;
+ private boolean isTracd;
+
public TracXmlRpcClient(AbstractWebLocation location, Version version) {
super(location, version);
this.httpClient = createHttpClient();
@@ -232,20 +239,24 @@ public class TracXmlRpcClient extends AbstractTracClient implements ITracWikiCli
factory = new TracHttpClientTransportFactory(xmlrpc, httpClient);
factory.setLocation(location);
- factory.setInterceptor(new HttpRequestInterceptor() {
- public void process(HttpMethod method) {
+ factory.setInterceptor(new HttpMethodInterceptor() {
+ public void processRequest(HttpMethod method) {
DigestScheme scheme = digestScheme;
if (scheme != null) {
Credentials creds = httpClient.getState().getCredentials(authScope);
if (creds != null) {
- try {
- method.addRequestHeader("Authorization", scheme.authenticate(creds, method));
- } catch (AuthenticationException e) {
- // ignore
- }
+ method.getHostAuthState().setAuthScheme(digestScheme);
+ method.getHostAuthState().setAuthRequested(true);
}
}
}
+
+ public void processResponse(HttpMethod method) {
+ AuthScheme authScheme = method.getHostAuthState().getAuthScheme();
+ if (authScheme instanceof DigestScheme) {
+ digestScheme = (DigestScheme) authScheme;
+ }
+ }
});
xmlrpc.setTransportFactory(factory);
}
@@ -278,50 +289,62 @@ public class TracXmlRpcClient extends AbstractTracClient implements ITracWikiCli
}
private void probeAuthenticationScheme(IProgressMonitor monitor) throws TracException {
- if (probed) {
+ this.digestScheme = null;
+
+ AuthenticationCredentials credentials = location.getCredentials(AuthenticationType.REPOSITORY);
+ if (!credentialsValid(credentials)) {
return;
}
+ HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(httpClient, location, monitor);
+ HeadMethod method = new HeadMethod(getXmlRpcUrl(credentials).toString());
try {
- AuthenticationCredentials credentials = location.getCredentials(AuthenticationType.REPOSITORY);
- if (!credentialsValid(credentials)) {
- return;
- }
-
- HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(httpClient, location, monitor);
- HeadMethod method = new HeadMethod(getXmlRpcUrl(credentials).toString());
- try {
- int result = WebUtil.execute(httpClient, hostConfiguration, method, monitor);
- if (result == HttpStatus.SC_UNAUTHORIZED || result == HttpStatus.SC_FORBIDDEN) {
- Header header = method.getResponseHeader("WWW-Authenticate");
- if (header != null) {
- if (header.getValue().startsWith("Basic")) {
- httpClient.getParams().setAuthenticationPreemptive(true);
- } else if (header.getValue().startsWith("Digest")) {
- DigestScheme scheme = new DigestScheme();
- try {
- scheme.processChallenge(header.getValue());
- this.digestScheme = scheme;
- } catch (MalformedChallengeException e) {
- // ignore
- }
- }
- }
+ // execute without any credentials set
+ int result = WebUtil.execute(httpClient, hostConfiguration, method, new HttpState(), monitor);
+ if (result == HttpStatus.SC_UNAUTHORIZED || result == HttpStatus.SC_FORBIDDEN) {
+ AuthScheme authScheme = method.getHostAuthState().getAuthScheme();
+ if (authScheme instanceof DigestScheme) {
+ this.digestScheme = (DigestScheme) authScheme;
+ } else if (authScheme instanceof BasicScheme) {
+ httpClient.getParams().setAuthenticationPreemptive(true);
}
- } catch (IOException e) {
- // ignore
- } finally {
- method.releaseConnection();
+
+ Header header = method.getResponseHeader("Server");
+ isTracd = (header != null && header.getValue().startsWith("tracd"));
+
+// Header header = method.getResponseHeader("WWW-Authenticate");
+// if (header != null) {
+// if (header.getValue().startsWith("Basic")) {
+// httpClient.getParams().setAuthenticationPreemptive(true);
+// } else if (header.getValue().startsWith("Digest")) {
+// DigestScheme scheme = new DigestScheme();
+// try {
+// scheme.processChallenge(header.getValue());
+// this.digestScheme = scheme;
+// } catch (MalformedChallengeException e) {
+// // ignore
+// }
+// }
+// }
}
+ } catch (IOException e) {
+ // ignore
} finally {
- probed = true;
+ method.releaseConnection();
}
}
private Object call(IProgressMonitor monitor, String method, Object... parameters) throws TracException {
monitor = Policy.monitorFor(monitor);
while (true) {
- probeAuthenticationScheme(monitor);
+ if (!probed) {
+ try {
+ probeAuthenticationScheme(monitor);
+ } finally {
+ probed = true;
+ }
+ }
+
getClient();
try {
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/HttpRequestInterceptor.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/HttpMethodInterceptor.java
index bc2938a8d..e1b263320 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/HttpRequestInterceptor.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/HttpMethodInterceptor.java
@@ -16,8 +16,10 @@ import org.apache.commons.httpclient.HttpMethod;
/**
* @author Steffen Pingel
*/
-public interface HttpRequestInterceptor {
+public interface HttpMethodInterceptor {
- public abstract void process(HttpMethod method);
+ public abstract void processRequest(HttpMethod method);
+
+ public abstract void processResponse(HttpMethod method);
}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/TracHttpClientTransportFactory.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/TracHttpClientTransportFactory.java
index 1033f7ec2..77cf85b7a 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/TracHttpClientTransportFactory.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/util/TracHttpClientTransportFactory.java
@@ -67,10 +67,10 @@ public class TracHttpClientTransportFactory implements XmlRpcTransportFactory {
private HostConfiguration hostConfiguration;
- private final HttpRequestInterceptor interceptor;
+ private final HttpMethodInterceptor interceptor;
public TracHttpClientTransport(XmlRpcClient client, HttpClient httpClient, AbstractWebLocation location,
- HttpRequestInterceptor interceptor) {
+ HttpMethodInterceptor interceptor) {
super(client, "");
this.httpClient = httpClient;
this.location = location;
@@ -135,7 +135,7 @@ public class TracHttpClientTransportFactory implements XmlRpcTransportFactory {
method.getParams().setVersion(HttpVersion.HTTP_1_1);
if (interceptor != null) {
- interceptor.process(method);
+ interceptor.processRequest(method);
}
}
@@ -208,6 +208,9 @@ public class TracHttpClientTransportFactory implements XmlRpcTransportFactory {
try {
WebUtil.execute(httpClient, hostConfiguration, method, monitor);
+ if (interceptor != null) {
+ interceptor.processResponse(method);
+ }
} catch (XmlRpcIOException e) {
Throwable t = e.getLinkedException();
if (t instanceof XmlRpcException) {
@@ -240,7 +243,7 @@ public class TracHttpClientTransportFactory implements XmlRpcTransportFactory {
private final HttpClient httpClient;
- private HttpRequestInterceptor interceptor;
+ private HttpMethodInterceptor interceptor;
public TracHttpClientTransportFactory(XmlRpcClient xmlRpcClient, HttpClient httpClient) {
this.xmlRpcClient = xmlRpcClient;
@@ -259,11 +262,11 @@ public class TracHttpClientTransportFactory implements XmlRpcTransportFactory {
this.location = location;
}
- public HttpRequestInterceptor getInterceptor() {
+ public HttpMethodInterceptor getInterceptor() {
return interceptor;
}
- public void setInterceptor(HttpRequestInterceptor interceptor) {
+ public void setInterceptor(HttpMethodInterceptor interceptor) {
this.interceptor = interceptor;
}

Back to the top