Author: fmui
Date: Wed Jul  6 10:32:56 2016
New Revision: 1751653

URL: http://svn.apache.org/viewvc?rev=1751653&view=rev
Log:
CMIS-989: added preemptiv authentication parameter

Modified:
    chemistry/portcmis/trunk/PortCMIS/binding/BindingIntf.cs
    chemistry/portcmis/trunk/PortCMIS/client/SessionParameter.cs
    chemistry/portcmis/trunk/PortCMISWin/binding/WindowsBindingIntf.cs

Modified: chemistry/portcmis/trunk/PortCMIS/binding/BindingIntf.cs
URL: 
http://svn.apache.org/viewvc/chemistry/portcmis/trunk/PortCMIS/binding/BindingIntf.cs?rev=1751653&r1=1751652&r2=1751653&view=diff
==============================================================================
--- chemistry/portcmis/trunk/PortCMIS/binding/BindingIntf.cs (original)
+++ chemistry/portcmis/trunk/PortCMIS/binding/BindingIntf.cs Wed Jul  6 
10:32:56 2016
@@ -384,7 +384,17 @@ namespace PortCMIS.Binding
 
             if (User != null)
             {
-                httpClientHandler.Credentials = new NetworkCredential(User, 
Password);
+                httpClientHandler.PreAuthenticate = true;
+                string preemptiveFlag = 
Session.GetValue(SessionParameter.PreemptivAuthentication) as string;
+                if (preemptiveFlag != null && 
preemptiveFlag.ToLowerInvariant().Equals("true"))
+                {
+                    var userPassword = Encoding.UTF8.GetBytes(User + ":" + 
Password);
+                    AuthenticationHeader = new 
AuthenticationHeaderValue("Basic", Convert.ToBase64String(userPassword));
+                }
+                else
+                {
+                    httpClientHandler.Credentials = new 
NetworkCredential(User, Password);
+                }
             }
             else
             {

Modified: chemistry/portcmis/trunk/PortCMIS/client/SessionParameter.cs
URL: 
http://svn.apache.org/viewvc/chemistry/portcmis/trunk/PortCMIS/client/SessionParameter.cs?rev=1751653&r1=1751652&r2=1751653&view=diff
==============================================================================
--- chemistry/portcmis/trunk/PortCMIS/client/SessionParameter.cs (original)
+++ chemistry/portcmis/trunk/PortCMIS/client/SessionParameter.cs Wed Jul  6 
10:32:56 2016
@@ -35,6 +35,9 @@ namespace PortCMIS.Client
         /// <summary>Password</summary>
         public const string Password = 
"org.apache.chemistry.portcmis.password";
 
+        /// <summary>Preemptive authentication ("true" or "false") (basic auth 
only)</summary>
+        public const string PreemptivAuthentication = 
"org.apache.chemistry.portcmis.binding.auth.http.preemptive";
+
         // ---- provider parameter ----
 
         /// <summary>Binding Type ("atompub" or "browser")</summary>

Modified: chemistry/portcmis/trunk/PortCMISWin/binding/WindowsBindingIntf.cs
URL: 
http://svn.apache.org/viewvc/chemistry/portcmis/trunk/PortCMISWin/binding/WindowsBindingIntf.cs?rev=1751653&r1=1751652&r2=1751653&view=diff
==============================================================================
--- chemistry/portcmis/trunk/PortCMISWin/binding/WindowsBindingIntf.cs 
(original)
+++ chemistry/portcmis/trunk/PortCMISWin/binding/WindowsBindingIntf.cs Wed Jul  
6 10:32:56 2016
@@ -18,8 +18,9 @@
 */
 
 using PortCMIS.Client;
+using System;
+using System.Text;
 using Windows.Security.Credentials;
-using Windows.Security.Cryptography;
 using Windows.Web.Http;
 using Windows.Web.Http.Filters;
 using Windows.Web.Http.Headers;
@@ -95,7 +96,17 @@ namespace PortCMIS.Binding
 
             if (User != null)
             {
-                httpClientFilter.ServerCredential = new 
PasswordCredential("cmis", User, Password);
+                string preemptiveFlag = 
Session.GetValue(SessionParameter.PreemptivAuthentication) as string;
+                if (preemptiveFlag != null && 
preemptiveFlag.ToLowerInvariant().Equals("true"))
+                {
+                    var userPassword = Encoding.UTF8.GetBytes(User + ":" + 
Password);
+                    AuthenticationHeader = new 
HttpCredentialsHeaderValue("Basic", Convert.ToBase64String(userPassword));
+                }
+                else
+                {
+                    httpClientFilter.ServerCredential = new 
PasswordCredential("cmis", User, Password);
+
+                }
             }
             else if (BearerToken != null)
             {
@@ -104,8 +115,8 @@ namespace PortCMIS.Binding
 
             if (ProxyUser != null)
             {
-                var userPassword = 
CryptographicBuffer.ConvertStringToBinary(ProxyUser + ":" + ProxyPassword, 
BinaryStringEncoding.Utf16LE);
-                ProxyAuthenticationHeader = new 
HttpCredentialsHeaderValue("Basic", 
CryptographicBuffer.EncodeToBase64String(userPassword));
+                var userPassword = Encoding.UTF8.GetBytes(ProxyUser + ":" + 
ProxyPassword);
+                ProxyAuthenticationHeader = new 
HttpCredentialsHeaderValue("Basic", Convert.ToBase64String(userPassword));
             }
 
             if (CsrfHeader != null)


Reply via email to