<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Milet's Logbook</title><link>http://blogs.msdn.com/pierreml/default.aspx</link><description>BizTalk, .NET development, and more</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Flowing credentials through BizTalk</title><link>http://blogs.msdn.com/pierreml/archive/2009/02/13/flowing-credentials-through-biztalk.aspx</link><pubDate>Fri, 13 Feb 2009 19:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9419347</guid><dc:creator>pierreml</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/pierreml/comments/9419347.aspx</comments><wfw:commentRss>http://blogs.msdn.com/pierreml/commentrss.aspx?PostID=9419347</wfw:commentRss><description>&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;</description><enclosure url="http://blogs.msdn.com/pierreml/attachment/9419347.ashx" length="17268" type="image/x-png" /><category domain="http://blogs.msdn.com/pierreml/archive/tags/BizTalk+Security+Credentials+WSE/default.aspx">BizTalk Security Credentials WSE</category></item><item><title>BizMock - BizTalk Fluent Tests</title><link>http://blogs.msdn.com/pierreml/archive/2009/02/13/bizmock.aspx</link><pubDate>Fri, 13 Feb 2009 19:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9419212</guid><dc:creator>pierreml</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/pierreml/comments/9419212.aspx</comments><wfw:commentRss>http://blogs.msdn.com/pierreml/commentrss.aspx?PostID=9419212</wfw:commentRss><description>&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;</description><category domain="http://blogs.msdn.com/pierreml/archive/tags/BizTalk+Test+FluentInterface+DDD+DSL+TDD/default.aspx">BizTalk Test FluentInterface DDD DSL TDD</category></item></channel></rss>