HttpAuth converted to use collections with generics

git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@603567 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2007-12-12 11:25:00 +00:00
parent 34d72d935e
commit f4d2074d1e
5 changed files with 20 additions and 20 deletions

View File

@ -375,7 +375,7 @@ public class DigestScheme extends RFC2617Scheme {
String response = digest; String response = digest;
String algorithm = getParameter("algorithm"); String algorithm = getParameter("algorithm");
List params = new ArrayList(20); List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(20);
params.add(new BasicNameValuePair("username", credentials.getPrincipalName())); params.add(new BasicNameValuePair("username", credentials.getPrincipalName()));
params.add(new BasicNameValuePair("realm", realm)); params.add(new BasicNameValuePair("realm", realm));
params.add(new BasicNameValuePair("nonce", nonce)); params.add(new BasicNameValuePair("nonce", nonce));
@ -395,7 +395,7 @@ public class DigestScheme extends RFC2617Scheme {
} }
for (int i = 0; i < params.size(); i++) { for (int i = 0; i < params.size(); i++) {
BasicNameValuePair param = (BasicNameValuePair) params.get(i); BasicNameValuePair param = params.get(i);
if (i > 0) { if (i > 0) {
buffer.append(", "); buffer.append(", ");
} }

View File

@ -59,7 +59,7 @@ public abstract class RFC2617Scheme implements AuthScheme {
/** /**
* Authentication parameter map. * Authentication parameter map.
*/ */
private Map params = null; private Map<String, String> params = null;
/** /**
* Flag whether authenticating against a proxy. * Flag whether authenticating against a proxy.
@ -129,7 +129,7 @@ public abstract class RFC2617Scheme implements AuthScheme {
throw new MalformedChallengeException("Authentication challenge is empty"); throw new MalformedChallengeException("Authentication challenge is empty");
} }
this.params = new HashMap(elements.length); this.params = new HashMap<String, String>(elements.length);
for (int i = 0; i < elements.length; i++) { for (int i = 0; i < elements.length; i++) {
HeaderElement element = elements[i]; HeaderElement element = elements[i];
this.params.put(element.getName(), element.getValue()); this.params.put(element.getName(), element.getValue());
@ -141,7 +141,7 @@ public abstract class RFC2617Scheme implements AuthScheme {
* *
* @return the map of authentication parameters * @return the map of authentication parameters
*/ */
protected Map getParameters() { protected Map<String, String> getParameters() {
return this.params; return this.params;
} }

View File

@ -61,7 +61,7 @@ public class TestCookiePathComparator extends TestCase {
cookie1.setPath("/a/b/"); cookie1.setPath("/a/b/");
BasicClientCookie cookie2 = new BasicClientCookie("name1", "value"); BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
cookie2.setPath("/a/"); cookie2.setPath("/a/");
Comparator comparator = new CookiePathComparator(); Comparator<Cookie> comparator = new CookiePathComparator();
assertTrue(comparator.compare(cookie1, cookie2) < 0); assertTrue(comparator.compare(cookie1, cookie2) < 0);
assertTrue(comparator.compare(cookie2, cookie1) > 0); assertTrue(comparator.compare(cookie2, cookie1) > 0);
} }
@ -71,7 +71,7 @@ public class TestCookiePathComparator extends TestCase {
cookie1.setPath("/a/b"); cookie1.setPath("/a/b");
BasicClientCookie cookie2 = new BasicClientCookie("name1", "value"); BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
cookie2.setPath("/a"); cookie2.setPath("/a");
Comparator comparator = new CookiePathComparator(); Comparator<Cookie> comparator = new CookiePathComparator();
assertTrue(comparator.compare(cookie1, cookie2) < 0); assertTrue(comparator.compare(cookie1, cookie2) < 0);
assertTrue(comparator.compare(cookie2, cookie1) > 0); assertTrue(comparator.compare(cookie2, cookie1) > 0);
} }
@ -81,7 +81,7 @@ public class TestCookiePathComparator extends TestCase {
cookie1.setPath("/a"); cookie1.setPath("/a");
BasicClientCookie cookie2 = new BasicClientCookie("name1", "value"); BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
cookie2.setPath("/a"); cookie2.setPath("/a");
Comparator comparator = new CookiePathComparator(); Comparator<Cookie> comparator = new CookiePathComparator();
assertTrue(comparator.compare(cookie1, cookie2) == 0); assertTrue(comparator.compare(cookie1, cookie2) == 0);
assertTrue(comparator.compare(cookie2, cookie1) == 0); assertTrue(comparator.compare(cookie2, cookie1) == 0);
} }
@ -91,7 +91,7 @@ public class TestCookiePathComparator extends TestCase {
cookie1.setPath("/a/"); cookie1.setPath("/a/");
BasicClientCookie cookie2 = new BasicClientCookie("name1", "value"); BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
cookie2.setPath("/a"); cookie2.setPath("/a");
Comparator comparator = new CookiePathComparator(); Comparator<Cookie> comparator = new CookiePathComparator();
assertTrue(comparator.compare(cookie1, cookie2) == 0); assertTrue(comparator.compare(cookie1, cookie2) == 0);
assertTrue(comparator.compare(cookie2, cookie1) == 0); assertTrue(comparator.compare(cookie2, cookie1) == 0);
} }
@ -101,7 +101,7 @@ public class TestCookiePathComparator extends TestCase {
cookie1.setPath(null); cookie1.setPath(null);
BasicClientCookie cookie2 = new BasicClientCookie("name1", "value"); BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
cookie2.setPath("/"); cookie2.setPath("/");
Comparator comparator = new CookiePathComparator(); Comparator<Cookie> comparator = new CookiePathComparator();
assertTrue(comparator.compare(cookie1, cookie2) == 0); assertTrue(comparator.compare(cookie1, cookie2) == 0);
assertTrue(comparator.compare(cookie2, cookie1) == 0); assertTrue(comparator.compare(cookie2, cookie1) == 0);
} }
@ -111,7 +111,7 @@ public class TestCookiePathComparator extends TestCase {
cookie1.setPath("/this"); cookie1.setPath("/this");
BasicClientCookie cookie2 = new BasicClientCookie("name1", "value"); BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
cookie2.setPath("/that"); cookie2.setPath("/that");
Comparator comparator = new CookiePathComparator(); Comparator<Cookie> comparator = new CookiePathComparator();
assertTrue(comparator.compare(cookie1, cookie2) == 0); assertTrue(comparator.compare(cookie1, cookie2) == 0);
assertTrue(comparator.compare(cookie2, cookie1) == 0); assertTrue(comparator.compare(cookie2, cookie1) == 0);
} }

View File

@ -67,7 +67,7 @@ public class TestCookiePolicy extends TestCase {
public void testRegisterUnregisterCookieSpecFactory() { public void testRegisterUnregisterCookieSpecFactory() {
CookieSpecRegistry registry = new CookieSpecRegistry(); CookieSpecRegistry registry = new CookieSpecRegistry();
List names = registry.getSpecNames(); List<String> names = registry.getSpecNames();
assertNotNull(names); assertNotNull(names);
assertEquals(0, names.size()); assertEquals(0, names.size());

View File

@ -105,7 +105,7 @@ public class TestDigestScheme extends TestCase {
authscheme.processChallenge(authChallenge); authscheme.processChallenge(authChallenge);
Header authResponse = authscheme.authenticate(cred, request); Header authResponse = authscheme.authenticate(cred, request);
Map table = parseAuthResponse(authResponse); Map<String, String> table = parseAuthResponse(authResponse);
assertEquals("username", table.get("username")); assertEquals("username", table.get("username"));
assertEquals("realm1", table.get("realm")); assertEquals("realm1", table.get("realm"));
assertEquals("/", table.get("uri")); assertEquals("/", table.get("uri"));
@ -122,7 +122,7 @@ public class TestDigestScheme extends TestCase {
authscheme.processChallenge(authChallenge); authscheme.processChallenge(authChallenge);
Header authResponse = authscheme.authenticate(cred, request); Header authResponse = authscheme.authenticate(cred, request);
Map table = parseAuthResponse(authResponse); Map<String, String> table = parseAuthResponse(authResponse);
assertEquals("username", table.get("username")); assertEquals("username", table.get("username"));
assertEquals("realm1", table.get("realm")); assertEquals("realm1", table.get("realm"));
assertEquals("/", table.get("uri")); assertEquals("/", table.get("uri"));
@ -139,7 +139,7 @@ public class TestDigestScheme extends TestCase {
authscheme.processChallenge(authChallenge); authscheme.processChallenge(authChallenge);
Header authResponse = authscheme.authenticate(cred, request); Header authResponse = authscheme.authenticate(cred, request);
Map table = parseAuthResponse(authResponse); Map<String, String> table = parseAuthResponse(authResponse);
assertEquals("username", table.get("username")); assertEquals("username", table.get("username"));
assertEquals("realm1", table.get("realm")); assertEquals("realm1", table.get("realm"));
assertEquals("/?param=value", table.get("uri")); assertEquals("/?param=value", table.get("uri"));
@ -159,7 +159,7 @@ public class TestDigestScheme extends TestCase {
authscheme.processChallenge(authChallenge); authscheme.processChallenge(authChallenge);
Header authResponse = authscheme.authenticate(cred, request); Header authResponse = authscheme.authenticate(cred, request);
Map table = parseAuthResponse(authResponse); Map<String, String> table = parseAuthResponse(authResponse);
assertEquals("username", table.get("username")); assertEquals("username", table.get("username"));
assertEquals("realm1", table.get("realm")); assertEquals("realm1", table.get("realm"));
assertEquals("/", table.get("uri")); assertEquals("/", table.get("uri"));
@ -210,7 +210,7 @@ public class TestDigestScheme extends TestCase {
assertTrue(response.indexOf("nc=00000001") > 0); // test for quotes assertTrue(response.indexOf("nc=00000001") > 0); // test for quotes
assertTrue(response.indexOf("qop=auth") > 0); // test for quotes assertTrue(response.indexOf("qop=auth") > 0); // test for quotes
Map table = parseAuthResponse(authResponse); Map<String, String> table = parseAuthResponse(authResponse);
assertEquals(username, table.get("username")); assertEquals(username, table.get("username"));
assertEquals(realm, table.get("realm")); assertEquals(realm, table.get("realm"));
assertEquals("MD5-sess", table.get("algorithm")); assertEquals("MD5-sess", table.get("algorithm"));
@ -251,7 +251,7 @@ public class TestDigestScheme extends TestCase {
authscheme.processChallenge(authChallenge); authscheme.processChallenge(authChallenge);
Header authResponse = authscheme.authenticate(cred, request); Header authResponse = authscheme.authenticate(cred, request);
Map table = parseAuthResponse(authResponse); Map<String, String> table = parseAuthResponse(authResponse);
assertEquals(username, table.get("username")); assertEquals(username, table.get("username"));
assertEquals(realm, table.get("realm")); assertEquals(realm, table.get("realm"));
assertEquals("MD5-sess", table.get("algorithm")); assertEquals("MD5-sess", table.get("algorithm"));
@ -300,13 +300,13 @@ public class TestDigestScheme extends TestCase {
assertFalse(authscheme.isComplete()); assertFalse(authscheme.isComplete());
} }
private static Map parseAuthResponse(final Header authResponse) { private static Map<String, String> parseAuthResponse(final Header authResponse) {
String s = authResponse.getValue(); String s = authResponse.getValue();
if (!s.startsWith("Digest ")) { if (!s.startsWith("Digest ")) {
return null; return null;
} }
HeaderElement[] elements = BasicHeaderValueParser.parseElements(s.substring(7), null); HeaderElement[] elements = BasicHeaderValueParser.parseElements(s.substring(7), null);
Map map = new HashMap(elements.length); Map<String, String> map = new HashMap<String, String>(elements.length);
for (int i = 0; i < elements.length; i++) { for (int i = 0; i < elements.length; i++) {
HeaderElement element = elements[i]; HeaderElement element = elements[i];
map.put(element.getName(), element.getValue()); map.put(element.getName(), element.getValue());