You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@chemistry.apache.org by "Lu, Wentao" <We...@bchydro.com> on 2016/01/20 01:05:47 UTC

How to add a http header on DotCMIS

Hi,

We have a .NET client need to consume CMIS.  In java, we can use SessionParameters.HEADER to add more http headers in the request. How can we do the same on DotCMIS? It seems does not have such parameter on DotCMIS library.


Thanks
Wentao
________________________________
This email and its attachments are intended solely for the personal use of the individual or entity named above. Any use of this communication by an unintended recipient is strictly prohibited. If you have received this email in error, any publication, use, reproduction, disclosure or dissemination of its contents is strictly prohibited. Please immediately delete this message and its attachments from your computer and servers. We would also appreciate if you would contact us by a collect call or return email to notify us of this error. Thank you for your cooperation.
-BCHydroDisclaimerID5.2.8.1541

RE: How to add a http header on DotCMIS

Posted by "Lu, Wentao" <We...@bchydro.com>.
Thanks Florian.
I implemented a test provider but got a runtime errors "Could not load authentication provider: Value cannot be null. Parameter name: type"   

at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at DotCMIS.Binding.Impl.CmisBinding..ctor(IDictionary`2 sessionParameters, AbstractAuthenticationProvider authenticationProvider)".

Code Snip as below:

namespace ConsoleApplication1
{
    class Program
    {
       static void Main(string[] args)
	.....................
	parameters["MyAuth"] = "MyAuth:" + credentials;
	parameters[SessionParameter.AuthenticationProviderClass] = "ConsoleApplication1.MyAuthenticationProvider";
	SessionFactory factory = SessionFactory.NewInstance();
	ISession session = factory.CreateSession(parameters);
	.........................
	.........................

    public class MyAuthenticationProvider : StandardAuthenticationProvider
    {
        public MyAuthenticationProvider()
        {
            Cookies = new CookieContainer();
        }

        protected override void HttpAuthenticate(HttpWebRequest request)
        {
            string user = GetUser();
            string password = GetPassword();
            string MyAuth = Session.GetValue("MyAuth").ToString();

            request.AllowWriteStreamBuffering = false;
            request.CookieContainer = Cookies;
            if (user != null || password != null)
            {
                if (request.Headers.GetValues("Authorization") == null)
                {
                    request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes((user ?? "") + ":" + (password ?? ""))));
                    request.Headers.Add("MyAuth", MyAuth);
                }
            }
        }
    }

Could you help to check anything wrong?  Sorry I am not .NET developer.

Thanks
Wentao


-----Original Message-----
From: Florian Müller [mailto:fmui@apache.org] 
Sent: 2016, January 20 12:21 AM
To: dev@chemistry.apache.org
Cc: Lu, Wentao
Subject: Re: How to add a http header on DotCMIS

Hi Wentao,

There no such session parameter in DotCMIS.
You have to implement your own authentication provider to set HTTP headers.
The simplest way is to derive your own authentication provider from StandardAuthenticationProvider and override the HttpAuthenticate method.


- Florian


> Hi,
> 
> We have a .NET client need to consume CMIS.  In java, we can use 
> SessionParameters.HEADER to add more http headers in the request. How 
> can we do the same on DotCMIS? It seems does not have such parameter 
> on DotCMIS library.
> 
> 
> Thanks
> Wentao
> ________________________________
> This email and its attachments are intended solely for the personal 
> use of the individual or entity named above. Any use of this 
> communication by an unintended recipient is strictly prohibited. If 
> you have received this email in error, any publication, use, 
> reproduction, disclosure or dissemination of its contents is strictly 
> prohibited. Please immediately delete this message and its attachments 
> from your computer and servers. We would also appreciate if you would 
> contact us by a collect call or return email to notify us of this 
> error. Thank you for your cooperation.
> -BCHydroDisclaimerID5.2.8.1541


RE: How to add a http header on DotCMIS

Posted by "Lu, Wentao" <We...@bchydro.com>.
Never mind, it works now.

I just need to use the full assembly name for the value.  Simply use namespace + classname does not work.

parameters[SessionParameter.AuthenticationProviderClass] = "ConsoleApplication1.MyAuthenticationProvider";
	

Thanks
Wentao


-----Original Message-----
From: Lu, Wentao 
Sent: 2016, January 20 10:35 AM
To: 'Florian Müller'; dev@chemistry.apache.org
Subject: RE: How to add a http header on DotCMIS

Thanks Florian.
I implemented a test provider but got a runtime errors "Could not load authentication provider: Value cannot be null. Parameter name: type"   

at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at DotCMIS.Binding.Impl.CmisBinding..ctor(IDictionary`2 sessionParameters, AbstractAuthenticationProvider authenticationProvider)".

Code Snip as below:

namespace ConsoleApplication1
{
    class Program
    {
       static void Main(string[] args)
	.....................
	parameters["MyAuth"] = "MyAuth:" + credentials;
	parameters[SessionParameter.AuthenticationProviderClass] = "ConsoleApplication1.MyAuthenticationProvider";
	SessionFactory factory = SessionFactory.NewInstance();
	ISession session = factory.CreateSession(parameters);
	.........................
	.........................

    public class MyAuthenticationProvider : StandardAuthenticationProvider
    {
        public MyAuthenticationProvider()
        {
            Cookies = new CookieContainer();
        }

        protected override void HttpAuthenticate(HttpWebRequest request)
        {
            string user = GetUser();
            string password = GetPassword();
            string MyAuth = Session.GetValue("MyAuth").ToString();

            request.AllowWriteStreamBuffering = false;
            request.CookieContainer = Cookies;
            if (user != null || password != null)
            {
                if (request.Headers.GetValues("Authorization") == null)
                {
                    request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes((user ?? "") + ":" + (password ?? ""))));
                    request.Headers.Add("MyAuth", MyAuth);
                }
            }
        }
    }

Could you help to check anything wrong?  Sorry I am not .NET developer.

Thanks
Wentao


-----Original Message-----
From: Florian Müller [mailto:fmui@apache.org]
Sent: 2016, January 20 12:21 AM
To: dev@chemistry.apache.org
Cc: Lu, Wentao
Subject: Re: How to add a http header on DotCMIS

Hi Wentao,

There no such session parameter in DotCMIS.
You have to implement your own authentication provider to set HTTP headers.
The simplest way is to derive your own authentication provider from StandardAuthenticationProvider and override the HttpAuthenticate method.


- Florian


> Hi,
> 
> We have a .NET client need to consume CMIS.  In java, we can use 
> SessionParameters.HEADER to add more http headers in the request. How 
> can we do the same on DotCMIS? It seems does not have such parameter 
> on DotCMIS library.
> 
> 
> Thanks
> Wentao
> ________________________________
> This email and its attachments are intended solely for the personal 
> use of the individual or entity named above. Any use of this 
> communication by an unintended recipient is strictly prohibited. If 
> you have received this email in error, any publication, use, 
> reproduction, disclosure or dissemination of its contents is strictly 
> prohibited. Please immediately delete this message and its attachments 
> from your computer and servers. We would also appreciate if you would 
> contact us by a collect call or return email to notify us of this 
> error. Thank you for your cooperation.
> -BCHydroDisclaimerID5.2.8.1541


Re: How to add a http header on DotCMIS

Posted by Florian Müller <fm...@apache.org>.
Hi Wentao,

There no such session parameter in DotCMIS.
You have to implement your own authentication provider to set HTTP 
headers.
The simplest way is to derive your own authentication provider from 
StandardAuthenticationProvider and override the HttpAuthenticate method.


- Florian


> Hi,
> 
> We have a .NET client need to consume CMIS.  In java, we can use
> SessionParameters.HEADER to add more http headers in the request. How
> can we do the same on DotCMIS? It seems does not have such parameter
> on DotCMIS library.
> 
> 
> Thanks
> Wentao
> ________________________________
> This email and its attachments are intended solely for the personal
> use of the individual or entity named above. Any use of this
> communication by an unintended recipient is strictly prohibited. If
> you have received this email in error, any publication, use,
> reproduction, disclosure or dissemination of its contents is strictly
> prohibited. Please immediately delete this message and its attachments
> from your computer and servers. We would also appreciate if you would
> contact us by a collect call or return email to notify us of this
> error. Thank you for your cooperation.
> -BCHydroDisclaimerID5.2.8.1541