abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r429443 - in /incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client: Client.java CommonsClient.java
Date Mon, 07 Aug 2006 19:29:48 GMT
Author: jmsnell
Date: Mon Aug  7 12:29:47 2006
New Revision: 429443

URL: http://svn.apache.org/viewvc?rev=429443&view=rev
Log:
Bubble authentication up to the surface of the Client interface.  This puts a direct dependency
on HttpClient in the interface
for setting auth credentials, registering alternative auth schemes, and declaring the auth
priority preferences.  There's not 
much we can do about it unless we create an abstraction over the HttpClient AuthScheme and
Credentials interfaces... 
which would be silly.

Modified:
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/Client.java
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsClient.java

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/Client.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/Client.java?rev=429443&r1=429442&r2=429443&view=diff
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/Client.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/Client.java
Mon Aug  7 12:29:47 2006
@@ -18,10 +18,14 @@
 package org.apache.abdera.protocol.client;
 
 import java.io.InputStream;
+import java.net.URISyntaxException;
 
 import org.apache.abdera.model.Base;
 import org.apache.abdera.protocol.cache.Cache;
 import org.apache.abdera.protocol.cache.CacheFactory;
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.auth.AuthPolicy;
+import org.apache.commons.httpclient.auth.AuthScheme;
 import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
 import org.apache.commons.httpclient.methods.RequestEntity;
 
@@ -31,6 +35,15 @@
 
   public abstract RequestOptions getDefaultRequestOptions();
   
+  public abstract void addCredentials(
+    String target, 
+    String realm,
+    String scheme,
+    Credentials credentials) 
+      throws URISyntaxException;
+  
+  public abstract void setAuthenticationSchemePriority(String... scheme);
+  
   public abstract void usePreemptiveAuthentication(boolean val);
   
   public abstract void init(String userAgent);
@@ -158,4 +171,8 @@
     String uri, 
     RequestEntity entity, 
     RequestOptions options);
+  
+  public static void registerScheme(String name, Class<AuthScheme> scheme) {
+    AuthPolicy.registerAuthScheme(name, scheme);
+  }
 }

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsClient.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsClient.java?rev=429443&r1=429442&r2=429443&view=diff
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsClient.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsClient.java
Mon Aug  7 12:29:47 2006
@@ -17,12 +17,19 @@
 */
 package org.apache.abdera.protocol.client;
 
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+
 import org.apache.abdera.protocol.cache.Cache;
 import org.apache.abdera.protocol.cache.CacheDisposition;
 import org.apache.abdera.protocol.cache.CachedResponse;
 import org.apache.abdera.util.Version;
+import org.apache.commons.httpclient.Credentials;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.auth.AuthPolicy;
+import org.apache.commons.httpclient.auth.AuthScope;
 import org.apache.commons.httpclient.methods.DeleteMethod;
 import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
 import org.apache.commons.httpclient.methods.GetMethod;
@@ -188,4 +195,27 @@
     return options;
   }
 
+  @Override
+  public void addCredentials(
+    String target,
+    String realm,
+    String scheme,
+    Credentials credentials) 
+      throws URISyntaxException {
+    URI uri = new URI(target);
+    AuthScope scope = 
+      new AuthScope(
+        uri.getHost(), 
+        uri.getPort(), 
+        realm, scheme);
+    client.getState().setCredentials(
+      scope, credentials);
+  }
+
+  public void setAuthenticationSchemePriority(String... scheme) {
+    List authPrefs = java.util.Arrays.asList(scheme);
+    client.getParams().setParameter(
+      AuthPolicy.AUTH_SCHEME_PRIORITY, 
+      authPrefs);
+  }
 }



Mime
View raw message