<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Milet's Logbook</title><subtitle type="html">BizTalk, .NET development, and more</subtitle><id>http://blogs.msdn.com/pierreml/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/pierreml/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/pierreml/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2009-02-13T16:27:00Z</updated><entry><title>Flowing credentials through BizTalk</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/pierreml/archive/2009/02/13/flowing-credentials-through-biztalk.aspx" /><link rel="enclosure" type="image/x-png" length="17268" href="http://blogs.msdn.com/pierreml/attachment/9419347.ashx" /><id>http://blogs.msdn.com/pierreml/archive/2009/02/13/flowing-credentials-through-biztalk.aspx</id><published>2009-02-13T19:54:00Z</published><updated>2009-02-13T19:54:00Z</updated><content type="html">&lt;P&gt;&lt;STRONG&gt;Scenario&lt;/STRONG&gt;: You&amp;nbsp; have a client application, with a user logged on with a domain user ( kerberos credentilas ). The application&amp;nbsp;calls a BizTalk Server 2004 orchestration&amp;nbsp;( a business process ) that calls&amp;nbsp;a Back End Web Service. The Web Service needs to know who is the logged user to take a decision on which task it has to execute.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Solution: &lt;/STRONG&gt;Extract from the input message the OriginatorSID context property (that &lt;BR&gt;contains the LogonUser string ) then impersonate it using a helper &lt;BR&gt;component :&lt;BR&gt;&lt;BR&gt;for example with an expression&amp;nbsp;shape&amp;nbsp;like this: &lt;BR&gt;bizImpHelper.Impersonate(IncomingMessage(Microsoft.BizTalk.XLANGs.BTXEngine.OriginatorSID));&lt;BR&gt;&lt;BR&gt;This is the helper class that does the impersonation: &lt;BR&gt;&lt;BR&gt;[Serializable]&lt;BR&gt;public class BizTalkImpersonationHelper&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; private BizTalkImpersonationContext bizImpCtxt; &lt;BR&gt;&amp;nbsp; public BizTalkImpersonationHelper()&lt;BR&gt;&amp;nbsp; {}&lt;BR&gt;&lt;BR&gt;&amp;nbsp; public void Impersonate( string logonUser )&lt;BR&gt;&amp;nbsp; {&lt;BR&gt;&amp;nbsp; &amp;nbsp; int slash = logonUser.IndexOf("\\");&lt;BR&gt;&amp;nbsp; &amp;nbsp; if( slash &amp;gt; 0 ){&lt;BR&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; string domain = logonUser.Substring(0,slash);&lt;BR&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; string user = logonUser.Substring(slash+1); &lt;BR&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; logonUser =&amp;nbsp; user + "@" + domain;&lt;BR&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; bizImpCtxt = new BizTalkImpersonationContext();&lt;BR&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; bizImpCtxt.Impersonate(logonUser);&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; public void UnDo()&lt;BR&gt;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if( bizImpCtxt != null )&lt;BR&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; bizImpCtxt.Undo();&lt;BR&gt;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;BR&gt;&lt;BR&gt;[Serializable]&lt;BR&gt;internal class BizTalkImpersonationContext&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp; private System.Security.Principal.WindowsIdentity identity;&lt;BR&gt;&amp;nbsp; [ThreadStatic]&lt;BR&gt;&amp;nbsp; static WindowsImpersonationContext wic ;&lt;BR&gt;&amp;nbsp; internal void Impersonate( string logonUser )&lt;BR&gt;&amp;nbsp; {&lt;BR&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; if( wic != null )&lt;BR&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; wic.Undo();&lt;BR&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; identity = new System.Security.Principal.WindowsIdentity(logonUser);&lt;BR&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; wic = &lt;BR&gt;((System.Security.Principal.WindowsIdentity)identity).Impersonate();&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;&lt;BR&gt;&amp;nbsp; internal void Undo()&lt;BR&gt;&amp;nbsp; {&lt;BR&gt;&amp;nbsp; &amp;nbsp; if( wic != null)&lt;BR&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; wic.Undo();&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;}&lt;BR&gt;&amp;nbsp;&lt;BR&gt;Declare the WindowsImpersonationContext thread static, to avoid &lt;BR&gt;collisions between different running orchestrations.&lt;BR&gt;&lt;BR&gt;In the orchestration&amp;nbsp;you should&amp;nbsp;define a scope to: &lt;BR&gt;&lt;BR&gt;1. Impersonate the caller&lt;BR&gt;2. Send the message and receive the response&lt;BR&gt;3. Undo the impersonation to restablish the biztalk service security context&lt;BR&gt;&lt;BR&gt;In the exception handler&lt;BR&gt;Undo the impersonation&lt;/P&gt;
&lt;P&gt;Note that&amp;nbsp;the BizTalk host&amp;nbsp;has to run under&amp;nbsp;a&amp;nbsp;domain account, that you have to create a service principal name for that account,&amp;nbsp;and configure it to&amp;nbsp;be trusted for delegation to the&amp;nbsp;specified service&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;BR&gt;A better approach maybe is to encapsulate that logic inside a pipeline &lt;BR&gt;component, that you can apply to any send port that needs to flow &lt;BR&gt;credentials. &lt;BR&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9419347" width="1" height="1"&gt;</content><author><name>pierreml</name><uri>http://blogs.msdn.com/members/pierreml.aspx</uri></author><category term="BizTalk Security Credentials WSE" scheme="http://blogs.msdn.com/pierreml/archive/tags/BizTalk+Security+Credentials+WSE/default.aspx" /></entry><entry><title>BizMock - BizTalk Fluent Tests</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/pierreml/archive/2009/02/13/bizmock.aspx" /><id>http://blogs.msdn.com/pierreml/archive/2009/02/13/bizmock.aspx</id><published>2009-02-13T19:27:00Z</published><updated>2009-02-13T19:27:00Z</updated><content type="html">&lt;P&gt;BizMock is a framework for testing BizTalk solutions,&amp;nbsp;using a&amp;nbsp;Domain Driven Design (DDD)&amp;nbsp;approach and fluent interface API. It&amp;nbsp;has&amp;nbsp;mocking capabilities, so no need to rely on dependent infraestructure like web services or DBs. The tests are&amp;nbsp;writen and executed&amp;nbsp;from within VS using regular Visual Studio Tests and C# code, allowing a TDD and&amp;nbsp;agile development&amp;nbsp;style of BizTalk solutions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it's main advantages are:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Rapid testing of Biztalk scenarios ( no more excuses to not test biztalk code) 
&lt;LI&gt;No need to leave the Visual Studio IDE 
&lt;LI&gt;We use regular Visual Studio C# Unit Tests code ( no puzzling xml) . 
&lt;LI&gt;Favors agile iterative development cycles with continous Integration. 
&lt;LI&gt;No need to rely on real implementations of dependent infraestructure like web services, Databases, etc. ( isolated on the developer machine or build server ) 
&lt;LI&gt;Increasead level of abstraction thanks to its Domain Driven Design approach and fluent interface. 
&lt;LI&gt;Rapid and guided development thanks to intelisense and its fluent interface API. 
&lt;LI&gt;Reusability of domain artifacts across tests, like ports, messages, verifiers etc. 
&lt;LI&gt;Extensibility model to allow the creation of new artifacts, actions, and expectations types over time and reused across solutions 
&lt;LI&gt;Leverages DDT ( Data Driven Test) 
&lt;LI&gt;In future releases can be enhanced with Visual Studio addins and tools: to automatically update deployments, autogenerate artifacts, autogenerate map and message verifiers tests. 
&lt;LI&gt;In future releases can be enhanced with guidance automation to guide the process and implement best practices 
&lt;LI&gt;In fututre realeases can be integrated wirth functional testing tools like FIT, to quickly create integration scenarios test cases &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;To know more&amp;nbsp;visit &lt;A href="http://www.codeplex.com/bizmock" mce_href="http://www.codeplex.com/bizmock"&gt;http://www.codeplex.com/bizmock&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9419212" width="1" height="1"&gt;</content><author><name>pierreml</name><uri>http://blogs.msdn.com/members/pierreml.aspx</uri></author><category term="BizTalk Test FluentInterface DDD DSL TDD" scheme="http://blogs.msdn.com/pierreml/archive/tags/BizTalk+Test+FluentInterface+DDD+DSL+TDD/default.aspx" /></entry></feed>