olegk 2003/04/22 10:00:26
Modified: httpclient/src/java/org/apache/commons/httpclient
HttpMethodBase.java
httpclient/src/java/org/apache/commons/httpclient/auth
AuthScheme.java NTLMScheme.java RFC2617Scheme.java
httpclient/src/test/org/apache/commons/httpclient
TestAuthenticator.java
Log:
Bug fix #19185 (NTLM Authentication Fails)
Contributed by Adrian Sutton
Reviews by Oleg Kalnichevski
Revision Changes Path
1.135 +5 -5 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
Index: HttpMethodBase.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
retrieving revision 1.134
retrieving revision 1.135
diff -u -r1.134 -r1.135
--- HttpMethodBase.java 20 Apr 2003 23:26:22 -0000 1.134
+++ HttpMethodBase.java 22 Apr 2003 17:00:24 -0000 1.135
@@ -2333,7 +2333,7 @@
buffer.append(port);
}
buffer.append('#');
- buffer.append(authscheme.getRealm());
+ buffer.append(authscheme.getID());
String realm = buffer.toString();
if (realmsUsed.contains(realm)) {
1.4 +22 -3 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/AuthScheme.java
Index: AuthScheme.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/AuthScheme.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AuthScheme.java 6 Apr 2003 22:31:53 -0000 1.3
+++ AuthScheme.java 22 Apr 2003 17:00:25 -0000 1.4
@@ -87,6 +87,7 @@
* </p>
*
* @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
+ * @author <a href="mailto:adrian@ephox.com">Adrian Sutton</a>
*
* @since 2.0beta1
*/
@@ -117,6 +118,24 @@
* @return the authentication realm
*/
String getRealm();
+
+ /**
+ * Returns a String identifying the authentication challenge. This is
+ * used, in combination with the host and port to determine if
+ * authorization has already been attempted or not. Schemes which
+ * require multiple requests to complete the authentication should
+ * return a different value for each stage in the request.
+ *
+ * <p>Additionally, the ID should take into account any changes to the
+ * authentication challenge and return a different value when appropriate.
+ * For example when the realm changes in basic authentication it should be
+ * considered a different authentication attempt and a different value should
+ * be returned.</p>
+ *
+ * @return String a String identifying the authentication challenge. The
+ * returned value may be null.
+ */
+ String getID();
/**
* Produces an authorization string for the given set of {@link Credentials},
1.4 +23 -3 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/NTLMScheme.java
Index: NTLMScheme.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/NTLMScheme.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- NTLMScheme.java 6 Apr 2003 22:31:53 -0000 1.3
+++ NTLMScheme.java 22 Apr 2003 17:00:25 -0000 1.4
@@ -134,6 +134,26 @@
return null;
}
+ /**
+ * Returns a String identifying the authentication challenge. This is
+ * used, in combination with the host and port to determine if
+ * authorization has already been attempted or not. Schemes which
+ * require multiple requests to complete the authentication should
+ * return a different value for each stage in the request.
+ *
+ * <p>Additionally, the ID should take into account any changes to the
+ * authentication challenge and return a different value when appropriate.
+ * For example when the realm changes in basic authentication it should be
+ * considered a different authentication attempt and a different value should
+ * be returned.</p>
+ *
+ * @return String a String identifying the authentication challenge. The
+ * returned value may be null.
+ */
+ public String getID() {
+ return ntlmchallenge;
+ }
+
/**
* Returns authentication parameter with the given name, if available.
1.4 +25 -3 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/RFC2617Scheme.java
Index: RFC2617Scheme.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/RFC2617Scheme.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- RFC2617Scheme.java 6 Apr 2003 22:31:53 -0000 1.3
+++ RFC2617Scheme.java 22 Apr 2003 17:00:25 -0000 1.4
@@ -130,4 +130,26 @@
public String getRealm() {
return getParameter("realm");
}
+
+ /**
+ * Returns a String identifying the authentication challenge. This is
+ * used, in combination with the host and port to determine if
+ * authorization has already been attempted or not. Schemes which
+ * require multiple requests to complete the authentication should
+ * return a different value for each stage in the request.
+ *
+ * <p>Additionally, the ID should take into account any changes to the
+ * authentication challenge and return a different value when appropriate.
+ * For example when the realm changes in basic authentication it should be
+ * considered a different authentication attempt and a different value should
+ * be returned.</p>
+ *
+ * <p>This method simply returns the realm for the challenge.</p>
+ *
+ * @return String a String identifying the authentication challenge. The
+ * returned value may be null.
+ */
+ public String getID() {
+ return getRealm();
+ }
}
1.25 +30 -4 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAuthenticator.java
Index: TestAuthenticator.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAuthenticator.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- TestAuthenticator.java 7 Apr 2003 19:23:36 -0000 1.24
+++ TestAuthenticator.java 22 Apr 2003 17:00:26 -0000 1.25
@@ -484,6 +484,32 @@
assertEquals(expected,
method.getRequestHeader("Authorization").getValue());
}
+
+ public void testNTLMAuthenticationRetry() throws Exception {
+ NTCredentials cred = new NTCredentials("username", "password", "host", "domain");
+ HttpState state = new HttpState();
+ state.setCredentials(null, null, cred);
+ HttpMethod method = new SimpleHttpMethod();
+ SimpleHttpConnection conn = new SimpleHttpConnection();
+ conn.addResponse(
+ "HTTP/1.1 401 Unauthorized\r\n" +
+ "WWW-Authenticate: NTLM\r\n" +
+ "Connection: close\r\n" +
+ "Server: HttpClient Test/2.0\r\n");
+ conn.addResponse(
+ "HTTP/1.1 401 Unauthorized\r\n" +
+ "WWW-Authenticate: NTLM TlRMTVNTUAACAAAAAAAAACgAAAABggAAU3J2Tm9uY2UAAAAAAAAAAA==\r\n"
+
+ "Connection: close\r\n" +
+ "Server: HttpClient Test/2.0\r\n");
+ conn.addResponse(
+ "HTTP/1.1 200 OK\r\n" +
+ "Connection: close\r\n" +
+ "Server: HttpClient Test/2.0\r\n\r\n" +
+ "stuff\r\n");
+ method.execute(state, conn);
+ assertNull(method.getResponseHeader("WWW-Authenticate"));
+ assertEquals(200, method.getStatusCode());
+ }
/**
* Test that the Unauthorized response is returned when doAuthentication is false.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
|