CMIS-989: added preemptiv authentication parameter
git-svn-id: https://svn.apache.org/repos/asf/chemistry/portcmis/trunk@1751653 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/PortCMIS/binding/BindingIntf.cs b/PortCMIS/binding/BindingIntf.cs
index 5e19fec..ae3dbea 100644
--- a/PortCMIS/binding/BindingIntf.cs
+++ b/PortCMIS/binding/BindingIntf.cs
@@ -384,7 +384,17 @@
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
{
diff --git a/PortCMIS/client/SessionParameter.cs b/PortCMIS/client/SessionParameter.cs
index 2d6080f..cc5e303 100644
--- a/PortCMIS/client/SessionParameter.cs
+++ b/PortCMIS/client/SessionParameter.cs
@@ -35,6 +35,9 @@
/// <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>
diff --git a/PortCMISWin/binding/WindowsBindingIntf.cs b/PortCMISWin/binding/WindowsBindingIntf.cs
index 3502510..dfc1a10 100644
--- a/PortCMISWin/binding/WindowsBindingIntf.cs
+++ b/PortCMISWin/binding/WindowsBindingIntf.cs
@@ -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 @@
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 @@
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)