chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1129229 - in /chemistry/dotcmis/trunk/DotCMIS: binding/binding-impl.cs binding/binding-intf.cs client/client-impl.cs
Date Mon, 30 May 2011 15:49:24 GMT
Author: fmui
Date: Mon May 30 15:49:24 2011
New Revision: 1129229

URL: http://svn.apache.org/viewvc?rev=1129229&view=rev
Log:
DotCMIS: session can be created with authentication provider instance (see CMIS-379)

Modified:
    chemistry/dotcmis/trunk/DotCMIS/binding/binding-impl.cs
    chemistry/dotcmis/trunk/DotCMIS/binding/binding-intf.cs
    chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs

Modified: chemistry/dotcmis/trunk/DotCMIS/binding/binding-impl.cs
URL: http://svn.apache.org/viewvc/chemistry/dotcmis/trunk/DotCMIS/binding/binding-impl.cs?rev=1129229&r1=1129228&r2=1129229&view=diff
==============================================================================
--- chemistry/dotcmis/trunk/DotCMIS/binding/binding-impl.cs (original)
+++ chemistry/dotcmis/trunk/DotCMIS/binding/binding-impl.cs Mon May 30 15:49:24 2011
@@ -35,6 +35,11 @@ namespace DotCMIS.Binding.Impl
         private BindingRepositoryService repositoryServiceWrapper;
 
         public CmisBinding(IDictionary<string, string> sessionParameters)
+            : this(sessionParameters, null)
+        {
+        }
+
+        public CmisBinding(IDictionary<string, string> sessionParameters, AbstractAuthenticationProvider
authenticationProvider)
         {
             if (sessionParameters == null)
             {
@@ -54,21 +59,29 @@ namespace DotCMIS.Binding.Impl
             }
 
             // set up authentication provider
-            string authenticationProviderClass;
-            if (sessionParameters.TryGetValue(SessionParameter.AuthenticationProviderClass,
out authenticationProviderClass))
+            if (authenticationProvider == null)
             {
-                try
-                {
-                    Type authProvType = Type.GetType(authenticationProviderClass);
-                    AbstractAuthenticationProvider authenticationProvider = (AbstractAuthenticationProvider)Activator.CreateInstance(authProvType);
-                    authenticationProvider.Session = session;
-                    session.PutValue(BindingSession.AuthenticationProvider, authenticationProvider);
-                }
-                catch (Exception e)
+                string authenticationProviderClass;
+                if (sessionParameters.TryGetValue(SessionParameter.AuthenticationProviderClass,
out authenticationProviderClass))
                 {
-                    throw new CmisRuntimeException("Could not load authentictaion provider:
" + e.Message, e);
+                    try
+                    {
+                        Type authProvType = Type.GetType(authenticationProviderClass);
+                        authenticationProvider = (AbstractAuthenticationProvider)Activator.CreateInstance(authProvType);
+                        authenticationProvider.Session = session;
+                        session.PutValue(BindingSession.AuthenticationProvider, authenticationProvider);
+                    }
+                    catch (Exception e)
+                    {
+                        throw new CmisRuntimeException("Could not load authentictaion provider:
" + e.Message, e);
+                    }
                 }
             }
+            else
+            {
+                authenticationProvider.Session = session;
+                session.PutValue(BindingSession.AuthenticationProvider, authenticationProvider);
+            }
 
             // initialize the SPI
             GetSpi();

Modified: chemistry/dotcmis/trunk/DotCMIS/binding/binding-intf.cs
URL: http://svn.apache.org/viewvc/chemistry/dotcmis/trunk/DotCMIS/binding/binding-intf.cs?rev=1129229&r1=1129228&r2=1129229&view=diff
==============================================================================
--- chemistry/dotcmis/trunk/DotCMIS/binding/binding-intf.cs (original)
+++ chemistry/dotcmis/trunk/DotCMIS/binding/binding-intf.cs Mon May 30 15:49:24 2011
@@ -218,37 +218,43 @@ namespace DotCMIS.Binding
             }
         }
 
-        public ICmisBinding CreateCmisBinding(IDictionary<string, string> sessionParameters)
+        public ICmisBinding CreateCmisBinding(IDictionary<string, string> sessionParameters,
AbstractAuthenticationProvider authenticationProvider)
         {
             CheckSessionParameters(sessionParameters, true);
             AddDefaultParameters(sessionParameters);
 
-            return new CmisBinding(sessionParameters);
+            return new CmisBinding(sessionParameters, authenticationProvider);
         }
 
-        public ICmisBinding CreateCmisAtomPubBinding(IDictionary<string, string> sessionParameters)
+        public ICmisBinding CreateCmisAtomPubBinding(IDictionary<string, string> sessionParameters,
AbstractAuthenticationProvider authenticationProvider)
         {
             CheckSessionParameters(sessionParameters, false);
             sessionParameters[SessionParameter.BindingSpiClass] = BindingSpiAtomPub;
-            if (!sessionParameters.ContainsKey(SessionParameter.AuthenticationProviderClass))
+            if (authenticationProvider == null)
             {
-                sessionParameters[SessionParameter.AuthenticationProviderClass] = StandardAuthenticationProviderClass;
+                if (!sessionParameters.ContainsKey(SessionParameter.AuthenticationProviderClass))
+                {
+                    sessionParameters[SessionParameter.AuthenticationProviderClass] = StandardAuthenticationProviderClass;
+                }
             }
 
             AddDefaultParameters(sessionParameters);
 
             Check(sessionParameters, SessionParameter.AtomPubUrl);
 
-            return new CmisBinding(sessionParameters);
+            return new CmisBinding(sessionParameters, authenticationProvider);
         }
 
-        public ICmisBinding CreateCmisWebServicesBinding(IDictionary<string, string>
sessionParameters)
+        public ICmisBinding CreateCmisWebServicesBinding(IDictionary<string, string>
sessionParameters, AbstractAuthenticationProvider authenticationProvider)
         {
             CheckSessionParameters(sessionParameters, false);
             sessionParameters[SessionParameter.BindingSpiClass] = BindingSpiWebServices;
-            if (!sessionParameters.ContainsKey(SessionParameter.AuthenticationProviderClass))
+            if (authenticationProvider == null)
             {
-                sessionParameters[SessionParameter.AuthenticationProviderClass] = StandardAuthenticationProviderClass;
+                if (!sessionParameters.ContainsKey(SessionParameter.AuthenticationProviderClass))
+                {
+                    sessionParameters[SessionParameter.AuthenticationProviderClass] = StandardAuthenticationProviderClass;
+                }
             }
 
             AddDefaultParameters(sessionParameters);
@@ -263,7 +269,7 @@ namespace DotCMIS.Binding
             Check(sessionParameters, SessionParameter.WebServicesRepositoryService);
             Check(sessionParameters, SessionParameter.WebServicesVersioningService);
 
-            return new CmisBinding(sessionParameters);
+            return new CmisBinding(sessionParameters, authenticationProvider);
         }
 
         // ---- internals ----

Modified: chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs
URL: http://svn.apache.org/viewvc/chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs?rev=1129229&r1=1129228&r2=1129229&view=diff
==============================================================================
--- chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs (original)
+++ chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs Mon May 30 15:49:24 2011
@@ -45,7 +45,12 @@ namespace DotCMIS.Client.Impl
 
         public ISession CreateSession(IDictionary<string, string> parameters)
         {
-            Session session = new Session(parameters);
+            return CreateSession(parameters, null, null, null);
+        }
+
+        public ISession CreateSession(IDictionary<string, string> parameters, IObjectFactory
objectFactory, AbstractAuthenticationProvider authenticationProvider, ICache cache)
+        {
+            Session session = new Session(parameters, objectFactory, authenticationProvider,
cache);
             session.Connect();
 
             return session;
@@ -53,6 +58,11 @@ namespace DotCMIS.Client.Impl
 
         public IList<IRepository> GetRepositories(IDictionary<string, string>
parameters)
         {
+            return GetRepositories(parameters, null, null, null);
+        }
+
+        public IList<IRepository> GetRepositories(IDictionary<string, string>
parameters, IObjectFactory objectFactory, AbstractAuthenticationProvider authenticationProvider,
ICache cache)
+        {
             ICmisBinding binding = CmisBindingHelper.CreateBinding(parameters);
 
             IList<IRepositoryInfo> repositoryInfos = binding.GetRepositoryService().GetRepositoryInfos(null);
@@ -60,7 +70,7 @@ namespace DotCMIS.Client.Impl
             IList<IRepository> result = new List<IRepository>();
             foreach (IRepositoryInfo data in repositoryInfos)
             {
-                result.Add(new Repository(data, parameters, this));
+                result.Add(new Repository(data, parameters, this, objectFactory, authenticationProvider,
cache));
             }
 
             return result;
@@ -74,6 +84,11 @@ namespace DotCMIS.Client.Impl
     {
         public static ICmisBinding CreateBinding(IDictionary<string, string> parameters)
         {
+            return CreateBinding(parameters, null);
+        }
+
+        public static ICmisBinding CreateBinding(IDictionary<string, string> parameters,
AbstractAuthenticationProvider authenticationProvider)
+        {
             if (parameters == null)
             {
                 throw new ArgumentNullException("parameters");
@@ -88,36 +103,36 @@ namespace DotCMIS.Client.Impl
             switch (bt)
             {
                 case BindingType.AtomPub:
-                    return CreateAtomPubBinding(parameters);
+                    return CreateAtomPubBinding(parameters, authenticationProvider);
                 case BindingType.WebServices:
-                    return CreateWebServiceBinding(parameters);
+                    return CreateWebServiceBinding(parameters, authenticationProvider);
                 case BindingType.Custom:
-                    return CreateCustomBinding(parameters);
+                    return CreateCustomBinding(parameters, authenticationProvider);
                 default:
                     throw new CmisRuntimeException("Ambiguous session parameter: " + parameters);
             }
         }
 
-        private static ICmisBinding CreateCustomBinding(IDictionary<string, string>
parameters)
+        private static ICmisBinding CreateCustomBinding(IDictionary<string, string>
parameters, AbstractAuthenticationProvider authenticationProvider)
         {
             CmisBindingFactory factory = CmisBindingFactory.NewInstance();
-            ICmisBinding binding = factory.CreateCmisBinding(parameters);
+            ICmisBinding binding = factory.CreateCmisBinding(parameters, authenticationProvider);
 
             return binding;
         }
 
-        private static ICmisBinding CreateWebServiceBinding(IDictionary<string, string>
parameters)
+        private static ICmisBinding CreateWebServiceBinding(IDictionary<string, string>
parameters, AbstractAuthenticationProvider authenticationProvider)
         {
             CmisBindingFactory factory = CmisBindingFactory.NewInstance();
-            ICmisBinding binding = factory.CreateCmisWebServicesBinding(parameters);
+            ICmisBinding binding = factory.CreateCmisWebServicesBinding(parameters, authenticationProvider);
 
             return binding;
         }
 
-        private static ICmisBinding CreateAtomPubBinding(IDictionary<string, string>
parameters)
+        private static ICmisBinding CreateAtomPubBinding(IDictionary<string, string>
parameters, AbstractAuthenticationProvider authenticationProvider)
         {
             CmisBindingFactory factory = CmisBindingFactory.NewInstance();
-            ICmisBinding binding = factory.CreateCmisAtomPubBinding(parameters);
+            ICmisBinding binding = factory.CreateCmisAtomPubBinding(parameters, authenticationProvider);
 
             return binding;
         }
@@ -129,20 +144,26 @@ namespace DotCMIS.Client.Impl
     public class Repository : RepositoryInfo, IRepository
     {
         private IDictionary<string, string> parameters;
-        private ISessionFactory sessionFactory;
+        private SessionFactory sessionFactory;
+        private IObjectFactory objectFactory;
+        private AbstractAuthenticationProvider authenticationProvider;
+        private ICache cache;
 
-        public Repository(IRepositoryInfo info, IDictionary<string, string> parameters,
ISessionFactory sessionFactory)
+        public Repository(IRepositoryInfo info, IDictionary<string, string> parameters,
SessionFactory sessionFactory, IObjectFactory objectFactory, AbstractAuthenticationProvider
authenticationProvider, ICache cache)
             : base(info)
         {
             this.parameters = new Dictionary<string, string>(parameters);
             this.parameters[SessionParameter.RepositoryId] = Id;
 
             this.sessionFactory = sessionFactory;
+            this.objectFactory = objectFactory;
+            this.authenticationProvider = authenticationProvider;
+            this.cache = cache;
         }
 
         public ISession CreateSession()
         {
-            return sessionFactory.CreateSession(parameters);
+            return sessionFactory.CreateSession(parameters, objectFactory, authenticationProvider,
cache);
         }
     }
 
@@ -168,6 +189,7 @@ namespace DotCMIS.Client.Impl
         public string RepositoryId { get { return RepositoryInfo.Id; } }
 
         public IObjectFactory ObjectFactory { get; protected set; }
+        protected AbstractAuthenticationProvider AuthenticationProvider { get; set; }
         protected ICache Cache { get; set; }
         protected bool cachePathOmit;
 
@@ -200,7 +222,7 @@ namespace DotCMIS.Client.Impl
             }
         }
 
-        public Session(IDictionary<string, string> parameters)
+        public Session(IDictionary<string, string> parameters, IObjectFactory objectFactory,
AbstractAuthenticationProvider authenticationProvider, ICache cache)
         {
             if (parameters == null)
             {
@@ -209,8 +231,9 @@ namespace DotCMIS.Client.Impl
 
             this.parameters = parameters;
 
-            ObjectFactory = CreateObjectFactory();
-            Cache = CreateCache();
+            ObjectFactory = (objectFactory == null ? CreateObjectFactory() : objectFactory);
+            AuthenticationProvider = authenticationProvider;
+            Cache = (cache == null ? CreateCache() : cache);
 
             string cachePathOmitStr;
             if (parameters.TryGetValue(SessionParameter.CachePathOmit, out cachePathOmitStr))
@@ -228,7 +251,7 @@ namespace DotCMIS.Client.Impl
             Lock();
             try
             {
-                Binding = CmisBindingHelper.CreateBinding(parameters);
+                Binding = CmisBindingHelper.CreateBinding(parameters, AuthenticationProvider);
 
                 string repositoryId;
                 if (!parameters.TryGetValue(SessionParameter.RepositoryId, out repositoryId))



Mime
View raw message