Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrelves2010-02-12 00:39:06 -0500
committerrelves2010-02-12 00:39:06 -0500
commit58d9432f7793dbbdf1c5e4dc367607e523e44af2 (patch)
treed3160e6dfc4ac746310b58237b501b01de538d9d /org.eclipse.mylyn.oslc.core
parent6ac7d3509ded0f23ab1ca34b3503a05bbedb7f8b (diff)
downloadorg.eclipse.mylyn.tasks-58d9432f7793dbbdf1c5e4dc367607e523e44af2.tar.gz
org.eclipse.mylyn.tasks-58d9432f7793dbbdf1c5e4dc367607e523e44af2.tar.xz
org.eclipse.mylyn.tasks-58d9432f7793dbbdf1c5e4dc367607e523e44af2.zip
NEW - bug 302672: [oslc] create unit test against RTC Rational Team Concert's OSLC api
https://bugs.eclipse.org/bugs/show_bug.cgi?id=302672
Diffstat (limited to 'org.eclipse.mylyn.oslc.core')
-rw-r--r--org.eclipse.mylyn.oslc.core/src/org/eclipse/mylyn/internal/oslc/core/client/AbstractOslcClient.java28
1 files changed, 26 insertions, 2 deletions
diff --git a/org.eclipse.mylyn.oslc.core/src/org/eclipse/mylyn/internal/oslc/core/client/AbstractOslcClient.java b/org.eclipse.mylyn.oslc.core/src/org/eclipse/mylyn/internal/oslc/core/client/AbstractOslcClient.java
index be0c3cdcf..6d47b98dd 100644
--- a/org.eclipse.mylyn.oslc.core/src/org/eclipse/mylyn/internal/oslc/core/client/AbstractOslcClient.java
+++ b/org.eclipse.mylyn.oslc.core/src/org/eclipse/mylyn/internal/oslc/core/client/AbstractOslcClient.java
@@ -19,10 +19,12 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
@@ -32,6 +34,8 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.commons.net.AbstractWebLocation;
+import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
+import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.commons.net.Policy;
import org.eclipse.mylyn.commons.net.WebUtil;
import org.eclipse.mylyn.internal.oslc.core.IOslcCoreConstants;
@@ -71,6 +75,26 @@ public abstract class AbstractOslcClient {
this.location = location;
this.httpClient = createHttpClient();
this.configuration = data;
+ configureHttpCredentials(location);
+ }
+
+ protected void configureHttpCredentials(AbstractWebLocation location) {
+ AuthScope authScope = new AuthScope(WebUtil.getHost(location.getUrl()), WebUtil.getPort(location.getUrl()),
+ null, AuthScope.ANY_SCHEME);
+
+ AuthenticationCredentials credentials = location.getCredentials(AuthenticationType.REPOSITORY);
+
+ if (credentialsValid(credentials)) {
+ Credentials creds = WebUtil.getHttpClientCredentials(credentials, WebUtil.getHost(location.getUrl()));
+ httpClient.getState().setCredentials(authScope, creds);
+ this.httpClient.getParams().setAuthenticationPreemptive(true);
+ } else {
+ httpClient.getState().clearCredentials();
+ }
+ }
+
+ protected boolean credentialsValid(AuthenticationCredentials credentials) {
+ return credentials != null && credentials.getUserName().length() > 0;
}
protected HttpClient createHttpClient() {
@@ -404,8 +428,8 @@ public abstract class AbstractOslcClient {
GetMethod method = new GetMethod(getRequestPath(requestPath));
method.setFollowRedirects(true);
method.setDoAuthentication(true);
- // application/xml is returned by oslc servers by default
- //method.setRequestHeader("Accept", "application/xml");
+ // application/xml is returned by oslc servers by default (but some may not play nice)
+ method.setRequestHeader("Accept", "application/xml"); //$NON-NLS-1$ //$NON-NLS-2$
return method;
}

Back to the top