summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2012-03-07 14:34:24 (EST)
committerSteffen Pingel2012-03-07 14:34:24 (EST)
commitd6a40baed09969d7a5aa9db48851dc9618612bf2 (patch)
tree07609a053d08d021b1b2adf52113415920e820b8
parent8ab3f3deff4c77b0962ee410166e579702cf7b53 (diff)
downloadorg.eclipse.mylyn.commons-d6a40baed09969d7a5aa9db48851dc9618612bf2.zip
org.eclipse.mylyn.commons-d6a40baed09969d7a5aa9db48851dc9618612bf2.tar.gz
org.eclipse.mylyn.commons-d6a40baed09969d7a5aa9db48851dc9618612bf2.tar.bz2
NEW - bug 372596: Hudson shows Unexpected response from Hudson server
for '/api/xml': Forbidden when using authentication https://bugs.eclipse.org/bugs/show_bug.cgi?id=372596 Change-Id: Iae66cd645eccf2980277a67b5836ad12c5d0ad49
-rw-r--r--org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationException.java15
-rw-r--r--org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationRequest.java11
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpOperation.java45
3 files changed, 63 insertions, 8 deletions
diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationException.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationException.java
index 01b150e..50632c4 100644
--- a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationException.java
+++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationException.java
@@ -24,18 +24,29 @@ public class AuthenticationException extends IOException {
private final AuthenticationRequest<?> request;
- public AuthenticationException(String message, AuthenticationRequest<?> request) {
+ private final boolean shouldRetry;
+
+ public AuthenticationException(String message, AuthenticationRequest<?> request, boolean shouldRetry) {
super(message);
Assert.isNotNull(request);
this.request = request;
+ this.shouldRetry = shouldRetry;
}
+ public AuthenticationException(String message, AuthenticationRequest<?> request) {
+ this(message, request, false);
+ }
+
public AuthenticationException(AuthenticationRequest<?> request) {
- this(null, request);
+ this(null, request, false);
}
public AuthenticationRequest<?> getRequest() {
return request;
}
+ public boolean shouldRetry() {
+ return shouldRetry;
+ }
+
}
diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationRequest.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationRequest.java
index f286169..dc272f0 100644
--- a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationRequest.java
+++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationRequest.java
@@ -23,11 +23,18 @@ public class AuthenticationRequest<T extends AuthenticationType<?>> {
private final RepositoryLocation location;
- public AuthenticationRequest(RepositoryLocation location, T authenticationType) {
+ private final String message;
+
+ public AuthenticationRequest(RepositoryLocation location, T authenticationType, String message) {
Assert.isNotNull(location);
Assert.isNotNull(authenticationType);
this.location = location;
this.authenticationType = authenticationType;
+ this.message = message;
+ }
+
+ public AuthenticationRequest(RepositoryLocation location, T authenticationType) {
+ this(location, authenticationType, null);
}
public T getAuthenticationType() {
@@ -39,7 +46,7 @@ public class AuthenticationRequest<T extends AuthenticationType<?>> {
}
public String getMessage() {
- return null;
+ return message;
}
}
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 915a927..2d7d617 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
@@ -59,19 +59,53 @@ public abstract class CommonHttpOperation<T> {
public CommonHttpResponse execute(HttpRequestBase request, IOperationMonitor monitor) throws IOException {
monitor = OperationUtil.convert(monitor);
+ // first attempt
+ boolean requestCredentials;
try {
- // first attempt
return executeOnce(request, monitor);
} catch (AuthenticationException e) {
+ requestCredentials = !e.shouldRetry();
+
+ handleAuthenticationError(request, e, monitor, requestCredentials);
+ }
+
+ // second attempt
+ try {
+ return executeOnce(request, monitor);
+ } catch (AuthenticationException e) {
+ if (requestCredentials) {
+ // new credentials were not correct either
+ invalidateAuthentication(e, monitor);
+ throw e;
+ }
+
+ handleAuthenticationError(request, e, monitor, true);
+ }
+
+ // third attempt
+ return executeOnce(request, monitor);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void handleAuthenticationError(HttpRequestBase request, AuthenticationException e,
+ IOperationMonitor monitor, boolean requestCredentials) throws AuthenticationException {
+ invalidateAuthentication(e, monitor);
+
+ if (!isRepeatable()) {
+ throw e;
+ }
+
+ if (requestCredentials) {
try {
requestCredentials((AuthenticationRequest) e.getRequest(), monitor);
} catch (UnsupportedOperationException e2) {
throw e;
}
}
+ }
- // second attempt
- return executeOnce(request, monitor);
+ protected boolean isRepeatable() {
+ return true;
}
protected CommonHttpResponse executeOnce(HttpRequestBase request, IOperationMonitor monitor) throws IOException {
@@ -80,7 +114,6 @@ public abstract class CommonHttpOperation<T> {
authenticate(monitor);
}
- // first attempt
HttpResponse response = client.execute(request, monitor);
try {
validate(response, monitor);
@@ -108,6 +141,10 @@ public abstract class CommonHttpOperation<T> {
return client.requestCredentials(request, monitor);
}
+ protected void invalidateAuthentication(AuthenticationException e, IOperationMonitor monitor) {
+ client.setAuthenticated(false);
+ }
+
protected void validate(HttpResponse response, IOperationMonitor monitor) throws AuthenticationException {
client.validate(response, monitor);
}