You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jg...@apache.org on 2007/09/27 08:29:29 UTC
svn commit: r579913 - in /geronimo/sandbox/AsyncHttpClient/src:
main/java/org/apache/ahc/codec/HttpIoHandler.java
main/java/org/apache/ahc/codec/HttpRequestMessage.java
test/java/org/apache/ahc/AuthTest.java
Author: jgenender
Date: Wed Sep 26 23:29:27 2007
New Revision: 579913
URL: http://svn.apache.org/viewvc?rev=579913&view=rev
Log:
Only allow 3 attempts to authorize or fail
Modified:
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java
geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AuthTest.java
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java?rev=579913&r1=579912&r2=579913&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java Wed Sep 26 23:29:27 2007
@@ -132,11 +132,15 @@
AsyncHttpClient client = (AsyncHttpClient)ioSession.getAttachment();
//Authenticate
- client.sendRequest(request);
+ int authCount = request.getAuthCount() + 1;
+ if (authCount <= 3){
+ request.setAuthCount(authCount);
+ client.sendRequest(request);
- //Close the current session since we are done with it
- ioSession.close();
- return;
+ //Close the current session since we are done with it
+ ioSession.close();
+ return;
+ }
}
cancelTasks(request);
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java?rev=579913&r1=579912&r2=579913&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java Wed Sep 26 23:29:27 2007
@@ -136,6 +136,12 @@
*/
private HashMap<AuthScope, Credentials> credentials = new HashMap<AuthScope, Credentials>();
+
+ /**
+ * Auth attempt count
+ */
+ private int authCount = 0;
+
/**
* Instantiates a new http request message.
*
@@ -462,5 +468,24 @@
*/
public void addCredentials(AuthScope scope, Credentials credentials) {
this.credentials.put(scope, credentials);
+ }
+
+
+ /**
+ * Gets the authorization attempt count
+ *
+ * @return the authorization attempt count
+ */
+ public int getAuthCount() {
+ return authCount;
+ }
+
+ /**
+ * Sets the authorization attempt count
+ *
+ * @param authCount the authorization attempt count
+ */
+ public void setAuthCount(int authCount) {
+ this.authCount = authCount;
}
}
Modified: geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AuthTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AuthTest.java?rev=579913&r1=579912&r2=579913&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AuthTest.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AuthTest.java Wed Sep 26 23:29:27 2007
@@ -48,6 +48,25 @@
assertEquals("Hello World!\n", callback.getMessage().getStringContent());
}
+ public void testBasicAuthFailure() throws Exception {
+
+ TestCallback callback = new TestCallback();
+ HttpRequestMessage request = new HttpRequestMessage(
+ new URL("http://localhost:8282/authbasic/secure.jsp"), callback);
+
+ UsernamePasswordCredentials creds = new UsernamePasswordCredentials("test","badpassword");
+ request.addCredentials(AuthScope.ANY, creds);
+ ahc.sendRequest(request);
+
+ synchronized (semaphore) {
+ //5 second timeout due to no response
+ semaphore.wait(5000);
+ }
+
+ //Should be an auth failure
+ assertEquals(401, callback.getMessage().getStatusCode());
+ }
+
public void testDigestAuth() throws Exception {
TestCallback callback = new TestCallback();
HttpRequestMessage request = new HttpRequestMessage(