chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r792983 - in /incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client: ContentManager.java connector/APPContentManager.java connector/Connector.java connector/HttpClientConnector.java
Date Fri, 10 Jul 2009 15:30:30 GMT
Author: fguillaume
Date: Fri Jul 10 15:30:29 2009
New Revision: 792983

URL: http://svn.apache.org/viewvc?rev=792983&view=rev
Log:
CMIS-21: move CredentialsProvider from ContentManager to Connector

Modified:
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ContentManager.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/APPContentManager.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Connector.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientConnector.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ContentManager.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ContentManager.java?rev=792983&r1=792982&r2=792983&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ContentManager.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ContentManager.java
Fri Jul 10 15:30:29 2009
@@ -18,7 +18,6 @@
 package org.apache.chemistry.atompub.client;
 
 import org.apache.chemistry.Repository;
-import org.apache.commons.httpclient.auth.CredentialsProvider;
 
 /**
  * The entry point to CMIS repositories exposed by a server.
@@ -43,8 +42,6 @@
 
     Repository getRepository(String id) throws ContentManagerException;
 
-    CredentialsProvider getCredentialsProvider();
-
     /**
      * Logs-in as the given user. All the subsequent connections made by this
      * content manager will use this login.

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/APPContentManager.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/APPContentManager.java?rev=792983&r1=792982&r2=792983&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/APPContentManager.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/APPContentManager.java
Fri Jul 10 15:30:29 2009
@@ -24,7 +24,6 @@
 import org.apache.commons.httpclient.Credentials;
 import org.apache.commons.httpclient.UsernamePasswordCredentials;
 import org.apache.commons.httpclient.auth.AuthScheme;
-import org.apache.commons.httpclient.auth.CredentialsNotAvailableException;
 import org.apache.commons.httpclient.auth.CredentialsProvider;
 
 /**
@@ -38,7 +37,7 @@
 
     protected Repository[] repos;
 
-    protected CredentialsProvider credentialsProvider;
+    protected String username;
 
     public APPContentManager(String url) {
         this(url, null);
@@ -47,7 +46,7 @@
     protected APPContentManager(String url, Connector connector) {
         this.baseUrl = url;
         if (connector == null) {
-            connector = new HttpClientConnector(new DefaultIOProvider(), this);
+            connector = new HttpClientConnector(new DefaultIOProvider());
         }
         this.connector = connector;
     }
@@ -75,8 +74,7 @@
         return repos;
     }
 
-    public Repository getRepository(String id)
-            throws ContentManagerException {
+    public Repository getRepository(String id) throws ContentManagerException {
         for (Repository repository : getRepositories()) {
             if (repository.getId().equals(id)) {
                 return repository;
@@ -101,31 +99,19 @@
 
     // TODO have another login method with more generic Credentials
     public void login(String username, String password) {
-        credentialsProvider = new UsernamePasswordCredentialsProvider(username,
-                password);
+        this.username = username;
+        CredentialsProvider cp = new UsernamePasswordCredentialsProvider(
+                username, password);
+        connector.setCredentialsProvider(cp);
     }
 
     public void logout() {
-        credentialsProvider = null;
-    }
-
-    public CredentialsProvider getCredentialsProvider() {
-        return credentialsProvider;
+        username = null;
+        connector.setCredentialsProvider(null);
     }
 
     public String getCurrentLogin() {
-        Credentials credentials;
-        try {
-            credentials = credentialsProvider.getCredentials(null, null, 0,
-                    false);
-        } catch (CredentialsNotAvailableException e) {
-            // cannot happen, our SimpleCredentialsProvider doesn't throw it
-            return null;
-        }
-        if (!(credentials instanceof UsernamePasswordCredentials)) {
-            return null;
-        }
-        return ((UsernamePasswordCredentials) credentials).getUserName();
+        return username;
     }
 
     /**

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Connector.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Connector.java?rev=792983&r1=792982&r2=792983&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Connector.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Connector.java
Fri Jul 10 15:30:29 2009
@@ -24,12 +24,15 @@
 import org.apache.chemistry.atompub.client.ContentManagerException;
 import org.apache.chemistry.atompub.client.stax.ReadContext;
 import org.apache.chemistry.atompub.client.stax.XmlObjectWriter;
+import org.apache.commons.httpclient.auth.CredentialsProvider;
 
 /**
  * A Connector abstracts the HTTP or AtomPub operations.
  */
 public interface Connector {
 
+    void setCredentialsProvider(CredentialsProvider credentialsProvider);
+
     <T> Response post(Request operation, XmlObjectWriter<T> writer, T object)
             throws ContentManagerException;
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientConnector.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientConnector.java?rev=792983&r1=792982&r2=792983&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientConnector.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientConnector.java
Fri Jul 10 15:30:29 2009
@@ -23,13 +23,13 @@
 import org.apache.chemistry.ObjectEntry;
 import org.apache.chemistry.Repository;
 import org.apache.chemistry.Type;
-import org.apache.chemistry.atompub.client.ContentManager;
 import org.apache.chemistry.atompub.client.ContentManagerException;
 import org.apache.chemistry.atompub.client.stax.ReadContext;
 import org.apache.chemistry.atompub.client.stax.XmlObjectWriter;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpMethod;
 import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.auth.CredentialsProvider;
 import org.apache.commons.httpclient.methods.DeleteMethod;
 import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.httpclient.methods.HeadMethod;
@@ -46,13 +46,14 @@
 
     protected final IOProvider io;
 
-    public HttpClientConnector(IOProvider io, ContentManager cm) {
+    public HttpClientConnector(IOProvider io) {
         this.io = io;
-        this.client = new HttpClient();
-        this.client.getParams().setAuthenticationPreemptive(true);
-        this.client.getParams().setParameter(
-                org.apache.commons.httpclient.auth.CredentialsProvider.PROVIDER,
-                cm.getCredentialsProvider());
+        client = new HttpClient();
+    }
+
+    public void setCredentialsProvider(CredentialsProvider cp) {
+        client.getParams().setAuthenticationPreemptive(true);
+        client.getParams().setParameter(CredentialsProvider.PROVIDER, cp);
     }
 
     protected void setMethodParams(HttpMethod method, Request request) {



Mime
View raw message