
<rss version="2.0">
  <channel>
    <title>Dblock.org | Code</title>
    <description>technology website</description>
    <link>http://code.dblock.org/</link>
    <language>en-us</language>
    <image>
      <url>http://code.dblock.org/images/blog/blog.gif</url>
      <title>Dblock.org | Code</title>
      <link>http://code.dblock.org/</link>
      <width>72</width>
      <height>49</height>
    </image>
    
      <item>
       <title>dotNetInstaller 1.10 Released</title>
       <pubDate>Mon, 26 Jul 2010 00:43:40 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p><a href="http://code.dblock.org/ShowPicture.aspx?id=84&ShowThumbnail=false"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="dni" border="0" alt="dni" src="http://code.dblock.org/ShowPicture.aspx?id=85&ShowThumbnail=false" width="160" height="63" /></a> </p>  <p>dotNetInstaller 1.10 was released July 12th, 2010. dotNetInstaller is a very popular general purpose setup bootstrapper for Microsoft Windows created by Davide Icardi. I’ve been maintaining the project and contributing the vast majority of the features since 2008, mostly driven by our needs at <a href="http://www.appsecinc.com">work</a>. </p>  <blockquote>   <p><a href="http://dotnetinstaller.codeplex.com/">&gt; Download</a></p> </blockquote>  <p>Here’re some highlights in this release.</p>  <ul>   <li>Added support for executable components with an optional response file and installation directory. </li>    <li>Added lots of convenience features in Installer Editor, such as remembering configuration files. </li>    <li>Added os_filter that behaves like lcid_filter for operating system IDs. </li>    <li>Added user-defined image control. </li>    <li>Holding the keyboard Control key and double-clicking on a bootstrapper component will install it, regardless of whether the component is selected or not. </li>    <li>Added /ProcessorArchitecture:list to InstallerLinker to link an installer targeting a specific platform architecture. </li> </ul>  <p>The next release (2.0) should be very exciting as I’ve been prototyping an HTML-based installer that gives users full control of the bootstrapper UI. Stay tuned.</p></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=117">Read</a> | Updated 7/26/2010</div></html>
         ]]>
       </description>
       <category>dotnetinstaller</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=117</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/117</guid>
      </item>
     
      <item>
       <title>Waffle 1.3 Released</title>
       <pubDate>Sun, 25 Jul 2010 19:19:51 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p><a href="http://waffle.codeplex.com/"><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="waffle" border="0" alt="waffle" align="right" src="http://code.dblock.org/ShowPicture.aspx?id=79&ShowThumbnail=false" width="164" height="67" /></a>WAFFLE exposes native Windows authentication facilities to C# and Java clients using JNA. Version 1.3 has shipped Wednesday, July 21, 2010. WAFFLE has seen incredible interest and <a href="http://waffle.codeplex.com/Thread/View.aspx?ThreadId=203792">production adoption</a> in the last few months as I’ve coded a bunch of Java filters &gt; <a href="http://waffle.codeplex.com/">Download 1.3</a>.</p>  <ul>   <li>If you’re writing PInvoke in C# or Java code for Windows authentication, save yourself some time, WAFFLE has these features for you:</li>    <ul>     <li>Account lookup locally and in Active Directory via Win32 API with zero configuration. </li>      <li>Enumerating Active Directory domains and domain information. </li>      <li>Returns computer domain / workgroup join information. </li>      <li>Supports logon for local and domain users returning consistent fully qualified names, identity (SIDs), local and domain groups, including nested. </li>      <li>Supports all functions required for implementing server-side single-signon with Negotiate and NTLM. </li>      <li>Supports Windows Identity impersonation. </li>      <li>Includes a Windows Installer Merge Module for distribution of C# binaries. </li>   </ul>    <li>If you're using Tomcat or Jetty with an IIS front-end to do authentication only, Waffle has the following features and will allow you to get rid of IIS:</li>    <ul>     <li>A Tomcat Negotiate (NTLM and Kerberos) Authenticator Valve - <a href="http://code.dblock.org/ShowPost.aspx?id=103">Tutorial</a>.</li>      <li>A generic Servlet Negotiate (NTLM and Kerberos) Security Filter - <a href="http://code.dblock.org/ShowPost.aspx?id=106">Tutorial</a>. </li>      <li>A Tomcat Single Sign-On + Form Authentication Mixed Valve - <a href="http://code.dblock.org/ShowPost.aspx?id=107">Tutorial</a>.</li>      <li>A Spring-Security Negotiate (NTLM and Kerberos) Filter - <a href="http://code.dblock.org/ShowPost.aspx?id=114">Totorial</a>.</li>      <li>A Spring-Security Windows Authentication Manager.</li>      <li>A JAAS Login Module - <a href="http://code.dblock.org/ShowPost.aspx?id=105">Tutorial</a>.</li>   </ul> </ul>  <p>WAFFLE has originated at <a href="http://www.appsecinc.com">AppSecInc.</a> and <a href="http://waffle.codeplex.com/team/view">the team</a> deserves the credit. John has <a href="http://blog.johnhite.com/">a blog</a> too, check it out.</p></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=116">Read</a></div></html>
         ]]>
       </description>
       <category>tomcat</category><category>spring</category><category>waffle</category><category>jna</category><category>active directory</category><category>win32</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=116</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/116</guid>
      </item>
     
      <item>
       <title>RemoteInstall Test Framework 1.2 Released</title>
       <pubDate>Sat, 17 Jul 2010 16:15:00 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped>I’ve released the RemoteInstaller Test Framework 1.2. It’s the second open-source release (click <a href="http://code.dblock.org/ShowPost.aspx?Id=62">here</a> for an intro) and I am pleased to see some community adoption. RemoteInstall is a system for automated testing based on VMWare technology and makes it easy to install software and execute tests against it.<br /><br />
The most important features in 1.2 include support for user-defined exit codes, support for rebooting between installers and passing snapshot-specific parameters around.<br /><br />
&gt; <a href="http://remoteinstall.codeplex.com/">Download</a><br /></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=115">Read</a> | Updated 7/17/2010</div></html>
         ]]>
       </description>
       <category>remoteinstall</category><category>testing</category><category>vmware</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=115</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/115</guid>
      </item>
     
      <item>
       <title>Single Sign-On: Spring-Security Negotiate Filter (Kerberos + NTLM) w/Waffle</title>
       <pubDate>Fri, 09 Jul 2010 15:10:36 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p><a href="http://code.dblock.org/ShowPicture.aspx?id=77&ShowThumbnail=false"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="springwaffle" border="0" alt="springwaffle" src="http://code.dblock.org/ShowPicture.aspx?id=78&ShowThumbnail=false" width="240" height="47" /></a>  </p>  <p>In this post I’ll explain how to configure the Waffle Spring-Security Negotiate filter to do single-sign-on on Windows and touch on how much more elegant the spring-based filter configuration is versus, for example, the <a href="http://code.dblock.org/ShowPost.aspx?id=106">generic servlet filter</a>.</p>  <p><strong>Download</strong></p>  <p>Download Waffle 1.3. The zip contains <em>Waffle.chm</em> with the latest version of this tutorial.</p>  <p><strong>Configure Your Application</strong></p>  <p><em>Configure Spring-Security</em></p>  <p>We'll assume that <a href="http://static.springsource.org/spring-security/site/">Spring-Security</a> is configured via web.xml with a filter chain and a Spring <em>ContextLoaderListener</em>. The Waffle beans configuration will be added to <em>waffle-filter.xml</em>.</p>  <blockquote>   <p>     </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">filter</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">filter-name</span><span style="color:#0000ff">&gt;</span>springSecurityFilterChain<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">filter-name</span><span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">filter-class</span><span style="color:#0000ff">&gt;</span>org.springframework.web.filter.DelegatingFilterProxy<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">filter-class</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">filter</span><span style="color:#0000ff">&gt;</span></li> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">filter-mapping</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">filter-name</span><span style="color:#0000ff">&gt;</span>springSecurityFilterChain<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">filter-name</span><span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">url-pattern</span><span style="color:#0000ff">&gt;</span>/*<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">url-pattern</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">filter-mapping</span><span style="color:#0000ff">&gt;</span></li> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">context-param</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">param-name</span><span style="color:#0000ff">&gt;</span>contextConfigLocation<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">param-name</span><span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">param-value</span><span style="color:#0000ff">&gt;</span>/WEB-INF/waffle-filter.xml<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">param-value</span><span style="color:#0000ff">&gt; </span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">context-param</span><span style="color:#0000ff">&gt;</span></li> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">listener</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">listener-class</span><span style="color:#0000ff">&gt;</span>org.springframework.web.context.ContextLoaderListener<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">listener-class</span><span style="color:#0000ff">&gt;</span></li> <li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">listener</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>    </blockquote>  <p><em>Package Files</em></p>  <p>You need waffle-jna.jar, jna.jar, platform.jar and commons-logging-1.1.1.jar from the Waffle distribution as well as Spring and Spring-security JARs. Those should be placed in your application’s classpath (eg. packaged in WAR). If you’re using Tomcat, for demo purposes you can put these files in Tomcat’s <em>lib</em>.</p>  <p><em>Windows Authentication Provider</em></p>  <p>Declare a Windows Authentication provider. This is the link between Waffle and the operating system.</p>  <blockquote>   <p>     </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">bean</span><span style="color:#0000ff"> </span><span style="color:#ff0000">id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffleWindowsAuthProvider</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">class</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffle.windows.auth.impl.WindowsAuthProviderImpl</span>"<span style="color:#0000ff"> /&gt;</span></li> </ol> </div> </div> </div>    </blockquote>  <p><em>Waffle Security Filter Providers</em></p>  <p>Declare a collection of Waffle security filter providers that implement various authentication protocols.</p>  <blockquote>   <p>     </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">bean</span><span style="color:#0000ff"> </span><span style="color:#ff0000">id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">negotiateSecurityFilterProvider</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">class</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffle.servlet.spi.NegotiateSecurityFilterProvider</span>"<span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">constructor-arg</span><span style="color:#0000ff"> </span><span style="color:#ff0000">ref</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffleWindowsAuthProvider</span>"<span style="color:#0000ff"> /&gt;</span></li> <li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">bean</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3"> </li> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">bean</span><span style="color:#0000ff"> </span><span style="color:#ff0000">id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">basicSecurityFilterProvider</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">class</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffle.servlet.spi.BasicSecurityFilterProvider</span>"<span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">constructor-arg</span><span style="color:#0000ff"> </span><span style="color:#ff0000">ref</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffleWindowsAuthProvider</span>"<span style="color:#0000ff"> /&gt;</span></li> <li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">bean</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3"> </li> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">bean</span><span style="color:#0000ff"> </span><span style="color:#ff0000">id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffleSecurityFilterProviderCollection</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">class</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffle.servlet.spi.SecurityFilterProviderCollection</span>"<span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">constructor-arg</span><span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">list</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">      <span style="color:#0000ff">&lt;</span><span style="color:#a31515">ref</span><span style="color:#0000ff"> </span><span style="color:#ff0000">bean</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">negotiateSecurityFilterProvider</span>"<span style="color:#0000ff"> /&gt;</span></li> <li>      <span style="color:#0000ff">&lt;</span><span style="color:#a31515">ref</span><span style="color:#0000ff"> </span><span style="color:#ff0000">bean</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">basicSecurityFilterProvider</span>"<span style="color:#0000ff"> /&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">list</span><span style="color:#0000ff">&gt;</span></li> <li>  <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">constructor-arg</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">bean</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>    </blockquote>  <p>If you’re not very familiar with Spring, you will start loving it right here. We’re adding two providers to a collection in a configuration file. This means that we don’t need to have another configuration mechanism than this one to add or remove one. We don’t need to do this in code either. Each class instance (bean) is also configurable individually – we can, for example, configure the name of the realm for Basic authentication.</p>  <blockquote>   <p>     </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">bean</span><span style="color:#0000ff"> </span><span style="color:#ff0000">id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">basicSecurityFilterProvider</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">class</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffle.servlet.spi.BasicSecurityFilterProvider</span>"<span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">constructor-arg</span><span style="color:#0000ff"> </span><span style="color:#ff0000">ref</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffleWindowsAuthProvider</span>"<span style="color:#0000ff"> /&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">property</span><span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Realm</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">value</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">DemoRealm</span>"<span style="color:#0000ff"> /&gt;</span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">bean</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>    </blockquote>  <p>It’s more verbose, but it’s much more flexible.</p>  <p><em>Add a Waffle Security Filter</em></p>  <p>Add the Waffle security filter and entry point to the <em>sec:http</em> configuration section. The filter will be placed before the Basic authentication filter that ships with Spring-Security. The filter uses the collection of authentication filter providers defined above to perform authentication.</p>  <blockquote>   <p>     </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">sec:http</span><span style="color:#0000ff"> </span><span style="color:#ff0000">entry-point-ref</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">negotiateSecurityFilterEntryPoint</span>"<span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">sec:intercept-url</span><span style="color:#0000ff"> </span><span style="color:#ff0000">pattern</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">/**</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">access</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">IS_AUTHENTICATED_FULLY</span>"<span style="color:#0000ff"> /&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">sec:custom-filter</span><span style="color:#0000ff"> </span><span style="color:#ff0000">ref</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffleNegotiateSecurityFilter</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">position</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">BASIC_AUTH_FILTER</span>"<span style="color:#0000ff"> /&gt;</span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">sec:http</span><span style="color:#0000ff">&gt;</span></li> <li> </li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;</span><span style="color:#a31515">bean</span><span style="color:#0000ff"> </span><span style="color:#ff0000">id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">negotiateSecurityFilterEntryPoint</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">class</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffle.spring.NegotiateSecurityFilterEntryPoint</span>"<span style="color:#0000ff">&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">property</span><span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Provider</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">ref</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffleSecurityFilterProviderCollection</span>"<span style="color:#0000ff"> /&gt;</span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">bean</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>    </blockquote>  <p><em>Spring-Security Authentication Manager</em></p>  <p>Define a required default Spring-Security authentication manager. We’re not going to use it in this setup because the filter takes care of authentication and the user doesn’t have a way to supply, for example, a username and password.</p>  <blockquote>   <p>     </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">sec:authentication-manager</span><span style="color:#0000ff"> </span><span style="color:#ff0000">alias</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">authenticationProvider</span>"<span style="color:#0000ff"> /&gt;</span></li> </ol> </div> </div> </div>    </blockquote>  <p>Note that Waffle does include a Spring-based authentication manager for form-based authentication or non-web-based scenarios.</p>  <p><em>The Filter Itself</em></p>  <p>Finally, define the Spring-Security Waffle filter that uses the collection of security filter providers to perform authentication.</p>  <blockquote>   <p>     </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">bean</span><span style="color:#0000ff"> </span><span style="color:#ff0000">id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffleNegotiateSecurityFilter</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">class</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffle.spring.NegotiateSecurityFilter</span>"<span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">property</span><span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Provider</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">ref</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffleSecurityFilterProviderCollection</span>"<span style="color:#0000ff"> /&gt;</span></li> <li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">bean</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>    </blockquote>  <p></p>  <p><strong>Demo Application</strong></p>  <p>A demo application with the complete configuration file can be found in the Waffle distribution in the <em>Samples\waffle-spring-filter</em> directory. Copy the entire directory into Tomcat's webapps directory and navigate to <a href="http://localhost:8080/waffle-spring-filter/">http://localhost:8080/waffle-spring-filter/</a>. You should be automatically logged-in under your current Windows account. </p>  <p>You can also see/browse the configuration source code <a href="http://waffle.codeplex.com/SourceControl/changeset/view/54977#1136921">here</a>.</p>  <p><strong>Links</strong></p>  <ul>   <li><a href="http://static.springsource.org/spring-security/site/">Spring-Security</a></li>    <li><a href="http://waffle.codeplex.com">Waffle</a></li> </ul></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=114">Read</a></div></html>
         ]]>
       </description>
       <category>spring</category><category>waffle</category><category>security</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=114</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/114</guid>
      </item>
     
      <item>
       <title>Iterating over lists in MSBuild</title>
       <pubDate>Wed, 07 Jul 2010 20:33:31 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p>I never remember how to do this, so here’s a refresher. In MSBuild you can easily define a list with properties and iterate over it.</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Project</span><span style="color:#0000ff"> </span><span style="color:#ff0000">DefaultTargets</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">all</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">xmlns</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">http://schemas.microsoft.com/developer/msbuild/2003</span>"<span style="color:#0000ff"> &gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">ItemGroup</span><span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Squirrel</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Include</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Bob</span>"<span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">      <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Color</span><span style="color:#0000ff">&gt;</span>green<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Color</span><span style="color:#0000ff">&gt;</span></li> <li>      <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Teeth</span><span style="color:#0000ff">&gt;</span>white<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Teeth</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Squirrel</span><span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Squirrel</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Include</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Marc</span>"<span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">      <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Color</span><span style="color:#0000ff">&gt;</span>orange<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Color</span><span style="color:#0000ff">&gt;</span></li> <li>      <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Teeth</span><span style="color:#0000ff">&gt;</span>yellow<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Teeth</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Squirrel</span><span style="color:#0000ff">&gt;</span></li> <li>  <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ItemGroup</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Target</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Name</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">ShowSquirrels</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Inputs</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">@Squirrel</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Outputs</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">%(Squirrel.Identity)</span>"<span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Message</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Text</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">%(Squirrel.Identity) is an %(Squirrel.Color) squirrel with %(Squirrel.Teeth) teeth</span>"<span style="color:#0000ff"> /&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Target</span><span style="color:#0000ff">&gt;</span></li> <li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Project</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>  <p>Run the sample above with <em>msbuild test.proj /t:ShowSquirrels</em>.</p></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=113">Read</a></div></html>
         ]]>
       </description>
       <category>msbuild</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=113</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/113</guid>
      </item>
     
      <item>
       <title>Introducing Oshi: Operating System and Hardware Information (Java)</title>
       <pubDate>Wed, 23 Jun 2010 01:10:34 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p><a href="http://code.dblock.org/ShowPicture.aspx?id=75&ShowThumbnail=false"><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="oshi" border="0" alt="oshi" align="right" src="http://code.dblock.org/ShowPicture.aspx?id=76&ShowThumbnail=false" width="72" height="96" /></a> Take <a href="http://www.hyperic.com/products/sigar">Hyperic SIGAR</a>, a very popular Java API that lets you collect system information. It has two major drawbacks.</p>  <ol>   <li>It uses a native library (eg. <em>hyperic-sigar-x86.dll)</em>, which you have to install separately from your application’s jar/war.</li>    <li>It’s GPL v2. My legal department immediate flagged that as a no-go since we’re a commercial product.</li> </ol>  <p>Sounds like we could live with the first problem, but we can’t live with the second. Licensing is a pest.</p>  <p>While we’re at it, we should be able to leverage <a href="https://jna.dev.java.net/">JNA</a> and fix the first problem too. In the end we could end up with a very nice library that lots of people use.</p>  <p><strong>Oshi Project</strong></p>  <p>Introducing the <em>Oshi Project</em>. I’ve put a day of work into it and a bit of design thought in terms of operating system and hardware interfaces. I’ve implemented those for Windows, so it can generate this kind of output.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li>Microsoft Windows 7</li> <li style="background: #f3f3f3">2 CPU(s):</li> <li> Intel(R) Core(TM)2 Duo CPU T7300  @ 2.00GHz</li> <li style="background: #f3f3f3"> Intel(R) Core(TM)2 Duo CPU T7300  @ 2.00GHz</li> <li>Memory: 532.1 MB/2.0 GB</li> </ol> </div> </div> </div>   <p>Here’s the code for the above.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li>SystemInfo si = <span style="color:#0000ff">new</span> SystemInfo();</li> <li style="background: #f3f3f3">OperatingSystem os = si.getOperatingSystem();</li> <li>System.out.println(os);</li> <li style="background: #f3f3f3">HardwareAbstractionLayer hal = si.getHardware();</li> <li>System.out.println(hal.getProcessors().length + <span style="color:#a31515">" CPU(s):"</span>);</li> <li style="background: #f3f3f3"><span style="color:#0000ff">for</span>(Processor cpu : hal.getProcessors()) {</li> <li>    System.out.println(<span style="color:#a31515">" "</span> + cpu);</li> <li style="background: #f3f3f3">}</li> <li>System.out.println(<span style="color:#a31515">"Memory: "</span> + </li> <li style="background: #f3f3f3">        FormatUtil.formatBytes(hal.getMemory().getAvailable()) + <span style="color:#a31515">"/"</span> + </li> <li>        FormatUtil.formatBytes(hal.getMemory().getTotal()));</li> </ol> </div> </div> </div>   <p><strong>What’s Next?</strong></p>  <p>Give Oshi a try, <a href="http://oshi.codeplex.com/">http://oshi.codeplex.com/</a>. </p>  <p>Oshi needs your help to implement *nix ports and create interfaces for other types of software and hardware information, such as disks, processes, printers, etc. Some of the functionality may be generic and should be pushed into JNA.</p></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=112">Read</a></div></html>
         ]]>
       </description>
       <category>oshi</category><category>jna</category><category>java</category><category>hardware</category><category>win32</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=112</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/112</guid>
      </item>
     
      <item>
       <title>Code Coverage with EMMA</title>
       <pubDate>Fri, 18 Jun 2010 12:24:02 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p><a href="http://code.dblock.org/ShowPicture.aspx?id=71&ShowThumbnail=false"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="right" src="http://code.dblock.org/ShowPicture.aspx?id=72&ShowThumbnail=false" width="220" height="64" /></a> </p>  <p>I’ve written an unusually high number of unit tests for the Java portion of <a href="http://waffle.codeplex.com/">Waffle</a>, mostly because the project became popular really fast with all those Java people trying to do Windows authentication. Some have succeeded and some filed several rather complicated bug reports that dealt with concurrency, sessions across HTTP requests, etc. It all needed to be unit-tested in order to make industrial-grade software.</p>  <p>If you asked me yesterday, I would have said that Waffle unit tests cover 99% of the code. But Emma says otherwise, and it’s probably right.</p>  <p><strong>Running Emma with JUnit</strong></p>  <p>It took me half an hour to integrate Emma. Pretty easy. You should do it too.</p>  <p>I downloaded Emma from <a href="http://emma.sourceforge.net">http://emma.sourceforge.net</a> and added it to ThirdParty/emma. What I want next is a <em>cover</em> target that can execute all unit tests with code coverage. We’re doing this in ANT with JUnit.</p>  <p><em>Define Emma JARs Location and ClassPath</em></p>  <p></p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">property</span><span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">emma.dir</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">value</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">${thirdparty.dir}/emma/lib</span>"<span style="color:#0000ff"> /&gt;</span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;</span><span style="color:#a31515">path</span><span style="color:#0000ff"> </span><span style="color:#ff0000">id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">emma.classpath</span>"<span style="color:#0000ff"> &gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">fileset</span><span style="color:#0000ff"> </span><span style="color:#ff0000">dir</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">${thirdparty.dir}/emma/lib</span>"<span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">include</span><span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">emma.jar</span>"<span style="color:#0000ff"> /&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">include</span><span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">emma_ant.jar</span>"<span style="color:#0000ff"> /&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">fileset</span><span style="color:#0000ff">&gt;</span></li> <li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">path</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>  <p></p>  <p><em>Instrument Files</em></p>  <p>I went the route of not changing my build tasks and instrumenting the .class files already built. Then I swap in those files with the instrumented ones. Note that Emma only generates .class files for instrumentable classes – those not containing debugging information, interface definitions and such aren’t included.</p>  <p></p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">target</span><span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">instrument</span>"<span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">echo</span><span style="color:#0000ff"> </span><span style="color:#ff0000">message</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Instrumenting ${waffle.lib}</span>"<span style="color:#0000ff"> /&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">path</span><span style="color:#0000ff"> </span><span style="color:#ff0000">id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">build.classpath</span>"<span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">pathelement</span><span style="color:#0000ff"> </span><span style="color:#ff0000">path</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">${waffle.lib}</span>"<span style="color:#0000ff">/&gt;</span></li> <li>  <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">path</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">emma</span><span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">instr</span><span style="color:#0000ff"> </span><span style="color:#ff0000">instrpathref</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">build.classpath</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">destdir</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">${waffle.cover}/lib</span>"</li> <li style="background: #f3f3f3">              <span style="color:#ff0000">metadatafile</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">${waffle.cover}/metadata.emma</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">merge</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">true</span>"<span style="color:#0000ff"> /&gt;</span></li> <li>  <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">emma</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">copy</span><span style="color:#0000ff"> </span><span style="color:#ff0000">todir</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">${waffle.lib}</span>"<span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">fileset</span><span style="color:#0000ff"> </span><span style="color:#ff0000">dir</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">${waffle.cover}/lib</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">includes</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">**/*</span>"<span style="color:#0000ff"> /&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">copy</span><span style="color:#0000ff">&gt;</span></li> <li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">target</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>  <p></p>  <p><em>Running Tests</em></p>  <p>The tests are run the same way as before, but we need to tell Emma where to write its output.</p>  <p></p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">junit</span><span style="color:#0000ff"> </span><span style="color:#ff0000">...</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">jvmarg</span><span style="color:#0000ff"> </span><span style="color:#ff0000">value</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">-Demma.coverage.out.file=${waffle.cover}/coverage.emma</span>"<span style="color:#0000ff"> /&gt;</span></li> <li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">junit</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>  <p></p>  <p><em>Generating an EMMA Report</em></p>  <p>Finally, we want to get a nice HTML document that summarizes coverage.</p>  <p></p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">target</span><span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">cover-report</span>"<span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">emma</span><span style="color:#0000ff">&gt;   </span></li> <li>        <span style="color:#0000ff">&lt;</span><span style="color:#a31515">report</span><span style="color:#0000ff"> </span><span style="color:#ff0000">sourcepath</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">${waffle.src}</span>"<span style="color:#0000ff">&gt;   </span></li> <li style="background: #f3f3f3">            <span style="color:#0000ff">&lt;</span><span style="color:#a31515">fileset</span><span style="color:#0000ff"> </span><span style="color:#ff0000">dir</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">${waffle.cover}</span>"<span style="color:#0000ff">&gt;   </span></li> <li>                <span style="color:#0000ff">&lt;</span><span style="color:#a31515">include</span><span style="color:#0000ff"> </span><span style="color:#ff0000">name</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">*.emma</span>"<span style="color:#0000ff"> /&gt;   </span></li> <li style="background: #f3f3f3">            <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">fileset</span><span style="color:#0000ff">&gt;   </span></li> <li>            <span style="color:#0000ff">&lt;</span><span style="color:#a31515">html</span><span style="color:#0000ff"> </span><span style="color:#ff0000">outfile</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">${waffle.cover}/coverage.html</span>"<span style="color:#0000ff"> /&gt;   </span></li> <li style="background: #f3f3f3">        <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">report</span><span style="color:#0000ff">&gt;   </span></li> <li>    <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">emma</span><span style="color:#0000ff">&gt;   </span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">target</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>  <p></p>  <p>Here’s an output.</p>  <p><a href="http://code.dblock.org/ShowPicture.aspx?id=73&ShowThumbnail=false"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://code.dblock.org/ShowPicture.aspx?id=74&ShowThumbnail=false" width="798" height="441" /></a></p>  <p>I see a lot of red. Emma doesn’t think I am doing such a great job after-all.</p>  <p><strong>Links</strong></p>  <ul>   <li><a href="http://emma.sourceforge.net/">EMMA on SourceForge</a> </li>    <li><a href="http://waffle.codeplex.com/SourceControl/changeset/view/54285#1099943">Waffle Build.xml with Emma Coverage</a>  </li> </ul></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=111">Read</a> | Updated 6/18/2010</div></html>
         ]]>
       </description>
       <category>emma</category><category>waffle</category><category>testing</category><category>java</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=111</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/111</guid>
      </item>
     
      <item>
       <title>WAFFLE: A PowerPoint Presentation</title>
       <pubDate>Tue, 08 Jun 2010 16:53:03 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p><a href="http://waffle.codeplex.com/Project/Download/FileDownload.aspx?DownloadId=126160"><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" align="right" src="http://code.dblock.org/ShowPicture.aspx?id=70&ShowThumbnail=false" width="240" height="65" /></a>I’ve uploaded a <a href="http://waffle.codeplex.com/Project/Download/FileDownload.aspx?DownloadId=126160">PowerPoint presentation</a> about Waffle that I made to my team. It can be a good start for talking points and a presentation about Windows authentication in Tomcat, Jetty, etc.</p></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=110">Read</a></div></html>
         ]]>
       </description>
       <category>tomcat</category><category>waffle</category><category>security</category><category>win32</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=110</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/110</guid>
      </item>
     
      <item>
       <title>Visual Studio 2008 Crashes: doesn’t always mean Microsoft sucks</title>
       <pubDate>Tue, 08 Jun 2010 13:09:25 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p><a href="http://forums.asp.net/1112.aspx"><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" align="right" src="http://code.dblock.org/ShowPicture.aspx?id=69&ShowThumbnail=false" width="244" height="193" /></a> I often hear from people that Microsoft sucks. When I worked there I found it funny.</p>  <p>I recently had a recurrent crash in Visual Studio 2008. I would switch to the HTML design view (ASP.NET application or simple HTLM page) et voila, crash. Annoying, to say the least. The call stack ended up somewhere in MFC and didn’t look promising. I spent a lot of time being frustrated until this morning, when I decided to actually do something about it.</p>  <p>Microsoft has active forums for all its software. Visual Studio 2008 forum is here: <a href="http://forums.asp.net/1112.aspx">http://forums.asp.net/1112.aspx</a>. Turns out that one of the <a href="http://forums.asp.net/t/1393894.aspx">existing hotfixes</a> seemed related to the area where I was seeing the crash. I downloaded and installed it, the problem went away. It also looks like if it didn’t, I could get a very reasonable turn-around on the forum after reporting a crash as someone is being paid to work the forum and collect issues, publish announcements and patches. No annoying forms and no calling on the phone some entry-level support person on the other side of the planet. It’s a developer-to-developer relationship and this is exactly how I like it.</p></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=109">Read</a></div></html>
         ]]>
       </description>
       <category>microsoft</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=109</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/109</guid>
      </item>
     
      <item>
       <title>Учись Работать / Вся правда о том, что нас мотивирует</title>
       <pubDate>Sat, 29 May 2010 23:48:04 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><embed height="385" type="application/x-shockwave-flash" width="640" src="http://www.youtube.com/v/u6XAPnuFjJc&color1=0xb1b1b1&color2=0xd0d0d0&hl=en_US&feature=player_embedded&fs=1" allowfullscreen="true" allowscriptaccess="always" /><br /><br />
<br /><br />
Everyone managing people should watch <a href="http://www.youtube.com/watch?v=u6XAPnuFjJc&feature=player_embedded" target="_self">Daniel H Pink's RSA intro</a>.<br /></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=108">Read</a></div></html>
         ]]>
       </description>
       <category>organizations</category><category>people</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=108</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/108</guid>
      </item>
     
      <item>
       <title>Tomcat Single Sign-On mixed with Form Authentication w/ Waffle</title>
       <pubDate>Thu, 27 May 2010 13:01:40 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p><a href="http://code.dblock.org/ShowPicture.aspx?id=65&ShowThumbnail=false"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="waffle" border="0" alt="waffle" align="right" src="http://code.dblock.org/ShowPicture.aspx?id=66&ShowThumbnail=false" width="164" height="67" /></a> </p>  <p>Most Tomcat users begin by implement Form-based authentication. Those deploying applications into enterprises soon discover that those enterprises use an Active Directory and have single sign-on on all intranet sites. They eventually find <a href="http://waffle.codeplex.com/">Waffle</a>, but don’t want to take the ability to do form-based logon away. </p>  <p><em>How do we give users a way to logon either way?</em></p>  <p><a href="http://code.dblock.org/ShowPicture.aspx?id=67&ShowThumbnail=false"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://code.dblock.org/ShowPicture.aspx?id=68&ShowThumbnail=false" width="244" height="175" /></a></p>  <p>You can accomplish this with the Waffle <em>MixedAuthenticator</em>.</p>  <p><strong>Configure Tomcat</strong></p>  <p><em>Download and Copy Files</em></p>  <blockquote>   <p>Download <a href="http://waffle.codeplex.com/">Waffle 1.3</a> and copy <em>waffle-jna.jar</em>, <em>jna.jar</em> and <em>platform.jar</em> to Tomcat's lib directory.</p> </blockquote>  <p><em>Configure Mixed Authenticator Valve</em></p>  <blockquote>   <p>Add a valve and a realm to the application context. For an application, modify <em>META-INF\context.xml</em>.</p>    <p></p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;?</span><span style="color:#a31515">xml</span><span style="color:#0000ff"> </span><span style="color:#ff0000">version</span><span style="color:#0000ff">=</span>'<span style="color:#0000ff">1.0</span>'<span style="color:#0000ff"> </span><span style="color:#ff0000">encoding</span><span style="color:#0000ff">=</span>'<span style="color:#0000ff">utf-8</span>'<span style="color:#0000ff">?&gt;</span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Context</span><span style="color:#0000ff">&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Valve</span><span style="color:#0000ff"> </span><span style="color:#ff0000">className</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffle.apache.MixedAuthenticator</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">principalFormat</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">fqn</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">roleFormat</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">both</span>"<span style="color:#0000ff"> /&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Realm</span><span style="color:#0000ff"> </span><span style="color:#ff0000">className</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffle.apache.WindowsRealm</span>"<span style="color:#0000ff"> /&gt;</span></li> <li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Context</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div> </blockquote>  <p><em>Security Roles and Constraints</em></p>  <blockquote>   <p>Configure security roles in <em>WEB-INF\web.xml</em>. The Waffle Mixed Authenticator adds all user's security groups (including nested and domain groups) as roles during authentication.</p>    <p></p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">security-role</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">role-name</span><span style="color:#0000ff">&gt;</span>Everyone<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">role-name</span><span style="color:#0000ff">&gt;</span></li> <li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">security-role</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>    <p></p>    <p>Restrict access to website resources.</p>    <p></p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">security-constraint</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">display-name</span><span style="color:#0000ff">&gt;</span>Waffle Security Constraint<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">display-name</span><span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">web-resource-collection</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">      <span style="color:#0000ff">&lt;</span><span style="color:#a31515">web-resource-name</span><span style="color:#0000ff">&gt;</span>Protected Area<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">web-resource-name</span><span style="color:#0000ff">&gt;</span></li> <li>      <span style="color:#0000ff">&lt;</span><span style="color:#a31515">url-pattern</span><span style="color:#0000ff">&gt;</span>/*<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">url-pattern</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">web-resource-collection</span><span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">auth-constraint</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">      <span style="color:#0000ff">&lt;</span><span style="color:#a31515">role-name</span><span style="color:#0000ff">&gt;</span>Everyone<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">role-name</span><span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">auth-constraint</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">security-constraint</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>    <p></p>    <p>Add a second security constraint that leaves the login page unprotected.</p>    <p></p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">security-constraint</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">display-name</span><span style="color:#0000ff">&gt;</span>Login Page<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">display-name</span><span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">web-resource-collection</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">      <span style="color:#0000ff">&lt;</span><span style="color:#a31515">web-resource-name</span><span style="color:#0000ff">&gt;</span>Unprotected Login Page<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">web-resource-name</span><span style="color:#0000ff">&gt;</span></li> <li>      <span style="color:#0000ff">&lt;</span><span style="color:#a31515">url-pattern</span><span style="color:#0000ff">&gt;</span>/login.jsp<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">url-pattern</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">web-resource-collection</span><span style="color:#0000ff">&gt;</span></li> <li>  <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">security-constraint</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>    <p></p> </blockquote>  <p><em>Configure Form Login</em></p>  <blockquote>   <p>Configure Form Login parameters with the location of the login page (repeated from the security constraint above) and an error page for failed logins. Modify <em>WEB-INF\web.xml</em>.</p>    <p></p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">login-config</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">   <span style="color:#0000ff">&lt;</span><span style="color:#a31515">form-login-config</span><span style="color:#0000ff">&gt;</span></li> <li>      <span style="color:#0000ff">&lt;</span><span style="color:#a31515">form-login-page</span><span style="color:#0000ff">&gt;</span>/login.jsp<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">form-login-page</span><span style="color:#0000ff">&gt;  </span></li> <li style="background: #f3f3f3">      <span style="color:#0000ff">&lt;</span><span style="color:#a31515">form-error-page</span><span style="color:#0000ff">&gt;</span>/error.html<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">form-error-page</span><span style="color:#0000ff">&gt;  </span></li> <li>  <span style="color:#0000ff"> &lt;/</span><span style="color:#a31515">form-login-config</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">login-config</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>    <p></p> </blockquote>  <p></p>  <p></p>  <p></p>  <p></p>  <p><em>Login Page</em></p>  <blockquote>   <p>Create a login page based on the following code. There're two requirements for the login form. The form-based authentication must post to any valid location with the <em>j_security_check</em> parameter. The destination page will be loaded after a successful login. The single sign-on form must similarly post to any valid location with the <em>j_negotiate_check</em> parameter in the query string.</p>    <p>Here’s a rudimentary example that lands an authenticated user on <em>index.jsp</em>.</p>    <p></p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#800000">form</span> <span style="color:#ff0000">method</span><span style="color:#0000ff">="POST"</span> <span style="color:#ff0000">name</span><span style="color:#0000ff">="loginform"</span> <span style="color:#ff0000">action</span><span style="color:#0000ff">="index.jsp?j_security_check"&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#800000">table</span> <span style="color:#ff0000">style</span><span style="color:#0000ff">="</span><span style="color:#ff0000">vertical-align</span><span style="color:#0000ff">: middle;"&gt;</span></li> <li>        <span style="color:#0000ff">&lt;</span><span style="color:#800000">tr</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">            <span style="color:#0000ff">&lt;</span><span style="color:#800000">td</span><span style="color:#0000ff">&gt;</span>Username:<span style="color:#0000ff">&lt;/</span><span style="color:#800000">td</span><span style="color:#0000ff">&gt;</span></li> <li>            <span style="color:#0000ff">&lt;</span><span style="color:#800000">td</span><span style="color:#0000ff">&gt;&lt;</span><span style="color:#800000">input</span> <span style="color:#ff0000">type</span><span style="color:#0000ff">="text"</span> <span style="color:#ff0000">name</span><span style="color:#0000ff">="j_username"</span> <span style="color:#0000ff">/&gt;&lt;/</span><span style="color:#800000">td</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">        <span style="color:#0000ff">&lt;/</span><span style="color:#800000">tr</span><span style="color:#0000ff">&gt;</span></li> <li>        <span style="color:#0000ff">&lt;</span><span style="color:#800000">tr</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">            <span style="color:#0000ff">&lt;</span><span style="color:#800000">td</span><span style="color:#0000ff">&gt;</span>Password:<span style="color:#0000ff">&lt;/</span><span style="color:#800000">td</span><span style="color:#0000ff">&gt;</span></li> <li>            <span style="color:#0000ff">&lt;</span><span style="color:#800000">td</span><span style="color:#0000ff">&gt;&lt;</span><span style="color:#800000">input</span> <span style="color:#ff0000">type</span><span style="color:#0000ff">="password"</span> <span style="color:#ff0000">name</span><span style="color:#0000ff">="j_password"</span> <span style="color:#0000ff">/&gt;&lt;/</span><span style="color:#800000">td</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">        <span style="color:#0000ff">&lt;/</span><span style="color:#800000">tr</span><span style="color:#0000ff">&gt;</span></li> <li>        <span style="color:#0000ff">&lt;</span><span style="color:#800000">tr</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">            <span style="color:#0000ff">&lt;</span><span style="color:#800000">td</span><span style="color:#0000ff">&gt;&lt;</span><span style="color:#800000">input</span> <span style="color:#ff0000">type</span><span style="color:#0000ff">="submit"</span> <span style="color:#ff0000">value</span><span style="color:#0000ff">="Login"</span> <span style="color:#0000ff">/&gt;&lt;/</span><span style="color:#800000">td</span><span style="color:#0000ff">&gt;</span></li> <li>        <span style="color:#0000ff">&lt;/</span><span style="color:#800000">tr</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;/</span><span style="color:#800000">table</span><span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;/</span><span style="color:#800000">form</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#800000">hr</span><span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#800000">form</span> <span style="color:#ff0000">method</span><span style="color:#0000ff">="POST"</span> <span style="color:#ff0000">name</span><span style="color:#0000ff">="loginform"</span> <span style="color:#ff0000">action</span><span style="color:#0000ff">="index.jsp?j_negotiate_check"&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#800000">input</span> <span style="color:#ff0000">type</span><span style="color:#0000ff">="submit"</span> <span style="color:#ff0000">value</span><span style="color:#0000ff">="Login w/ Current Windows Credentials"</span> <span style="color:#0000ff">/&gt;</span></li> <li>    <span style="color:#0000ff">&lt;/</span><span style="color:#800000">form</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>    <p></p> </blockquote>  <p><strong>Demo</strong></p>  <p>A demo application can be found in the Waffle distribution in the <em>Samples\Tomcat\waffle-mixed</em> directory. Copy the entire directory into Tomcat's <em>webapps</em> directory and navigate to <a href="http://localhost:8080/waffle-mixed/">http://localhost:8080/waffle-mixed/</a>. Pick your method of login! </p>  <p><strong>How does it Work?</strong></p>  <p>Implementation details follow. Read at your own risk.</p>  <p>From the unauthenticated login page we are making two possible requests: one will trigger Single Sign-On and another will trigger form-based authentication. To do single sign-on we will need access to the request/response objects and to do forms authentication we will need access to the realms interface. The place where we have both is in <em>org.apache.catalina.Authenticator.</em></p>  <blockquote>   <p>     </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li>@Override</li> <li style="background: #f3f3f3"><span style="color:#0000ff">protected</span> boolean authenticate(Request request, Response response, LoginConfig loginConfig) {</li> <li> </li> <li style="background: #f3f3f3">    <span style="color:#2b91af">String</span> queryString = request.getQueryString();</li> <li>    boolean negotiateCheck = (queryString != <span style="color:#0000ff">null</span> && queryString.equals(<span style="color:#a31515">"j_negotiate_check"</span>));</li> <li style="background: #f3f3f3">    boolean securityCheck = (queryString != <span style="color:#0000ff">null</span> && queryString.equals(<span style="color:#a31515">"j_security_check"</span>));</li> <li> </li> <li style="background: #f3f3f3">    Principal principal = request.getUserPrincipal();</li> <li>    </li> <li style="background: #f3f3f3">    AuthorizationHeader authorizationHeader = <span style="color:#0000ff">new</span> AuthorizationHeader(request);        </li> <li>    boolean ntlmPost = authorizationHeader.isNtlmType1PostAuthorizationHeader();</li> <li style="background: #f3f3f3"> </li> <li>    <span style="color:#0000ff">if</span> (principal != <span style="color:#0000ff">null</span> && ! ntlmPost) {</li> <li style="background: #f3f3f3">        <span style="color:#0000ff">return</span> <span style="color:#0000ff">true</span>;</li> <li>    } <span style="color:#0000ff">else</span> <span style="color:#0000ff">if</span> (negotiateCheck) {</li> <li style="background: #f3f3f3">        <span style="color:#0000ff">if</span> (! authorizationHeader.isNull()) {</li> <li>            <span style="color:#0000ff">return</span> negotiate(request, response, authorizationHeader);</li> <li style="background: #f3f3f3">        } <span style="color:#0000ff">else</span> {</li> <li>            sendUnauthorized(response);</li> <li style="background: #f3f3f3">            <span style="color:#0000ff">return</span> <span style="color:#0000ff">false</span>;</li> <li>        }</li> <li style="background: #f3f3f3">    } <span style="color:#0000ff">else</span> <span style="color:#0000ff">if</span> (securityCheck) {</li> <li>        boolean postResult = post(request, response, loginConfig);</li> <li style="background: #f3f3f3">        <span style="color:#0000ff">if</span> (postResult) {</li> <li>            redirectTo(request, response, request.getServletPath());</li> <li style="background: #f3f3f3">        } <span style="color:#0000ff">else</span> {</li> <li>            redirectTo(request, response, loginConfig.getErrorPage());</li> <li style="background: #f3f3f3">        }</li> <li>        <span style="color:#0000ff">return</span> postResult;</li> <li style="background: #f3f3f3">    } <span style="color:#0000ff">else</span> {</li> <li>        redirectTo(request, response, loginConfig.getLoginPage());</li> <li style="background: #f3f3f3">        <span style="color:#0000ff">return</span> <span style="color:#0000ff">false</span>;</li> <li>    }</li> <li style="background: #f3f3f3">}</li> </ol> </div> </div> </div>    </blockquote>  <p>Negotiate mimics the behavior of <a href="http://waffle.codeplex.com/SourceControl/changeset/view/53334#1106356">NegotiateAuthenticator</a>, while form post follows the standard Authenticator registration process.</p>  <blockquote>   <p></p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li><span style="color:#0000ff">private</span> boolean post(Request request, Response response, LoginConfig loginConfig) {        </li> <li style="background: #f3f3f3">    <span style="color:#2b91af">String</span> username = request.getParameter(<span style="color:#a31515">"j_username"</span>);</li> <li>    <span style="color:#2b91af">String</span> password = request.getParameter(<span style="color:#a31515">"j_password"</span>);</li> <li style="background: #f3f3f3">    IWindowsIdentity windowsIdentity = <span style="color:#0000ff">null</span>;</li> <li>    <span style="color:#0000ff">try</span> {</li> <li style="background: #f3f3f3">        windowsIdentity = _auth.logonUser(username, password);</li> <li>    } <span style="color:#0000ff">catch</span> (<span style="color:#2b91af">Exception</span> e) {</li> <li style="background: #f3f3f3">        <span style="color:#0000ff">return</span> <span style="color:#0000ff">false</span>;</li> <li>    }</li> <li style="background: #f3f3f3">    </li> <li>    WindowsPrincipal windowsPrincipal = <span style="color:#0000ff">new</span> WindowsPrincipal(windowsIdentity, context.getRealm(), _principalFormat, _roleFormat);</li> <li style="background: #f3f3f3">    register(request, response, windowsPrincipal, <span style="color:#a31515">"FORM"</span>, windowsPrincipal.getName(), <span style="color:#0000ff">null</span>);</li> <li>    <span style="color:#0000ff">return</span> <span style="color:#0000ff">true</span>;</li> <li style="background: #f3f3f3">}</li> </ol> </div> </div> </div>    <p></p> </blockquote>  <p><strong>Links</strong></p>  <ul>   <li><a href="http://waffle.codeplex.com/">Download Waffle</a> </li>    <li><a href="http://waffle.codeplex.com/SourceControl/changeset/view/53334#1106353">MixedAuthenticator.java</a></li> </ul></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=107">Read</a> | Updated 5/30/2010</div></html>
         ]]>
       </description>
       <category>waffle</category><category>jna</category><category>security</category><category>java</category><category>active directory</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=107</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/107</guid>
      </item>
     
      <item>
       <title>Single Sign-On: Servlet Negotiate Security Filter (Kerberos + NTLM) w/ Waffle</title>
       <pubDate>Tue, 25 May 2010 18:03:19 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p><em>Jamais deux sans trois.</em></p>  <p><em><a href="http://code.dblock.org/ShowPicture.aspx?id=63&ShowThumbnail=false"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="waffle" border="0" alt="waffle" align="right" src="http://code.dblock.org/ShowPicture.aspx?id=64&ShowThumbnail=false" width="164" height="67" /></a></em>In a previous post I showed how to use the Waffle Tomcat Authenticator to implement single-sign-on with Tomcat. That works very well and utilizes the concept of Tomcat realms to protect various resources. Turns out, there’re disadvantages to this approach. These are quite well explained in the <a href="http://securityfilter.sourceforge.net/">Tomcat Security Filter project</a>. It all boils down to not requiring a realm, so lets see how to use the Waffle <em>NegotiateSecurityFilter </em>with Tomcat (you should be able to use it with other implementations, including Jetty).</p>  <p><strong>Download</strong></p>  <p>Download <a href="http://code.dblock.org/ShowUrl.aspx?ObjectId=105&ObjectType=Post&Url=http%3a%2f%2fcode.dblock.org%2fShowUrl.aspx%3fObjectId%3d103%26ObjectType%3dPost%26Url%3dhttp%253a%252f%252fwaffle.codeplex.com%252f">Waffle 1.3</a>. The zip contains <em>Waffle.chm</em> that has the latest version of this tutorial.</p>  <p><strong>Configure Tomcat</strong></p>  <p><em>Copy Files</em></p>  <blockquote>   <p>Copy <em>waffle-jna.jar</em>, <em>jna.jar</em> and <em>platform.jar</em> to Tomcat's <em>lib</em> directory. You can package these files with your application, but this is easier for the demonstration.</p> </blockquote>  <p><em>Security Filter</em></p>  <blockquote>   <p>Add the security filter to <em>WEB-INF\web.xml</em>.</p>    <p></p>    <p></p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">filter</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">filter-name</span><span style="color:#0000ff">&gt;</span>SecurityFilter<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">filter-name</span><span style="color:#0000ff">&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">filter-class</span><span style="color:#0000ff">&gt;</span>waffle.servlet.NegotiateSecurityFilter<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">filter-class</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">filter</span><span style="color:#0000ff">&gt;</span></li> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">filter-mapping</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">filter-name</span><span style="color:#0000ff">&gt;</span>SecurityFilter<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">filter-name</span><span style="color:#0000ff">&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">url-pattern</span><span style="color:#0000ff">&gt;</span>/*<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">url-pattern</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">filter-mapping</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div> </blockquote>  <p>That’s it.</p>  <p><strong>Demo Application</strong></p>  <p>A demo application can be found in the Waffle distribution in the <em>Samples\Tomcat\waffle-filter</em> directory. Copy the entire directory into Tomcat's webapps directory and navigate to <a href="http://localhost:8080/waffle-filter/">http://localhost:8080/waffle-filter/</a>.</p>  <p><strong>Retrieving User Principal</strong></p>  <p>If you’re familiar with Tomcat you’ll be surprised that <em>&lt;%= request.getUserPrincipal().getName() %&gt;</em> works in a JSP page with this filter in place and no realm configuration. Theoretically Tomcat says you cannot assign a Principal to the request in a filter. The guys at the <a href="http://securityfilter.sourceforge.net/">Tomcat Security Filter Project</a> found a very simple solution – wrap the request up and pass the wrapper into the next filter in the chain. We use the same technique as you can see in <a href="http://waffle.codeplex.com/SourceControl/changeset/view/53021#1103569">NegotiateSecurityFilter.java</a> and <a href="http://waffle.codeplex.com/SourceControl/changeset/view/53021#1103572">NegotiateRequestWrapper.java</a>.</p>  <blockquote>   <p></p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li>WindowsPrincipal windowsPrincipal = <span style="color:#0000ff">new</span> WindowsPrincipal(windowsIdentity, <span style="color:#0000ff">null</span>, _principalFormat, _roleFormat);</li> <li style="background: #f3f3f3">subject.getPrincipals().add(windowsPrincipal);</li> <li>session.setAttribute(<span style="color:#a31515">"javax.security.auth.subject"</span>, subject);</li> <li style="background: #f3f3f3">NegotiateRequestWrapper requestWrapper = <span style="color:#0000ff">new</span> NegotiateRequestWrapper(request, windowsPrincipal);</li> <li>chain.doFilter(requestWrapper, response);</li> </ol> </div> </div> </div>    <p></p> </blockquote>  <p><strong>Links</strong></p>  <ul>   <li><a href="http://code.dblock.org/ShowPost.aspx?id=103">Single Sign-On: Tomcat Negotiate Authenticator (Kerberos + NTLM) w/ Waffle</a>: explains how to do Single Sign-On with a Tomcat Authenticator. </li>    <li><a href="http://code.dblock.org/ShowPost.aspx?id=105">Windows/Active Directory Authentication: Tomcat + JAAS w/ Waffle</a>: explains how to do Windows authentication in Tomcat with JAAS </li>    <li><a href="http://waffle.codeplex.com/SourceControl/changeset/view/53021#1103569">NegotiateSecurityFilter.java Source Code</a> </li> </ul></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=106">Read</a> | Updated 5/30/2010</div></html>
         ]]>
       </description>
       <category>tomcat</category><category>waffle</category><category>security</category><category>java</category><category>active directory</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=106</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/106</guid>
      </item>
     
      <item>
       <title>Windows/Active Directory Authentication: Tomcat + JAAS w/ Waffle</title>
       <pubDate>Mon, 24 May 2010 12:24:18 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p><a href="http://waffle.codeplex.com/"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="waffle" border="0" alt="waffle" align="right" src="http://code.dblock.org/ShowPicture.aspx?id=60&ShowThumbnail=false" width="164" height="67" /></a> We used to have code that checked whether a username/password was valid, then tried to enumerate user groups in Active Directory. That didn’t work for nested groups, domains with trusts and many other scenarios in-between. Then we wrote what eventually became <a href="http://waffle.codeplex.com">Waffle</a>. This week-end I added a <a href="http://en.wikipedia.org/wiki/Java_Authentication_and_Authorization_Service">JAAS</a> LoginModule to <a href="http://waffle.codeplex.com/releases/view/43113">Waffle 1.3</a>. You can use this with anything that supports JAAS, such as Tomcat for BASIC, DIGEST or FORMS authentication. This is actually a simple demonstration (as opposed to the <a href="http://code.dblock.org/ShowPost.aspx?id=103">Single Sign-On Negotiate/NTLM/Kerberos valve</a>) of Waffle and is how we originally used it. Here’s how.</p>  <p><strong>Download</strong></p>  <p>Download <a href="http://code.dblock.org/ShowUrl.aspx?ObjectId=103&ObjectType=Post&Url=http%3a%2f%2fwaffle.codeplex.com%2f">Waffle 1.3</a>. The zip contains <em>Waffle.chm</em> that has the latest version of this tutorial.</p>  <p><strong>Configure Tomcat</strong></p>  <p><em>Copy Files</em></p>  <blockquote>   <p>Copy <em>waffle-jna.jar</em>, <em>jna.jar</em> and <em>platform.jar</em> to Tomcat's <em>lib</em> directory. </p> </blockquote>  <p><em>JAAS Realm</em></p>  <blockquote>   <p>Add a JAAS realm to the application context. Modify <em>META-INF\context.xml </em>of your application.</p>    <p></p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Context</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Realm</span><span style="color:#0000ff"> </span><span style="color:#ff0000">className</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">org.apache.catalina.realm.JAASRealm</span>"</li> <li>         <span style="color:#0000ff"></span><span style="color:#ff0000">appName</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Jaas</span>"</li> <li style="background: #f3f3f3">         <span style="color:#0000ff"></span><span style="color:#ff0000">userClassNames</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffle.jaas.UserPrincipal</span>"</li> <li>         <span style="color:#0000ff"></span><span style="color:#ff0000">roleClassNames</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffle.jaas.RolePrincipal</span>"</li> <li style="background: #f3f3f3">         <span style="color:#0000ff"></span><span style="color:#ff0000">useContextClassLoader</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">false</span>"</li> <li>         <span style="color:#0000ff"></span><span style="color:#ff0000">debug</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">true</span>"<span style="color:#0000ff"> /&gt;</span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Context</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>    <p></p> </blockquote>  <p><em>Authentication</em></p>  <blockquote>   <p>Modify <em>WEB-INF\web.xml</em> of your application.</p>    <p>Enable BASIC, DIGEST or FORMS authentication for this realm. </p>    <p></p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">login-config</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">auth-method</span><span style="color:#0000ff">&gt;</span>BASIC<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">auth-method</span><span style="color:#0000ff">&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">realm-name</span><span style="color:#0000ff">&gt;</span>Jaas<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">realm-name</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">login-config</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>    <p></p>    <p>Configure security roles. The Waffle login module adds all user's security groups (including nested and domain groups) as roles during authentication.</p>    <p></p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">security-role</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">role-name</span><span style="color:#0000ff">&gt;</span>Everyone<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">role-name</span><span style="color:#0000ff">&gt;</span></li> <li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">security-role</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>    <p></p>    <p>Restrict access to website resources. For example, to restrict the entire website to locally authenticated users add the following.</p>    <p></p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">security-constraint</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">display-name</span><span style="color:#0000ff">&gt;</span>Waffle Security Constraint<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">display-name</span><span style="color:#0000ff">&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">web-resource-collection</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">web-resource-name</span><span style="color:#0000ff">&gt;</span>Protected Area<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">web-resource-name</span><span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">url-pattern</span><span style="color:#0000ff">&gt;</span>/*<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">url-pattern</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">web-resource-collection</span><span style="color:#0000ff">&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">auth-constraint</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">role-name</span><span style="color:#0000ff">&gt;</span>Everyone<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">role-name</span><span style="color:#0000ff">&gt;</span></li> <li>  <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">auth-constraint</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">security-constraint</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>    <p></p> </blockquote>  <p><em>Login Configuration</em></p>  <blockquote>   <p>Create a login configuration file, <em>login.conf</em>. This configuration file specifies how to plug the Waffle Windows Login Module.</p>    <p></p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li>Jaas {</li> <li style="background: #f3f3f3">    waffle.jaas.WindowsLoginModule sufficient;</li> <li>};</li> </ol> </div> </div> </div>    <p></p>    <p>The login.conf configuration file is passed to Java with -Djava.security.auth.login.config=&lt;path-to-file&gt;/login.conf.</p> </blockquote>  <p><em>JAAS Security Policy</em></p>  <blockquote>   <p>Create JAAS policy configuration file, jaas.policy. This file specifies which identities are granted which permissions.</p>    <p></p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li>grant Principal * * {</li> <li style="background: #f3f3f3">  permission java.security.AllPermission "/*";</li> <li>};</li> </ol> </div> </div> </div>    <p></p>    <p>The policy file is passed to Java with -Djava.security.auth.policy=&lt;path-to-file&gt;/jaas.policy.</p> </blockquote>  <p><strong>Start Tomcat</strong></p>  <p>You must start Tomcat with Security Manager enabled (-security) and configure it with a login configuration and policy. For example, the following will start Tomcat using the demo login.conf and jaas.policy from the Waffle samples.</p>  <p></p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li>@echo off</li> <li style="background: #f3f3f3">setlocal</li> <li>set JAVA_OPTS=-Djava.security.auth.login.config="C:/Program Files/Tomcat/webapps/waffle-jaas/login.conf" -Djava.security.auth.policy="C:/Program Files/Tomcat/webapps/waffle-jaas/jaas.policy"</li> <li style="background: #f3f3f3">call bin/catalina.bat run -security</li> <li>endlocal</li> </ol> </div> </div> </div>  <p></p>  <p></p>  <p><strong>Demo Application</strong></p>  <p>A demo application can be found in the Waffle distribution in the <em>Samples\Tomcat\waffle-jaas</em> directory. Copy the entire directory into Tomcat's webapps directory, start Tomcat as explained above, and navigate to <a href="http://localhost:8080/waffle-jaas/">http://localhost:8080/waffle-jaas/</a>. You will be prompted for your Windows login, enter your Windows credentials and log-in.</p>  <p><a href="http://code.dblock.org/ShowPicture.aspx?id=61&ShowThumbnail=false"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://code.dblock.org/ShowPicture.aspx?id=62&ShowThumbnail=false" width="240" height="206" /></a> </p>  <p><strong>Links</strong></p>  <ul>   <li><a href="http://waffle.codeplex.com/">Waffle</a> </li>    <li><a href="http://waffle.codeplex.com/SourceControl/changeset/view/52933#1103401">JAAS LoginModule Source Code</a> </li> </ul></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=105">Read</a> | Updated 5/30/2010</div></html>
         ]]>
       </description>
       <category>tomcat</category><category>waffle</category><category>jna</category><category>java</category><category>active directory</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=105</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/105</guid>
      </item>
     
      <item>
       <title>NTLM: Please show ID with every POST</title>
       <pubDate>Thu, 20 May 2010 22:16:08 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p><strong>Prologue</strong></p>  <p>I was debugging a GWT application that worked well with FORM authentication and refused to work with integrated Windows auth (NTLM/Kerberos) on some machines. It all started with a benign error message.</p>  <blockquote>   <p><a href="http://code.dblock.org/ShowPicture.aspx?id=58&ShowThumbnail=false"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://code.dblock.org/ShowPicture.aspx?id=59&ShowThumbnail=false" width="401" height="152" /></a> </p> </blockquote>  <p>The log reveals an interesting stack. </p>  <blockquote>   <p><font size="1">Exception while dispatching incoming RPC call        <br />java.lang.IllegalArgumentException: encodedRequest cannot be empty         <br />at com.google.gwt.user.server.rpc.RPC.decodeRequest(RPC.java:226)         <br />at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:163)         <br />at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:86)         <br />at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)         <br />at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)</font></p> </blockquote>  <p>We’re in the middle of an Ajax POST. Examining the HTTP request we find that it doesn’t have a body. This explains why GWT is throwing this exception, but doesn’t explain why this happens. I asked for help on both the <a href="http://groups.google.com/group/google-web-toolkit/browse_thread/thread/6039401ab4221f7c">GWT group</a> and on <a href="http://www.extjs.com/forum/showthread.php?99321-Exception-while-dispatching-incoming-RPC-call">EXTJs premium forum</a>, but didn’t get anything useful.</p>  <blockquote>   <p><font size="1">POST /dbprotect/com.example.gwt.main/service/ServiceRPC HTTP/1.1        <br />Accept: */*         <br />Accept-Language: en-us         <br /></font><font size="1">Content-Type: text/x-gwt-rpc; charset=utf-8        <br />Accept-Encoding: gzip, deflate         <br />User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; Trident/4.0; …)         <br />Host: localhost:20080         <br />Content-Length: 0         <br />Connection: Keep-Alive         <br />Cache-Control: no-cache         <br />Authorization: Negotiate TlRMTVNTUAABAAAAB7IIogkACQAxAAAACQAJACgAAAAFAs4OAAAAD0RET1VCLVJFRFdPUktHUk9VUA==</font></p> </blockquote>  <p><strong>The Heart of the Salamander</strong></p>  <p>I mentioned that I had two environments: one that worked and one that didn’t. The defining moment came when <a href="http://blog.johnhite.com/">John</a> pointed out that the working environment was choosing <em>Kerberos</em>, while the non-working environment was choosing <em>NTLM</em> when performing <em>Negotiate</em> authentication. It was clear that after a Kerberos auth the POST no longer carried an Authorization header and had a body.</p>  <p>I (mistakenly) concluded that this was a GWT bug with Internet Explorer. It failed the same way in Chrome though, so this wasn’t some kind of conspiracy.</p>  <p><strong>The Reckoning</strong></p>  <p>I started reading GWT code. I also read the <a href="http://davenport.sourceforge.net/ntlm.html">NTLM RFC</a>. The latter was helpful.</p>  <blockquote>   <p><em><font size="1">This scheme differs from most "normal" HTTP authentication mechanisms, in that subsequent requests over the authenticated connection are not themselves authenticated; NTLM is connection-oriented, rather than request-oriented. So a second request for "<stripped>/index.html</stripped>" would not carry any authentication information, and the server would request none. If the server detects that the connection to the client has been dropped, a request for "<stripped>/index.html</stripped>" would result in the server reinitiating the NTLM handshake. </font></em></p>    <p><em>A notable exception to the above is the client's behavior when submitting a POST request (typically employed when the client is sending form data to the server). If the client determines that the server is not the local host, the client will initiate reauthentication for POST requests over the active connection. The client will first submit <strong>an empty POST request with a Type 1 message</strong> in the "<stripped>Authorization</stripped>" header; the server responds with the Type 2 message (in the "<stripped>WWW-Authenticate</stripped>" header as shown above). The client then resubmits the POST with the Type 3 message, sending the form data with the request. </em></p> </blockquote>  <p>I got bitten by the NTLM protocol. It hurt.</p>  <p><strong>The Fix</strong></p>  <p>This fix was easy. When an empty POST is sent, we must follow the protocol and perform authentication instead of assuming that the client is already authenticated (we did do that in a previous GET). This is now properly implemented in the <a href="http://waffle.codeplex.com/">Waffle Tomcat Authenticator</a> (<a href="http://waffle.codeplex.com/SourceControl/changeset/view/52704#1097376">source</a>).</p>  <p><strong>Suboptimal Performance</strong></p>  <p>There’s a big side effect to this NTLM negotiation – degraded performance. You’re getting a POST request that requires authentication every time you have a new connection. This happens a lot with AJAX sites, such as GWT-based ones. A workaround is described in <a href="http://support.microsoft.com/kb/251404">KB251404</a>, setting <em>HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Internet Settings/DisableNTLMPreAuth</em> to 1.</p>  <p>In a properly configured Active Directory you’re most likely to be using Kerberos anyway. This requires a valid SPN. Read <a href="http://blogs.msdn.com/sql_protocols/archive/2006/12/02/understanding-kerberos-and-ntlm-authentication-in-sql-server-connections.aspx">this article</a> to start – it’s about SQL server, but applies to all services. Adding a <em>HTTP/server.com:port</em> SPN was sufficient in some of my test environments to avoid NTLM altogether.</p></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=104">Read</a></div></html>
         ]]>
       </description>
       <category>gwt</category><category>waffle</category><category>security</category><category>java</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=104</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/104</guid>
      </item>
     
      <item>
       <title>Single Sign-On: Tomcat Negotiate Authenticator (Kerberos + NTLM) w/ Waffle</title>
       <pubDate>Thu, 20 May 2010 00:32:22 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p><a href="http://code.dblock.org/ShowPicture.aspx?id=52&ShowThumbnail=false"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="right" src="http://code.dblock.org/ShowPicture.aspx?id=53&ShowThumbnail=false" width="130" height="92" /></a> </p>  <p>I’ve added a Tomcat Negotiate (Kerberos + NTLM) authenticator to <a href="http://waffle.codeplex.com">Waffle</a> 1.3 for Tomcat 6. Here’s how to use it.</p>  <p><strong>Download</strong></p>  <p>Download <a href="http://waffle.codeplex.com/">Waffle 1.3</a>. The zip contains <em>Waffle.chm</em> that has the latest version of this tutorial.</p>  <p><strong>Configure Tomcat</strong></p>  <p><em>Copy Files</em></p>  <blockquote>   <p>I started with a default installation of Tomcat 6. Checked that I could start the server and navigate to <a href="http://localhost:8080">http://localhost:8080</a>. Copy the following files into tomcat’s <em>lib</em> directory.</p>    <ul>     <li><em>jna.jar</em>: Java Native Access </li>      <li><em>platform.jar</em>: JNA platform-specific API </li>      <li><em>waffle-jna.jar</em>: Tomcat Negotiate Authenticator </li>   </ul> </blockquote>  <p><em>Authenticator Valve</em></p>  <blockquote>   <p>Add a valve and a realm to the application context in your context.xml (for an application) or in server.xml (for the entire Tomcat installation).</p>    <p>     </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Context</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Valve</span><span style="color:#0000ff"> </span><span style="color:#ff0000">className</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffle.apache.NegotiateAuthenticator</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">principalFormat</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">fqn</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">roleFormat</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">both</span>"<span style="color:#0000ff"> /&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Realm</span><span style="color:#0000ff"> </span><span style="color:#ff0000">className</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">waffle.apache.WindowsRealm</span>"<span style="color:#0000ff"> /&gt;</span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Context</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>       <p></p> </blockquote>  <p><em>Security Roles</em></p>  <blockquote>   <p>Configure security roles in your application’s <em>web.xml</em>. The Waffle authenticator adds all user's security groups (including nested and domain groups) as roles during authentication.</p>    <p>     </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">security-role</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">role-name</span><span style="color:#0000ff">&gt;</span>Everyone<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">role-name</span><span style="color:#0000ff">&gt;</span></li> <li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">security-role</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>    </blockquote>  <p><em>Restrict Access</em></p>  <blockquote>   <p>Restrict access to website resources. For example, to restrict the entire website to locally authenticated users add the following in <em>web.xml</em>.</p>    <p>     </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">security-constraint</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">display-name</span><span style="color:#0000ff">&gt;</span>Waffle Security Constraint<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">display-name</span><span style="color:#0000ff">&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">web-resource-collection</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">web-resource-name</span><span style="color:#0000ff">&gt;</span>Protected Area<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">web-resource-name</span><span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">url-pattern</span><span style="color:#0000ff">&gt;</span>/*<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">url-pattern</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">web-resource-collection</span><span style="color:#0000ff">&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">auth-constraint</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">role-name</span><span style="color:#0000ff">&gt;</span>Everyone<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">role-name</span><span style="color:#0000ff">&gt;</span></li> <li>  <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">auth-constraint</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">security-constraint</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>    </blockquote>  <p><strong>Test</strong></p>  <p>Restart Tomcat and navigate to <a href="http://localhost:8080/">http://localhost:8080/</a>.</p>  <p>You should be prompted for a logon with a popup. This is because by default localhost is not in the <em>Intranet Zone </em>and the server returned a 401 Unauthorized. Internet servers with a fully qualified named are detected automatically.</p>  <p><em>Internet Explorer</em></p>  <blockquote>   <p>Ensure that Integrated Windows Authentication is enabled. </p>    <ol>     <li>Choose the<em> Tools, Internet Options</em> menu. </li>      <li>Click the <em>Advanced</em> tab. </li>      <li>Scroll down to <em>Security</em> </li>      <li>Check <em>Enable Integrated Windows Authentication</em>. </li>      <li>Restart the browser. </li>   </ol>    <p>The target website must be in the Intranet Zone. </p>    <ol>     <li>Navigate to the website. </li>      <li>Choose the <em>Tools, Internet Options</em> menu. </li>      <li>Click the <em>Local Intranet</em> icon. </li>      <li>Click the <em>Sites</em> button. </li>      <li>Check <em>Autmatically detect intranet network</em>. </li>      <li>For localhost, click <em>Advanced</em>. </li>      <li>Add <a href="http://localhost">http://localhost</a> to the list. </li>   </ol> </blockquote>  <p><em>Firefox</em></p>  <ol>   <ol>     <li>Type <em>about:config</em> in the address bar and hit enter. </li>      <li>Type <em>network.negotiate-auth.trusted-uris</em> in the Filter box. </li>      <li>Put your server name as the value. If you have more than one server, you can enter them all as a comma separated list. </li>      <li>Close the tab. </li>   </ol> </ol>  <p>Navigate to <a href="http://localhost:8080">http://localhost:8080</a> after adding it to the Intranet Zone. </p>  <p><a href="http://code.dblock.org/ShowPicture.aspx?id=54&ShowThumbnail=false"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://code.dblock.org/ShowPicture.aspx?id=55&ShowThumbnail=false" width="244" height="40" /></a> </p>  <p>You should no longer be prompted and automatically authenticated.</p>  <p><a href="http://code.dblock.org/ShowPicture.aspx?id=56&ShowThumbnail=false"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://code.dblock.org/ShowPicture.aspx?id=57&ShowThumbnail=false" width="640" height="464" /></a> </p>  <p><strong>Logs</strong></p>  <p>In the logs you will see the following output for a successful logon.</p>  <p></p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li>FINE: logged <span style="color:#0000ff">in</span> user: dblock-green\dblock (S-1-5-21-3442045183-1395134217-4167419351-1000)</li> <li style="background: #f3f3f3">FINE:  group: dblock-green\None</li> <li>FINE:  group: Everyone</li> <li style="background: #f3f3f3">FINE:  group: dblock-green\HelpLibraryUpdaters</li> <li>FINE:  group: dblock-green\HomeUsers</li> <li style="background: #f3f3f3">FINE:  group: BUILTIN\Administrators</li> <li>FINE:  group: BUILTIN\Users</li> <li style="background: #f3f3f3">FINE:  group: NT AUTHORITY\INTERACTIVE</li> <li>FINE:  group: CONSOLE LOGON</li> <li style="background: #f3f3f3">FINE:  group: NT AUTHORITY\Authenticated Users</li> <li>FINE:  group: NT AUTHORITY\This Organization</li> <li style="background: #f3f3f3">FINE:  group: S-1-5-5-0-442419</li> <li>FINE:  group: LOCAL</li> <li style="background: #f3f3f3">FINE:  group: NT AUTHORITY\NTLM Authentication</li> <li>FINE:  group: Mandatory Label\Medium Mandatory Level</li> <li style="background: #f3f3f3">INFO: successfully logged <span style="color:#0000ff">in</span> user: dblock-green\dblock</li> </ol> </div> </div> </div>  <p></p>  <p>My laptop is not a member of an Active Directory domain, but you would see domain groups, including nested ones here. There’s nothing special to do for Active Directory. The authenticator also automatically handles all aspects of the Negotiate protocol, chooses Kerberos vs. NTLM and supports NTLM POST. It basically has the same effect in Tomcat as choosing Integrated Windows authentication options in IIS.</p>  <p><strong>Links</strong></p>  <ul>   <li><a href="http://waffle.codeplex.com/SourceControl/changeset/view/52761#1097376">Tomcat Negotiate Authenticator Source Code</a> </li> </ul>  <p><strong>Related Projects</strong></p>  <ul>   <li><a href="http://tomcatspnego.codeplex.com/">Tomcat SPNEGO by Dominique Guerrin</a>: this is a very good prototype of a filter. It uses JNI and not JNA, doesn’t support NTLM POST and the code is pretty thick. </li>    <li><a href="http://spnego.sourceforge.net/">SPNEGO Sourceforge</a>: it’s a nightmare to configure, doesn’t work without an Active Directory domain and requires an SPN </li>    <li><a href="http://jcifs.samba.org/src/docs/ntlmhttpauth.html">JCIFS NTLM</a>: no longer supported and they recommend using Jespa </li>    <li><a href="http://www.ioplex.com/jespa.html">Jespa</a>: a commercial implementation that claims to do the same thing as Waffle, but uses the Netlogon service instead of the native Windows API </li> </ul></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=103">Read</a> | Updated 5/30/2010</div></html>
         ]]>
       </description>
       <category>tomcat</category><category>waffle</category><category>java</category><category>active directory</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=103</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/103</guid>
      </item>
     
      <item>
       <title>Spring-LDAP: Naming and Directory Services with OpenDS</title>
       <pubDate>Thu, 13 May 2010 09:45:02 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p><a href="http://code.dblock.org/ShowPicture.aspx?id=50&ShowThumbnail=false"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="right" src="http://code.dblock.org/ShowPicture.aspx?id=51&ShowThumbnail=false" width="206" height="77" /></a> </p>  <p>In a <a href="http://code.dblock.org/ShowPost.aspx?id=96">previous post</a> I’ve described an initial implementation of OpenDS as a naming and directory service, including extending the directory schema and reading and writing directory objects with JNDI. As actual (read: competent) Java developers took over my prototype, they switched from JNDI to <a href="http://www.springsource.org/ldap">spring-ldap</a>. The resulting code is much more pleasant, and I got to learn a bit more about Spring.</p>  <p><strong>Service Object</strong></p>  <p>Lets get something useful in and out of the directory: a <em>Service</em> object. Naturally it doesn’t matter where it came from, so the Service class is a simple container.</p>  <p></p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="background: #fff; overflow: auto">       <ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; white-space: nowrap; background: #ffffff; padding-top: 0px">         <li><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> Service { </li>          <li style="background: #f3f3f3">    String _name; </li>          <li>    String _serviceUri; </li>          <li style="background: #f3f3f3">     </li>          <li>    <span style="color: #0000ff">public</span> Service(String name, String uri) {        </li>          <li style="background: #f3f3f3">        _name = name; </li>          <li>        _serviceUri = uri;       </li>          <li style="background: #f3f3f3">    } </li>          <li>     </li>          <li style="background: #f3f3f3">    <span style="color: #0000ff">public</span> String toString() { </li>          <li>        <span style="color: #0000ff">return</span> _name + <span style="color: #a31515">" @ "</span> + _serviceUri; </li>          <li style="background: #f3f3f3">    } </li>          <li>  </li>          <li style="background: #f3f3f3">    <span style="color: #0000ff">public</span> String getName() { </li>          <li>        <span style="color: #0000ff">return</span> _name; </li>          <li style="background: #f3f3f3">    } </li>          <li>  </li>          <li style="background: #f3f3f3">    <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> setName(String name) { </li>          <li>        _name = name; </li>          <li style="background: #f3f3f3">    } </li>          <li>  </li>          <li style="background: #f3f3f3">    <span style="color: #0000ff">public</span> String getServiceUri() { </li>          <li>        <span style="color: #0000ff">return</span> _serviceUri; </li>          <li style="background: #f3f3f3">    } </li>          <li>  </li>          <li style="background: #f3f3f3">    <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> setServiceUri(String uri) { </li>          <li>        _serviceUri = uri; </li>          <li style="background: #f3f3f3">    } </li>          <li>} </li>       </ol>     </div>   </div> </div>  <p></p>  <p>You’ll immediately notice that in contrast with the previous implementation, this object knows nothing about being stored in a directory. I was lazy then, but this time Spring <strike>forces</strike> helps me write better code.</p>  <p><strong>Service DAO</strong></p>  <p>At the core of spring-ldap lies <em>LdapTemplate</em> that executes core LDAP functionality and encapsulates all the plumbing. We’re going to implement a simple DAO for our Service objects that can, for example, retrieve all services.</p>  <p></p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="background: #fff; overflow: auto">       <ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; white-space: nowrap; background: #ffffff; padding-top: 0px">         <li><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ServiceDAO { </li>          <li style="background: #f3f3f3">    <span style="color: #0000ff">private</span> LdapTemplate _ldapTemplate; </li>          <li>     </li>          <li style="background: #f3f3f3">    <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> setLdapTemplate(LdapTemplate ldapTemplate) { </li>          <li>        _ldapTemplate = ldapTemplate; </li>          <li style="background: #f3f3f3">    } </li>          <li>     </li>          <li style="background: #f3f3f3">    <span style="color: #0000ff">public</span> List&lt;Service&gt; getAllServices() { </li>          <li>        <span style="color: #0000ff">return</span> (List&lt;Service&gt;) _ldapTemplate.search(<span style="color: #a31515">""</span>, <span style="color: #a31515">"(objectclass=Service)"</span>, </li>          <li style="background: #f3f3f3">                <span style="color: #0000ff">new</span> ServiceAttributesMapper());         </li>          <li>    }     </li>          <li style="background: #f3f3f3">} </li>       </ol>     </div>   </div> </div>  <p></p>  <p>Notice a few important things here. First, we have not specified how to connect to the LDAP server - that will appear in the runtime configuration. Secondly, we use <em>ServiceAttributesMapper</em>, a class that knows how to map LDAP attributes into a Service object, achieving a very nice separation of concerns. </p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="background: #fff; overflow: auto">       <ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; white-space: nowrap; background: #ffffff; padding-top: 0px">         <li><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ServiceAttributesMapper implements AttributesMapper { </li>          <li style="background: #f3f3f3">    <span style="color: #0000ff">public</span> Object mapFromAttributes(Attributes attrs) throws NamingException { </li>          <li>        <span style="color: #0000ff">return</span> <span style="color: #0000ff">new</span> Service( </li>          <li style="background: #f3f3f3">                attrs.get(<span style="color: #a31515">"name"</span>).get().toString(), </li>          <li>                attrs.get(<span style="color: #a31515">"serviceUri"</span>).get().toString()                 </li>          <li style="background: #f3f3f3">                );         </li>          <li>    } </li>          <li style="background: #f3f3f3">} </li>       </ol>     </div>   </div> </div>  <p><strong>Spring Configuration</strong></p>  <p>To make it all work we need some configuration. We can define a <em>springldap.xml</em> configuration file for our tests, another one for production, etc.</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="background: #fff; overflow: auto">       <ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px">         <li>&lt;?xml version=<span style="color: #a31515">"1.0"</span> encoding=<span style="color: #a31515">"UTF-8"</span>?&gt; </li>          <li style="background: #f3f3f3">&lt;beans xmlns=<span style="color: #a31515">"http://www.springframework.org/schema/beans"</span> </li>          <li>    xmlns:xsi=<span style="color: #a31515">"http://www.w3.org/2001/XMLSchema-instance"</span> </li>          <li style="background: #f3f3f3">    xsi:schemaLocation=<span style="color: #a31515">"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"</span>&gt; </li>          <li>    &lt;bean id=<span style="color: #a31515">"contextSource"</span> </li>          <li style="background: #f3f3f3">        <span style="color: #0000ff">class</span>=<span style="color: #a31515">"org.springframework.ldap.core.support.LdapContextSource"</span>&gt; </li>          <li>        &lt;<span style="color: #0000ff">property</span> name=<span style="color: #a31515">"url"</span> value=<span style="color: #a31515">"ldap://localhost:389"</span> /&gt; </li>          <li style="background: #f3f3f3">        &lt;<span style="color: #0000ff">property</span> name=<span style="color: #a31515">"base"</span> value=<span style="color: #a31515">"dc=example,dc=com"</span> /&gt; </li>          <li>        &lt;<span style="color: #0000ff">property</span> name=<span style="color: #a31515">"userDn"</span> value=<span style="color: #a31515">"cn=Directory Manager"</span> /&gt; </li>          <li style="background: #f3f3f3">        &lt;<span style="color: #0000ff">property</span> name=<span style="color: #a31515">"password"</span> value=<span style="color: #a31515">"password"</span> /&gt;         </li>          <li>    &lt;/bean&gt; </li>          <li style="background: #f3f3f3">    &lt;bean id=<span style="color: #a31515">"ldapTemplate"</span> <span style="color: #0000ff">class</span>=<span style="color: #a31515">"org.springframework.ldap.core.LdapTemplate"</span>&gt; </li>          <li>        &lt;constructor-arg ref=<span style="color: #a31515">"contextSource"</span> /&gt; </li>          <li style="background: #f3f3f3">    &lt;/bean&gt; </li>          <li>    &lt;bean id=<span style="color: #a31515">"ldapService"</span> <span style="color: #0000ff">class</span>=<span style="color: #a31515">"com.example.springldap.ServiceDAO"</span>&gt; </li>          <li style="background: #f3f3f3">        &lt;<span style="color: #0000ff">property</span> name=<span style="color: #a31515">"ldapTemplate"</span> ref=<span style="color: #a31515">"ldapTemplate"</span> /&gt; </li>          <li>    &lt;/bean&gt; </li>          <li style="background: #f3f3f3">&lt;/beans&gt; </li>       </ol>     </div>   </div> </div>  <p>What does this do?</p>  <ol>   <li>Defines the values for the <em>LdapContextSource</em>. In our case, a url to our OpenDS installation, a base path to the objects, a user and password to access the directory. </li>    <li>Defines how to construct an <em>LdapTemplate</em> that encapsulates LDAP core functionality. It takes the context source defined above. </li>    <li>Tells Spring to set the <em>LdapTemplate</em> property of the <em>ServiceDAO</em> with the value above. </li> </ol>  <p>We could have done this all in code, but Spring helps us create another level of abstraction and enables a complete configuration-based runtime experience.</p>  <p><strong>Getting Services</strong></p>  <p>We still need to tell Spring to use this configuration at runtime before we can call DAO methods such as <em>getAllServices</em>.</p>  <p></p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="background: #fff; overflow: auto">       <ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; white-space: nowrap; background: #ffffff; padding-top: 0px">         <li>Resource resource = <span style="color: #0000ff">new</span> ClassPathResource(<span style="color: #a31515">"/springldap.xml"</span>); </li>          <li style="background: #f3f3f3">BeanFactory factory = <span style="color: #0000ff">new</span> XmlBeanFactory(resource); </li>          <li>ServiceDAO ldapService = (ServiceDAO) factory.getBean(<span style="color: #a31515">"ldapService"</span>); </li>          <li style="background: #f3f3f3">List&lt;Service&gt; serviceList = ldapService.getAllServices(); </li>       </ol>     </div>   </div> </div>  <p></p>  <p>This is nice! With Spring, we have achieved complete separation of responsibilities and pluggable configuration and, all things considered, wrote a lot less code. </p>  <p><strong>More DAO</strong></p>  <p><em>Create or Update a Service</em></p>  <p></p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="background: #fff; overflow: auto">       <ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; white-space: nowrap; background: #ffffff; padding-top: 0px">         <li><span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> createOrUpdateService(Service s) { </li>          <li style="background: #f3f3f3">    Attributes attrs = <span style="color: #0000ff">new</span> BasicAttributes(<span style="color: #0000ff">true</span>);  <span style="color: #008000">// Case ignore</span> </li>          <li>    Attribute oc = <span style="color: #0000ff">new</span> BasicAttribute(<span style="color: #a31515">"objectclass"</span>); </li>          <li style="background: #f3f3f3">    oc.add(<span style="color: #a31515">"extensibleObject"</span>); </li>          <li>    oc.add(<span style="color: #a31515">"top"</span>); </li>          <li style="background: #f3f3f3">    attrs.put(oc); </li>          <li>    attrs.put(<span style="color: #a31515">"objectclass"</span>, <span style="color: #a31515">"Service"</span>); </li>          <li style="background: #f3f3f3">    attrs.put(<span style="color: #a31515">"name"</span>, s.getName()); </li>          <li>    attrs.put(<span style="color: #a31515">"serviceUri"</span>, s.getServiceUri()); </li>          <li style="background: #f3f3f3">    DistinguishedName newServiceDN = <span style="color: #0000ff">new</span> DistinguishedName(); </li>          <li>    newServiceDN.add(<span style="color: #a31515">"cn"</span>, s.getName()); </li>          <li style="background: #f3f3f3">    _ldapTemplate.rebind(newServiceDN, null, attrs); </li>          <li>} </li>       </ol>     </div>   </div> </div>  <p></p>  <p><em>Delete a Service</em></p>  <p></p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="background: #fff; overflow: auto">       <ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; white-space: nowrap; background: #ffffff; padding-top: 0px">         <li><span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> deleteService(Service s) { </li>          <li style="background: #f3f3f3">    DistinguishedName serviceDN = <span style="color: #0000ff">new</span> DistinguishedName(); </li>          <li>    serviceDN.add(<span style="color: #a31515">"cn"</span>, s.getName()); </li>          <li style="background: #f3f3f3">    _ldapTemplate.unbind(serviceDN);         </li>          <li>} </li>       </ol>     </div>   </div> </div>  <p></p>  <p><em>Get a Service by Name</em></p>  <p></p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterSmartContent">   <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'Courier New', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="background: #fff; overflow: auto">       <ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; white-space: nowrap; background: #ffffff; padding-top: 0px">         <li><span style="color: #0000ff">public</span> Service getServiceByName(String name) throws NameNotFoundException { </li>          <li style="background: #f3f3f3">    <span style="color: #0000ff">return</span> (Service) _ldapTemplate.lookup(<span style="color: #a31515">"cn="</span> + name, </li>          <li>            <span style="color: #0000ff">new</span> ServiceAttributesMapper()); </li>          <li style="background: #f3f3f3">} </li>       </ol>     </div>   </div> </div>  <p></p>  <p><strong>Running the Code</strong></p>  <p>You can run the source code from this article with OpenDS and Eclipse.</p>  <ol>   <li>Check out the source code with SVN from <a href="svn://svn.vestris.com/codeproject/JndiDemo">svn://svn.vestris.com/codeproject/JndiDemo</a>. </li>    <li>Install OpenDS from <a href="http://www.opends.org">http://www.opends.org</a>. </li>    <li>Copy <em>schema\Services.ldif</em> into <em>OpenDS\config\schema\100-Services.ldif</em> and restart OpenDS. </li>    <li>Import the <em>JndiDemo</em> project into Eclipse and run JUnit tests in the <em>src-test</em> package. </li> </ol>  <p><strong>Links</strong></p>  <ul>   <li><a href="http://svn.vestris.com/listing.php?repname=Vestris+SVN&path=%2Fcodeproject%2FJndiDemo%2F#path_codeproject_JndiDemo_">Source Code for this Article</a> </li>    <li><a href="http://www.opends.org/">OpenDS Directory Server</a> </li>    <li><a href="http://code.dblock.org/ShowPost.aspx?id=96">Getting Started with JNDI and OpenDS</a> </li>    <li><a href="http://www.springsource.org/ldap">Spring-LDAP</a> </li> </ul></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=102">Read</a> | Updated 5/14/2010</div></html>
         ]]>
       </description>
       <category>opends</category><category>spring</category><category>jndi</category><category>java</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=102</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/102</guid>
      </item>
     
      <item>
       <title>MSI Property Patterns: Upgrading, FirstInstall and Maintenance</title>
       <pubDate>Tue, 11 May 2010 20:00:00 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p>In writing new MSI installers, you must think about upgrade. I always recommend major upgrade – uninstall and reinstall is much cleaner. In that case the Installed vs. NOT Installed properties get confusing very quickly, so we came up with some shortcuts that make life easier. </p>
<p>We include the following file in every installer, as is.</p>
<p></p><div class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'courier new', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">
<div style="background: #fff; overflow: auto">
<ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; white-space: nowrap; background: #ffffff; padding-top: 0px">
<li><span style="color: #0000ff">&lt;?</span><span style="color: #a31515">include</span><span style="color: #0000ff"> </span><span style="color: #808080">Runtime.wxi</span><span style="color: #0000ff">?&gt;</span></li></ol></div></div></div>
<p></p>
<p>Runtime.wxi follows.</p>
<p></p><div class="wlWriterSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'courier new', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">
<div style="background: #fff; overflow: auto">
<ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; white-space: nowrap; background: #ffffff; padding-top: 0px">
<li><span style="color: #0000ff">&lt;?</span><span style="color: #a31515">xml</span><span style="color: #0000ff"> </span><span style="color: #ff0000">version</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">1.0</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">encoding</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">utf-8</span>"<span style="color: #0000ff">?&gt;</span> </li>
<li style="background: #f3f3f3"><span style="color: #0000ff">&lt;</span><span style="color: #a31515">Include</span><span style="color: #0000ff"> </span><span style="color: #ff0000">xmlns</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">http://schemas.microsoft.com/wix/2006/wi</span>"<span style="color: #0000ff">&gt;</span> </li>
<li>  </li>
<li style="background: #f3f3f3">  <span style="color: #0000ff">&lt;!--</span> </li>
<li>   <span style="color: #008000">FirstInstall: when product is installed for the first time</span> </li>
<li style="background: #f3f3f3">   <span style="color: #008000">Upgrading: when we run upgrade for the installed product</span> </li>
<li>   <span style="color: #008000">RemovingForUpgrade: when upgrade removes previous installation</span> </li>
<li style="background: #f3f3f3">   <span style="color: #008000">Uninstalling: when product is being completely unistalled</span> </li>
<li>   <span style="color: #008000">Maintenance: configuration maintenance</span> </li>
<li style="background: #f3f3f3">  <span style="color: #0000ff">--&gt;</span> </li>
<li>  </li>
<li style="background: #f3f3f3">  <span style="color: #0000ff">&lt;</span><span style="color: #a31515">CustomAction</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Id</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetFirstInstall</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">Property</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">FirstInstall</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">Value</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">true</span>"<span style="color: #0000ff"> /&gt;</span> </li>
<li>  <span style="color: #0000ff">&lt;</span><span style="color: #a31515">CustomAction</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Id</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetUpgrading</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">Property</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">Upgrading</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">Value</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">true</span>"<span style="color: #0000ff"> /&gt;</span> </li>
<li style="background: #f3f3f3">  <span style="color: #0000ff">&lt;</span><span style="color: #a31515">CustomAction</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Id</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetRemovingForUpgrade</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">Property</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">RemovingForUpgrade</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">Value</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">true</span>"<span style="color: #0000ff"> /&gt;</span> </li>
<li>  <span style="color: #0000ff">&lt;</span><span style="color: #a31515">CustomAction</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Id</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetUninstalling</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">Property</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">Uninstalling</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">Value</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">true</span>"<span style="color: #0000ff"> /&gt;</span> </li>
<li style="background: #f3f3f3">  <span style="color: #0000ff">&lt;</span><span style="color: #a31515">CustomAction</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Id</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetMaintenance</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">Property</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">Maintenance</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">Value</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">true</span>"<span style="color: #0000ff"> /&gt;</span> </li>
<li>  </li>
<li style="background: #f3f3f3">  <span style="color: #0000ff">&lt;</span><span style="color: #a31515">InstallExecuteSequence</span><span style="color: #0000ff">&gt;</span> </li>
<li>    <span style="color: #0000ff">&lt;</span><span style="color: #a31515">Custom</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Action</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetFirstInstall</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">After</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">FindRelatedProducts</span>"<span style="color: #0000ff">&gt;</span> </li>
<li style="background: #f3f3f3">      NOT Installed AND NOT OLDERVERSION_BEINGUPGRADED AND NOT NEWERVERSION_INSTALLED </li>
<li>    <span style="color: #0000ff">&lt;/</span><span style="color: #a31515">Custom</span><span style="color: #0000ff">&gt;</span> </li>
<li style="background: #f3f3f3">    <span style="color: #0000ff">&lt;</span><span style="color: #a31515">Custom</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Action</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetUpgrading</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">After</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetFirstInstall</span>"<span style="color: #0000ff">&gt;</span> </li>
<li>      OLDERVERSION_BEINGUPGRADED AND NOT (REMOVE="ALL") </li>
<li style="background: #f3f3f3">    <span style="color: #0000ff">&lt;/</span><span style="color: #a31515">Custom</span><span style="color: #0000ff">&gt;</span> </li>
<li>    <span style="color: #0000ff">&lt;</span><span style="color: #a31515">Custom</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Action</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetUninstalling</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">After</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetUpgrading</span>"<span style="color: #0000ff">&gt;</span> </li>
<li style="background: #f3f3f3">      Installed AND (REMOVE="ALL") AND NOT (OLDERVERSION_BEINGUPGRADED OR UPGRADINGPRODUCTCODE) </li>
<li>    <span style="color: #0000ff">&lt;/</span><span style="color: #a31515">Custom</span><span style="color: #0000ff">&gt;</span> </li>
<li style="background: #f3f3f3">    <span style="color: #0000ff">&lt;</span><span style="color: #a31515">Custom</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Action</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetMaintenance</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">After</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetUninstalling</span>"<span style="color: #0000ff">&gt;</span> </li>
<li>      Installed AND NOT Upgrading AND NOT Uninstalling AND NOT UPGRADINGPRODUCTCODE </li>
<li style="background: #f3f3f3">    <span style="color: #0000ff">&lt;/</span><span style="color: #a31515">Custom</span><span style="color: #0000ff">&gt;</span> </li>
<li>    <span style="color: #0000ff">&lt;</span><span style="color: #a31515">Custom</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Action</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetRemovingForUpgrade</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">After</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">RemoveExistingProducts</span>"<span style="color: #0000ff">&gt;</span> </li>
<li style="background: #f3f3f3">      (REMOVE="ALL") AND UPGRADINGPRODUCTCODE </li>
<li>    <span style="color: #0000ff">&lt;/</span><span style="color: #a31515">Custom</span><span style="color: #0000ff">&gt;</span> </li>
<li style="background: #f3f3f3">  <span style="color: #0000ff">&lt;/</span><span style="color: #a31515">InstallExecuteSequence</span><span style="color: #0000ff">&gt;</span> </li>
<li>  <span style="color: #0000ff">&lt;</span><span style="color: #a31515">InstallUISequence</span><span style="color: #0000ff">&gt;</span> </li>
<li style="background: #f3f3f3">    <span style="color: #0000ff">&lt;</span><span style="color: #a31515">Custom</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Action</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetFirstInstall</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">After</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">FindRelatedProducts</span>"<span style="color: #0000ff">&gt;</span> </li>
<li>      Not Installed AND NOT OLDERVERSION_BEINGUPGRADED AND NOT NEWERVERSION_INSTALLED </li>
<li style="background: #f3f3f3">    <span style="color: #0000ff">&lt;/</span><span style="color: #a31515">Custom</span><span style="color: #0000ff">&gt;</span> </li>
<li>    <span style="color: #0000ff">&lt;</span><span style="color: #a31515">Custom</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Action</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetUpgrading</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">After</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetFirstInstall</span>"<span style="color: #0000ff">&gt;</span> </li>
<li style="background: #f3f3f3">      OLDERVERSION_BEINGUPGRADED AND NOT (REMOVE="ALL") </li>
<li>    <span style="color: #0000ff">&lt;/</span><span style="color: #a31515">Custom</span><span style="color: #0000ff">&gt;</span> </li>
<li style="background: #f3f3f3">    <span style="color: #0000ff">&lt;</span><span style="color: #a31515">Custom</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Action</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetUninstalling</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">After</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetUpgrading</span>"<span style="color: #0000ff">&gt;</span> </li>
<li>      Installed AND (REMOVE="ALL") AND NOT (OLDERVERSION_BEINGUPGRADED OR UPGRADINGPRODUCTCODE) </li>
<li style="background: #f3f3f3">    <span style="color: #0000ff">&lt;/</span><span style="color: #a31515">Custom</span><span style="color: #0000ff">&gt;</span> </li>
<li>    <span style="color: #0000ff">&lt;</span><span style="color: #a31515">Custom</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Action</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetMaintenance</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">After</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">SetUninstalling</span>"<span style="color: #0000ff">&gt;</span> </li>
<li style="background: #f3f3f3">      Installed AND NOT Upgrading AND NOT Uninstalling AND NOT UPGRADINGPRODUCTCODE </li>
<li>    <span style="color: #0000ff">&lt;/</span><span style="color: #a31515">Custom</span><span style="color: #0000ff">&gt;</span> </li>
<li style="background: #f3f3f3">  <span style="color: #0000ff">&lt;/</span><span style="color: #a31515">InstallUISequence</span><span style="color: #0000ff">&gt;</span> </li>
<li><span style="color: #0000ff">&lt;/</span><span style="color: #a31515">Include</span><span style="color: #0000ff">&gt;</span> </li></ol></div></div></div>
<p></p>
<p>Don’t forget to define the OLDERVERSION_BEINGUPGRADED and NEWERVERSION_INSTALLED properties in the Upgrade table.</p>
<p></p><div class="wlWriterSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'courier new', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">
<div style="background: #fff; overflow: auto">
<ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; white-space: nowrap; background: #ffffff; padding-top: 0px">
<li><span style="color: #0000ff">&lt;</span><span style="color: #a31515">Upgrade</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Id</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">$(var.UpgradeCode)</span>"<span style="color: #0000ff">&gt;</span> </li>
<li style="background: #f3f3f3">  <span style="color: #0000ff">&lt;</span><span style="color: #a31515">UpgradeVersion</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Property</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">OLDERVERSION_BEINGUPGRADED</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">Minimum</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">0.0.0</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">Maximum</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">$(var.ProductVersion)</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">IncludeMaximum</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">no</span>"<span style="color: #0000ff"> /&gt;</span> </li>
<li>  <span style="color: #0000ff">&lt;</span><span style="color: #a31515">UpgradeVersion</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Property</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">NEWERVERSION_INSTALLED</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">OnlyDetect</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">yes</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">Minimum</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">$(var.ProductVersion)</span>"<span style="color: #0000ff"> </span><span style="color: #ff0000">IncludeMinimum</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">no</span>"<span style="color: #0000ff"> /&gt;</span> </li>
<li style="background: #f3f3f3"><span style="color: #0000ff">&lt;/</span><span style="color: #a31515">Upgrade</span><span style="color: #0000ff">&gt;</span> </li></ol></div></div></div>
<p></p>
<p>And change the install sequence for major upgrade.</p>
<p></p><div class="wlWriterSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: 'courier new', courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">
<div style="background: #fff; overflow: auto">
<ol style="padding-bottom: 0px; margin: 0px; padding-left: 5px; padding-right: 0px; white-space: nowrap; background: #ffffff; padding-top: 0px">
<li><span style="color: #0000ff">&lt;</span><span style="color: #a31515">InstallExecuteSequence</span><span style="color: #0000ff">&gt;</span> </li>
<li style="background: #f3f3f3">  <span style="color: #0000ff">&lt;</span><span style="color: #a31515">FindRelatedProducts</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Before</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">AppSearch</span>"<span style="color: #0000ff"> /&gt;</span> </li>
<li>  <span style="color: #0000ff">&lt;</span><span style="color: #a31515">AppSearch</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Before</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">LaunchConditions</span>"<span style="color: #0000ff"> /&gt;</span> </li>
<li style="background: #f3f3f3">  <span style="color: #0000ff">&lt;</span><span style="color: #a31515">RemoveExistingProducts</span><span style="color: #0000ff"> </span><span style="color: #ff0000">After</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">InstallInitialize</span>"<span style="color: #0000ff"> /&gt;</span> </li>
<li><span style="color: #0000ff">&lt;/</span><span style="color: #a31515">InstallExecuteSequence</span><span style="color: #0000ff">&gt;</span> </li>
<li style="background: #f3f3f3"><span style="color: #0000ff">&lt;</span><span style="color: #a31515">InstallUISequence</span><span style="color: #0000ff">&gt;</span> </li>
<li>  <span style="color: #0000ff">&lt;</span><span style="color: #a31515">FindRelatedProducts</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Before</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">AppSearch</span>"<span style="color: #0000ff"> /&gt;</span> </li>
<li style="background: #f3f3f3">  <span style="color: #0000ff">&lt;</span><span style="color: #a31515">AppSearch</span><span style="color: #0000ff"> </span><span style="color: #ff0000">Before</span><span style="color: #0000ff">=</span>"<span style="color: #0000ff">LaunchConditions</span>"<span style="color: #0000ff"> /&gt;</span> </li>
<li><span style="color: #0000ff">&lt;/</span><span style="color: #a31515">InstallUISequence</span><span style="color: #0000ff">&gt;</span> </li></ol></div></div></div>
<p></p>
<p>Initially we had to deal with a legacy InstallShield installer and these properties were more complicated. Read <a href="http://code.dblock.org/ShowPost.aspx?id=42">this post</a> instead if that’s what you’re trying to do.</p></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=101">Read</a> | Updated 5/11/2010</div></html>
         ]]>
       </description>
       <category>msi</category><category>wix</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=101</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/101</guid>
      </item>
     
      <item>
       <title>MSI Community Extensions: deploying databases</title>
       <pubDate>Tue, 11 May 2010 17:56:55 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p>I announced in a <a href="http://code.dblock.org/ShowPost.aspx?id=65">previous post</a> that AppSecInc. has open-sourced its Wix extensions. We’ve continued developing the project for our own needs and have seen some adoption, especially for installing databases. This was expected, since what distinguishes these extensions from stock Wix ones is a programming model that is not narrowly focused on MSSQL, effectively supporting any ODBC database today and creating the opportunity to support other database targets, such as Oracle.</p>  <p>In this post I’ll show you how to get started with installing an MSSQL database in just a few lines of code.</p>  <p><strong>Adding References</strong></p>  <p>First, you must add a reference to the WixDataSource extension to your Wix project and include the DataSource extension’s namespace into the Wix XML declaration.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Wix</span><span style="color:#0000ff"> </span><span style="color:#ff0000">xmlns</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">http://schemas.microsoft.com/wix/2006/wi</span>"<span style="color:#0000ff"></span></li> <li style="background: #f3f3f3"><span style="color:#0000ff"> </span><span style="color:#ff0000">xmlns:DataSource</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">http://schemas.appsecinc.com/wix/DataSourceExtension</span>"<span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>   <p><strong>ODBC Connection</strong></p>  <p>To connect to a database you need an ODBC connection. For now, we don’t have <em>ODBC_CONNECTION_STRING</em> defined, so each implementation that uses this connection will need (and does) supply its own default. For example, SQL server extensions assume that the default connection string refers to a local database with Windows authentication.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">DataSource:ODBCConnection</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">DemoSQLServerConnection</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">ConnectionString</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">[ODBC_CONNECTION_STRING]</span>"<span style="color:#0000ff"> /&gt;</span></li> </ol> </div> </div> </div>   <p></p>  <p></p>  <p><strong>MSSQL Database</strong></p>  <p>We can now define an MSSQL database.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Component</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">MSSQLDatabaseMsiComponent</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Guid</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">0FEAF4B6-7065-47e2-A403-E94A4B176772</span>"<span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">CreateFolder</span><span style="color:#0000ff">/&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">DataSource:MSSQLDatabase</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">MSSQLDemoDatabase</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Name</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">DemoDatabase</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">ConnectionId</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">DemoSQLServerConnection</span>"<span style="color:#0000ff"> </span></li> <li style="background: #f3f3f3">   <span style="color:#0000ff"></span><span style="color:#ff0000">CreateOnInstall</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">yes</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">DropOnUnInstall</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">no</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">CheckIfExists</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">yes</span>"<span style="color:#0000ff"> /&gt;</span></li> <li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Component</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>   <p></p>  <p>What’s happening here? </p>  <p>We tell the extension to create a database called <em>DemoDatabase</em> using the <em>DemoSQLServerConnection</em>. We tell it to create the database on install and not to drop it on uninstall. We also tell it to check whether the database exists and not to fail if that’s the case. This is a typical scenario where a DBA will pre-create the database and the installer will need to create tables and upload initial data into it.</p>  <p>We’ve nested the database under a component, so component rules apply. You can include the component into a feature and the user can, for example, choose to install or not install the feature. You can add other conditions at many levels here, etc.</p>  <p><strong>Database Schema</strong></p>  <p>A database without a schema is not very useful. We author a .sql file that creates the schema and execute it on FirstInstall (for more explanation on FirstInstall and Upgrading conditions see <a href="http://code.dblock.org/ShowPost.aspx?id=42">this post</a>).</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">DataSource:MSSQLDatabase</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">MSSQLDemoDatabase</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Name</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">DemoDatabase</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">ConnectionId</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">DemoSQLServerConnection</span>"</li> <li style="background: #f3f3f3">  <span style="color:#0000ff"></span><span style="color:#ff0000">CreateOnInstall</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">yes</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">DropOnUnInstall</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">no</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">CheckIfExists</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">yes</span>"<span style="color:#0000ff">&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">DataSource:ODBCExecute</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">MSSQLDemoDatabase_CreateSchema</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">ExecuteOnInstall</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">yes</span>"<span style="color:#0000ff"> </span></li> <li style="background: #f3f3f3">   <span style="color:#0000ff"></span><span style="color:#ff0000">BasePath</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">[INSTALLLOCATION]</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Type</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">SqlServer</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">File</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Schema.sql</span>"<span style="color:#0000ff">&gt;</span>FirstInstall OR Upgrading<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">DataSource:ODBCExecute</span><span style="color:#0000ff">&gt;</span></li> <li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">DataSource:MSSQLDatabase</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>   <p>To simplify things for the purposes of this post, the Schema.sql file knows how to handle its own upgrade. </p>  <p>There’re some more interesting things here. Notice that we use a generic <em>ODBCExecute</em> extension that works for this specific MSSQL database. The declaration has a <em>Type=”SqlServer”</em>. This is a new feature in <a href="http://msiext.codeplex.com/releases/view/39468">MSI Extensions 1.2</a> – the file will be parsed with an actual SQL parser, split by GO statements (configurable) and execute the statements one-by-one. The idea is that the parsers can one day become converters and adjust syntax from, for example, HQL to SQL of a specific database target. For now, this makes SQL execution identical to one in MSSQL Query Analyzer.</p>  <p>Secondly, with MSI Extensions 1.2, Schema.sql may be an ANSI or a UTF-8 file. This is detected automatically. You can finally deploy your databases with Russian table names or content.</p>  <p><strong>User Experience</strong></p>  <p>We now want to give users an opportunity to choose where to install this database and which credentials to use. For this purpose we add the <em>WixCommonUiExtension.dll</em> to the project and redefine the UI sequence to reference some stock dialogs.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">&lt;?</span><span style="color:#a31515">xml</span><span style="color:#0000ff"> </span><span style="color:#ff0000">version</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">1.0</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">encoding</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">utf-8</span>"<span style="color:#0000ff">?&gt;</span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Include</span><span style="color:#0000ff">&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Property</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">CREATE_DATABASE_LOGON_TYPE</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Value</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">WinAuthCurrentUser</span>"<span style="color:#0000ff"> /&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Property</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">CHECK_CREATE_DATABASE_PERMS</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Value</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">yes</span>"<span style="color:#0000ff"> /&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Property</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">RUNTIME_DATABASE_LOGON_TYPE</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Value</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">WinAuth</span>"<span style="color:#0000ff"> /&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Property</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">CHECK_RUNTIME_DATABASE_PERMS</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Value</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">yes</span>"<span style="color:#0000ff"> /&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Property</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">RUNTIME_DATABASE_NAME</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Value</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Northwind</span>"<span style="color:#0000ff"> /&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Property</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">RUNTIME_DATABASE_PERMS_TABLE</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Value</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Authors</span>"<span style="color:#0000ff"> /&gt;</span></li> <li>  <span style="color:#0000ff">&lt;</span><span style="color:#a31515">UI</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">DialogRef</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">SelectDbDlg</span>"<span style="color:#0000ff"> /&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">DialogRef</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">DbCreateCredDlg</span>"<span style="color:#0000ff"> /&gt;  </span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">DialogRef</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">GenericErrorDlg</span>"<span style="color:#0000ff"> /&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">DialogRef</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">WelcomeDlg</span>"<span style="color:#0000ff"> /&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">DialogRef</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">VerifyReadyDlg</span>"<span style="color:#0000ff"> /&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">DialogRef</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">ErrorDlg</span>"<span style="color:#0000ff"> /&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">DialogRef</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">FatalError</span>"<span style="color:#0000ff"> /&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">DialogRef</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">FilesInUse</span>"<span style="color:#0000ff"> /&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">DialogRef</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Id</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">UserExit</span>"<span style="color:#0000ff"> /&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Publish</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Dialog</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">WelcomeDlg</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Control</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Next</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Event</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">NewDialog</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Value</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">SelectDbDlg</span>"<span style="color:#0000ff">&gt;</span>NOT Installed<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Publish</span><span style="color:#0000ff">&gt;        </span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Publish</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Dialog</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">SelectDbDlg</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Control</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Next</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Event</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">NewDialog</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Value</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">DbCreateCredDlg</span>"<span style="color:#0000ff">&gt;</span>NOT Installed<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Publish</span><span style="color:#0000ff">&gt;    </span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Publish</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Dialog</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">SelectDbDlg</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Control</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Back</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Event</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">NewDialog</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Value</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">WelcomeDlg</span>"<span style="color:#0000ff">&gt;</span>NOT Installed<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Publish</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Publish</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Dialog</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">DbCreateCredDlg</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Control</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Next</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Event</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">NewDialog</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Value</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">VerifyReadyDlg</span>"<span style="color:#0000ff">&gt;</span>NOT Installed<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Publish</span><span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Publish</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Dialog</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">DbCreateCredDlg</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Control</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Back</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Event</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">NewDialog</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Value</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">SelectDbDlg</span>"<span style="color:#0000ff">&gt;</span>NOT Installed<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Publish</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Publish</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Dialog</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">VerifyReadyDlg</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Control</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Back</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Event</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">NewDialog</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Value</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">DbCreateCredDlg</span>"<span style="color:#0000ff">&gt;</span>NOT Installed<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Publish</span><span style="color:#0000ff">&gt;</span></li> <li>    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Publish</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Dialog</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">ExitDialog</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Control</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Back</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Event</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">EndDialog</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Value</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">VerifyReadyDlg</span>"<span style="color:#0000ff">&gt;</span>1<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Publish</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#0000ff">&lt;</span><span style="color:#a31515">Publish</span><span style="color:#0000ff"> </span><span style="color:#ff0000">Dialog</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">ExitDialog</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Control</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Finish</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Event</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">EndDialog</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Value</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">Return</span>"<span style="color:#0000ff"> </span><span style="color:#ff0000">Order</span><span style="color:#0000ff">=</span>"<span style="color:#0000ff">999</span>"<span style="color:#0000ff">&gt;</span>1<span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Publish</span><span style="color:#0000ff">&gt;</span></li> <li>  <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">UI</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3"><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Include</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>   <p>Notice the DbCreateCredDlg that was inserted and a few defaults for various options that drive this dialog. The latter supports testing credentials, choosing whether to use SQL Server or Windows authentication, etc.</p>  <p>The DbCreateCredDlg looks like this and publishes the <em>ODBC_CONNECTION_STRING</em> property, connecting the dots between the UI and the ODBC connection used to create the database.</p>  <p><a href="http://code.dblock.org/ShowPicture.aspx?id=47&ShowThumbnail=false"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="MSSQLDatabase" border="0" alt="MSSQLDatabase" src="http://code.dblock.org/ShowPicture.aspx?id=48&ShowThumbnail=false" width="513" height="402" /></a> </p>  <p><strong>Conclusion</strong></p>  <p>That’s it. You now have a working database installer with virtually zero lines of code.</p></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=100">Read</a></div></html>
         ]]>
       </description>
       <category>databases</category><category>msi</category><category>wix</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=100</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/100</guid>
      </item>
     
      <item>
       <title>FoodCandy.com: Implementing Facebook Connect and Signup w/ Graph API</title>
       <pubDate>Fri, 07 May 2010 14:44:54 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p><strong><a href="http://code.dblock.org/ShowPicture.aspx?id=38&ShowThumbnail=false"><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="facebook" border="0" alt="facebook" align="right" src="http://code.dblock.org/ShowPicture.aspx?id=39&ShowThumbnail=false" width="160" height="212" /></a> Overview</strong></p>  <p>I finally found some time to implement Facebook Connect for <a href="http://www.foodcandy.com/">FoodCandy.com</a>. You can now do the following.</p>  <ul>   <li>Sign-Up with a Facebook account, no questions asked on FoodCandy.com. </li>    <li>Associate an existing Facebook account with a previously created FoodCandy.com account. </li>    <li>Login to FoodCandy with a previously associated Facebook account. </li> </ul>  <p><strong>Is it hard?</strong></p>  <p>It’s not. There’s about a day of work for all the items above, including this post.</p>  <p><strong>Why am I writing this?</strong></p>  <p>Two reasons.</p>  <p>There’re several interesting aspects to the FoodCandy service model, in particular that the website is just a front-end UI to <a href="http://sncore.vestris.com">SnCore</a> and cannot do authentication. It needs to pass all data to the services back-end via a SOAP API, which in turn will do authentication. This means that we need to do more work and less magic. </p>  <p>I had to do some wrestling with JavaScript and the Facebook API at login. Most of the examples I found didn’t quite work. This post should, hopefully, be more helpful to those implementing Facebook Connect in C# / ASP.NET. </p>  <p><strong>Application Registration</strong></p>  <p>I registered <a href="http://www.facebook.com/#!/developers/apps.php">an application</a>, which gave me an API key and a shared secret. The first is public, but the latter is going to be stored on the back-end and used to verify login signatures or make authenticated calls to Facebook. You would typically store both in some configuration file, SnCore has a settings framework that lets you store both public information and “password”-like settings accessible to the back-end only.</p>  <blockquote>   <p><a href="http://code.dblock.org/ShowPicture.aspx?id=40&ShowThumbnail=false"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://code.dblock.org/ShowPicture.aspx?id=41&ShowThumbnail=false" width="240" height="234" /></a> </p> </blockquote>  <p><strong>Single Sign On</strong></p>  <p>The best document to read first is <a href="http://developers.facebook.com/docs/guides/web">here</a>.</p>  <p><em>A Facebook Login Button</em></p>  <div>I want a login button that gives users a choice of logging into the site with a username and a password, an OpenId and now with a Facebook login. The recommended way is to include some JavaScript and use FBML (a simple markup language) to render it. That approach caused me to have a click-popup-reload cycle, which I didn’t like at all. An alternate suggested way is to generate a login URL manually and let the user navigate away from the site, login to Facebook and return. This is simpler, IMHO, code non-withstanding.</div>  <blockquote>   <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li><span style="color:#0000ff">public</span> <span style="color:#0000ff">string</span> GetLoginUrl(<span style="color:#0000ff">string</span> returnUrl)</li> <li style="background: #f3f3f3">{</li> <li>    <span style="color:#0000ff">return</span> <span style="color:#0000ff">string</span>.Format(<span style="color:#a31515">"http://www.facebook.com/login.php?api_key={0}&extern=1&fbconnect=1&req_perms=publish_stream,email&return_session=1&v=1.0&next={1}&fb_connect=1&cancel_url={1}"</span>,</li> <li style="background: #f3f3f3">        FacebookAPIKey, <span style="color:#2b91af">Renderer</span>.UrlEncode(<span style="color:#0000ff">string</span>.Format(<span style="color:#a31515">"{0}/FacebookConnect.aspx?connect=1&ReturnUrl={1}"</span>, mSessionManager.WebsiteUrl, <span style="color:#2b91af">Renderer</span>.UrlEncode(returnUrl))));</li> <li>}</li> </ol> </div> </div> </div> </blockquote>  <p>The URL specifies the following.</p>  <ul>   <li>Tell Facebook login to return to FacebookConnect.aspx with parameters that will indicate the redirect location after a successful login. Facebook application settings require you to specify a single login return location. In addition this must be a dynamic page with a ? in the URL. </li>    <li>Tell Facebook that we want <em>publish_stream</em> and <em>email</em> access. The <em>publish_stream</em> option asks the user to authorize our application to publish content on Facebook, which is beyond the scope of this post. The <em>email</em> option asks the user to authorize our application to send the user an e-mail. You don’t actually ever get the user’s e-mail, but an application-specific e-mail forward address. </li> </ul>  <p><em>Redirect After Login</em></p>  <p>A logged-in user is now returned to FacebookConnect.aspx with a number of parameters in the URL that contain session information.</p>  <p>Facebook JavaScript can process all that into cookies. The cookie names start with the API key. You can find a lot more detail about cookies <a href="http://wiki.developers.facebook.com/index.php/Verifying_The_Signature#Signatures_and_Facebook_Connect_Sites">here</a>.</p>  <blockquote>   <p><a href="http://code.dblock.org/ShowPicture.aspx?id=42&ShowThumbnail=false"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://code.dblock.org/ShowPicture.aspx?id=43&ShowThumbnail=false" width="465" height="108" /></a> </p> </blockquote>  <p>Invoking this JavaScript gave me a lot of headache – I was properly redirected to FacebookConnect.aspx, but no cookies were set. The problem was that you need to initialize the Facebook API, then synchronously wait for it to set the cookies and therefore complete. </p>  <div>The following code works every time.</div>  <blockquote>   <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li> <span style="color:#0000ff">&lt;</span><span style="color:#a31515">div</span> <span style="color:#ff0000">id</span><span style="color:#0000ff">="fb-root"&gt;&lt;/</span><span style="color:#a31515">div</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3"> <span style="color:#0000ff">&lt;</span><span style="color:#a31515">script</span> <span style="color:#ff0000">src</span><span style="color:#0000ff">="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"</span> <span style="color:#ff0000">type</span><span style="color:#0000ff">="text/javascript"&gt;&lt;/</span><span style="color:#a31515">script</span><span style="color:#0000ff">&gt;</span></li> <li> <span style="color:#0000ff">&lt;</span><span style="color:#a31515">script</span> <span style="color:#ff0000">type</span><span style="color:#0000ff">="text/javascript"&gt;</span></li> <li style="background: #f3f3f3">  <span style="color:#0000ff">var</span> facebookAPIKey = <span style="color:#a31515">"&lt;% Response.Write(FacebookAPIKey); %&gt;"</span>;</li> <li>  FB.init(facebookAPIKey);</li> <li style="background: #f3f3f3">  FB.ensureInit(<span style="color:#0000ff">function</span>() {</li> <li>   FB.Connect.get_status().waitUntilReady( <span style="color:#0000ff">function</span>( status ) {</li> <li style="background: #f3f3f3">      <span style="color:#0000ff">switch</span> ( status ) {</li> <li>      <span style="color:#0000ff">case</span> FB.ConnectState.connected:</li> <li style="background: #f3f3f3">         window.location=<span style="color:#a31515">"&lt;% Response.Write(ReturnUrl); %&gt;"</span>;</li> <li>         <span style="color:#0000ff">break</span>;</li> <li style="background: #f3f3f3">      <span style="color:#0000ff">case</span> FB.ConnectState.appNotAuthorized:</li> <li>      <span style="color:#0000ff">case</span> FB.ConnectState.userNotLoggedIn:</li> <li style="background: #f3f3f3">         FB.Connect.requireSession();</li> <li>     alert(<span style="color:#a31515">'There was an error logging in.'</span>);</li> <li style="background: #f3f3f3">      }</li> <li>   });</li> <li style="background: #f3f3f3">  });</li> <li> <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">script</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div> </blockquote>  <p></p>  <p></p>  <p><em>Verifying the Signature</em></p>  <p>FacebookConnect.aspx does the job at performing a cross-site Facebook login, then redirects back to the initial login page. The latter must now verify that the login is legit and locate a FoodCandy account associated with this Facebook login. I do this work in the actual login page.</p>  <p>If you’re doing all of this on the client side, read <a href="http://wiki.developers.facebook.com/index.php/Verifying_The_Signature">this document</a> for background and use the <a href="http://fbconnectauth.codeplex.com/">Facebook Connect library</a>. I had to split the process between the front-end and the back-end and used it for a reference implementation.</p>  <p>Facebook cookies are collected in a sorted list, concatenated and signed.</p>  <blockquote>   <p>     </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">public</span> <span style="color:#2b91af">SortedList</span>&lt;<span style="color:#0000ff">string</span>, <span style="color:#0000ff">string</span>&gt; GetFacebookCookies(<span style="color:#2b91af">HttpCookieCollection</span> cookies)</li> <li style="background: #f3f3f3">{</li> <li>    <span style="color:#2b91af">SortedList</span>&lt;<span style="color:#0000ff">string</span>, <span style="color:#0000ff">string</span>&gt; sortedCookies = <span style="color:#0000ff">new</span> <span style="color:#2b91af">SortedList</span>&lt;<span style="color:#0000ff">string</span>, <span style="color:#0000ff">string</span>&gt;();</li> <li style="background: #f3f3f3">    <span style="color:#0000ff">string</span> cookiePrefix = FacebookAPIKey + <span style="color:#a31515">"_"</span>;</li> <li>    <span style="color:#0000ff">foreach</span> (<span style="color:#0000ff">string</span> cookieName <span style="color:#0000ff">in</span> cookies)</li> <li style="background: #f3f3f3">    {</li> <li>        <span style="color:#0000ff">if</span> (cookieName.StartsWith(cookiePrefix))</li> <li style="background: #f3f3f3">        {</li> <li>            <span style="color:#0000ff">var</span> cookie = cookies[cookieName];</li> <li style="background: #f3f3f3">            sortedCookies.Add(cookie.Name.Substring(cookiePrefix.Length), cookie.Value);</li> <li>        }</li> <li style="background: #f3f3f3">    }</li> <li> </li> <li style="background: #f3f3f3">    <span style="color:#0000ff">return</span> sortedCookies;</li> <li>}</li> </ol> </div> </div> </div>    </blockquote>  <p>The signature must match the value of the cookie with the same name as the API key.</p>  <blockquote>   <p>     </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">var</span> sb = <span style="color:#0000ff">new</span> <span style="color:#2b91af">StringBuilder</span>();</li> <li style="background: #f3f3f3"><span style="color:#0000ff">foreach</span> (<span style="color:#2b91af">String</span> s <span style="color:#0000ff">in</span> cookies.AllKeys)</li> <li>{</li> <li style="background: #f3f3f3">    sb.AppendFormat(<span style="color:#a31515">"{0}={1}"</span>, s, cookies[s]);</li> <li>}</li> <li style="background: #f3f3f3"> </li> <li>sb.Append(facebookSecret);</li> <li style="background: #f3f3f3"><span style="color:#0000ff">string</span> stringToHash = sb.ToString();</li> <li> </li> <li style="background: #f3f3f3"><span style="color:#2b91af">StringBuilder</span> computedHash = <span style="color:#0000ff">new</span> <span style="color:#2b91af">StringBuilder</span>();</li> <li><span style="color:#0000ff">byte</span>[] hash = <span style="color:#2b91af">MD5</span>.Create().ComputeHash(<span style="color:#2b91af">Encoding</span>.UTF8.GetBytes(stringToHash));</li> <li style="background: #f3f3f3"><span style="color:#0000ff">foreach</span> (<span style="color:#0000ff">byte</span> b <span style="color:#0000ff">in</span> hash)</li> <li>{</li> <li style="background: #f3f3f3">    computedHash.AppendFormat(<span style="color:#a31515">"{0:x2}"</span>, b);</li> <li>}</li> <li style="background: #f3f3f3"> </li> <li><span style="color:#0000ff">return</span> computedHash.ToString().ToLowerInvariant() == signature.ToLowerInvariant();</li> </ol> </div> </div> </div>    </blockquote>  <p><em>Facebook Account Id to FoodCandy Account Id</em></p>  <p>Once the signature is verified, you can trust the Facebook user id stored in the “user” cookie. It’s a 64-bit integer. I created a new table in SnCore called <em>AccountFacebook</em> and allow users to associate facebook IDs with their account. If the back-end can locate such an account, an SnCore login ticket is issued, which completes the login operation.</p>  <blockquote>   <p>     </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#2b91af">AccountFacebook</span> account = (<span style="color:#2b91af">AccountFacebook</span>)session.CreateCriteria(<span style="color:#0000ff">typeof</span>(<span style="color:#2b91af">AccountFacebook</span>))</li> <li style="background: #f3f3f3">        .Add(<span style="color:#2b91af">Expression</span>.Eq(<span style="color:#a31515">"FacebookAccountId"</span>, FacebookAccountId))</li> <li>        .UniqueResult();</li> </ol> </div> </div> </div>    </blockquote>  <p><strong>FoodCandy Signup with Facebook</strong></p>  <p>The signup process first goes through the same logon process as described above, except that the final landing page is one that will create an account. Most of what I describe below is well explained <a href="http://devtacular.com/articles/bkonrad/how-to-retrieve-user-data-from-facebook-connect-in-aspnet">here</a>, albeit for an older version of the API. This should serve as a refresher.</p>  <p>First, I got hold of the <a href="http://facebooktoolkit.codeplex.com/">Facebook Developer Toolkit</a> that implements calls to Facebook using the <a href="http://developers.facebook.com/docs/api">Facebook Graph API</a>. It is initialized with the API key, the secret and a session key. The toolkit is going to be making server-to-server calls from FoodCandy to Facebook, it’s all back-end operation.</p>  <blockquote>   <p>     </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li>Facebook.Session.<span style="color:#2b91af">ConnectSession</span> facebookSession = <span style="color:#0000ff">new</span> Facebook.Session.<span style="color:#2b91af">ConnectSession</span>(</li> <li style="background: #f3f3f3">    FacebookAPIKey, FacebookSecret);</li> <li> </li> <li style="background: #f3f3f3">facebookSession.SessionKey = facebookCookies[<span style="color:#a31515">"session_key"</span>];</li> <li>facebookSession.UserId = <span style="color:#0000ff">long</span>.Parse(facebookCookies[<span style="color:#a31515">"user"</span>]);</li> <li style="background: #f3f3f3">Facebook.Rest.<span style="color:#2b91af">Api</span> facebookAPI = <span style="color:#0000ff">new</span> Facebook.Rest.<span style="color:#2b91af">Api</span>(facebookSession);</li> </ol> </div> </div> </div>    </blockquote>  <p>At signup I need the user’s name, e-mail and birthday. I’d also like to get the user’s location and maybe even a picture.</p>  <blockquote>   <p>     </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li>Facebook.Schema.<span style="color:#2b91af">user</span> user = facebookAPI.Users.GetInfo();</li> <li style="background: #f3f3f3"> </li> <li><span style="color:#2b91af">TransitAccount</span> ta = <span style="color:#0000ff">new</span> <span style="color:#2b91af">TransitAccount</span>();</li> <li style="background: #f3f3f3">ta.Name = user.name;</li> <li>ta.Birthday = <span style="color:#2b91af">DateTime</span>.Parse(user.birthday_date);</li> <li style="background: #f3f3f3">acct.CreateWithFacebook(t_facebook.FacebookAccountId, user.proxied_email, </li> <li>    ta, <span style="color:#2b91af">ManagedAccount</span>.GetAdminSecurityContext(session));</li> <li style="background: #f3f3f3"> </li> <li><span style="color:#0000ff">if</span> (user.current_location != <span style="color:#0000ff">null</span>)</li> <li style="background: #f3f3f3">{</li> <li>    ta.City = user.current_location.city;</li> <li style="background: #f3f3f3"> </li> <li>    <span style="color:#0000ff">int</span> country_id;</li> <li style="background: #f3f3f3">    <span style="color:#0000ff">if</span> (<span style="color:#2b91af">ManagedCountry</span>.TryGetCountryId(session, user.current_location.country, <span style="color:#0000ff">out</span> country_id))</li> <li>        ta.Country = user.current_location.country;</li> <li style="background: #f3f3f3">    </li> <li>    <span style="color:#0000ff">int</span> state_id;</li> <li style="background: #f3f3f3">    <span style="color:#0000ff">if</span> (<span style="color:#2b91af">ManagedState</span>.TryGetStateId(session, user.current_location.state, user.current_location.country, <span style="color:#0000ff">out</span> state_id))</li> <li>        ta.State = user.current_location.state;</li> <li style="background: #f3f3f3">}</li> <li> </li> <li style="background: #f3f3f3"><span style="color:#0000ff">if</span> (user.picture_big != <span style="color:#0000ff">null</span>)</li> <li>{</li> <li style="background: #f3f3f3">    <span style="color:#2b91af">TransitAccountPicture</span> t_picture = <span style="color:#0000ff">new</span> <span style="color:#2b91af">TransitAccountPicture</span>();</li> <li>    t_picture.AccountId = acct.Id;</li> <li style="background: #f3f3f3">    <span style="color:#2b91af">ThumbnailBitmap</span> bitmap = <span style="color:#0000ff">new</span> <span style="color:#2b91af">ThumbnailBitmap</span>(<span style="color:#0000ff">new</span> <span style="color:#2b91af">Bitmap</span>(user.picture_big));</li> <li>    t_picture.Bitmap = bitmap.Bitmap;</li> <li style="background: #f3f3f3">    t_picture.Thumbnail = bitmap.Thumbnail;</li> <li>    t_picture.Name = user.pic;</li> <li style="background: #f3f3f3">    <span style="color:#2b91af">ManagedAccountPicture</span> m_picture = <span style="color:#0000ff">new</span> <span style="color:#2b91af">ManagedAccountPicture</span>(session);</li> <li>    m_picture.CreateOrUpdate(t_picture, <span style="color:#2b91af">ManagedAccount</span>.GetAdminSecurityContext(session));</li> <li style="background: #f3f3f3">}</li> <li> </li> <li style="background: #f3f3f3">SnCore.Data.Hibernate.<span style="color:#2b91af">Session</span>.Flush();</li> <li><span style="color:#0000ff">return</span> acct.Id;</li> </ol> </div> </div> </div>    </blockquote>  <p>That’s a lot of private information that you gave me with a single click! Let's look at the created account.</p>  <blockquote>   <p><a href="http://code.dblock.org/ShowPicture.aspx?id=44&ShowThumbnail=false"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://code.dblock.org/ShowPicture.aspx?id=45&ShowThumbnail=false" width="640" height="290" /></a> </p> </blockquote>  <p>Try it! Signup to FoodCandy with a Facebook account.</p>  <blockquote>   <p><a href="http://www.facebook.com/login.php?api_key=bc87da063d03aa5543d261ad7c3e1062&extern=1&fbconnect=1&req_perms=publish_stream,email&return_session=1&v=1.0&next=http%3a%2f%2fwww.foodcandy.com%2fFacebookConnect.aspx%3fconnect%3d1%26ReturnUrl%3dhttp%253a%252f%252fwww.foodcandy.com%252fAccountCreateFacebook.aspx&fb_connect=1&cancel_url=http%3a%2f%2fwww.foodcandy.com%2fFacebookConnect.aspx%3fconnect%3d1%26ReturnUrl%3dhttp%253a%252f%252fwww.foodcandy.com%252fAccountCreateFacebook.aspx"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="facebook" border="0" alt="facebook" src="http://code.dblock.org/ShowPicture.aspx?id=46&ShowThumbnail=false" width="100" height="133" /></a> </p> </blockquote>  <p><strong>Links</strong></p>  <ul>   <li><a href="http://svn.vestris.com/listing.php?repname=Vestris+SVN&path=%2Ffoodcandy%2F#path_foodcandy_">FoodCandy Source Code</a></li>    <ul>     <li><a href="http://svn.vestris.com/filedetails.php?repname=Vestris+SVN&path=%2Ffoodcandy%2FSnCore.Web%2FFacebookConnect.aspx">FacebookConnect.aspx</a> / <a href="http://svn.vestris.com/filedetails.php?repname=Vestris+SVN&path=%2Ffoodcandy%2FSnCore.Web%2FFacebookConnect.aspx.cs">.cs</a></li>      <li><a href="http://svn.vestris.com/filedetails.php?repname=Vestris+SVN&path=%2Ffoodcandy%2FSnCore.Web%2FApp_Code%2FFacebookPageManager.cs">FacebookPageManager.cs</a></li>   </ul>    <li><a href="http://sncore.vestris.com/">SnCore Social Networking Framework</a></li> </ul></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=99">Read</a></div></html>
         ]]>
       </description>
       <category>sncore</category><category>facebook</category><category>foodcandy</category><category>.net</category><category>asp.net</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=99</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/99</guid>
      </item>
     
      <item>
       <title>Java Native Access (JNA) 3.2.5 Shipped</title>
       <pubDate>Wed, 28 Apr 2010 12:16:40 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p><a href="https://jna.dev.java.net/"><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="java-logo_svg-a" border="0" alt="java-logo_svg-a" align="right" src="http://code.dblock.org/ShowPicture.aspx?id=37&ShowThumbnail=false" width="130" height="172" /> Java Native Access (JNA)</a> 3.2.5 shipped quietly last week.</p>  <p>JNA now includes <em>platform.jar</em> that has cross-platform mappings and mappings for a number of commonly used platform functions, including a large number of Win32 mappings as well as a set of utility classes that simplify native access. The code is tested and the utility interfaces ensure that native memory management is taken care of correctly. I’ve contributed a boatload of code in this area, so when something doesn’t work you can blame me.</p>  <p>Before you map your own functions, check the <a href="https://jna.dev.java.net/javadoc/platform/overview-summary.html">platform package documentation</a> for an already mapped one. </p>  <p>Platform-specific structures are mapped by header. For example, ShlObj.h structures can be found in com.sun.jna.platform.win32.ShlObj. Platform functions are mapped by library. For example, Advapi32.dll functions can be found in com.sun.jna.platform.win32.Advapi32. Simplified interfaces (wrappers) for Advapi32.dll functions can be found in com.sun.jna.platform.win32.Advapi32Util.</p>  <p>The following large areas have been covered to some extent in native interfaces and utility libraries: Registry, SSPI, Active Directory, DPAPI, Users and Groups and Shell.</p>  <ul>   <li><a href="https://jna.dev.java.net/servlets/ProjectDocumentList?folderID=12139&expandFolder=12139&folderID=0">Download 3.2.5</a> </li> </ul>  <p>There will be more refactoring and coverage in the next release. It also seems to have picked up a little traction on the mailing list as people have been sending patches with more Win32 code. I’ll do my best at committing that, so send more. The goal is to eventually cover all of win32 SDK and put the Java to Win32 interoperability problem to rest.</p></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=98">Read</a></div></html>
         ]]>
       </description>
       <category>jna</category><category>java</category><category>win32</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=98</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/98</guid>
      </item>
     
      <item>
       <title>Harvesting wix files</title>
       <pubDate>Wed, 14 Apr 2010 21:54:22 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p>Sometimes great is the enemy of good. I recently had to harvest a large number of files to create a wix installer. I tried <em>heat.exe</em>, but after struggling with its generation style and even considering writing an XSLT, I decided it would be faster to just code what I want in C#. This generates a .wxi file that follows somewhat of a standard of naming components .C, directories .D and skipping .svn folders.</p>  <p>It just gets the job done.</p>  <p></p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap"> <li><span style="color:#0000ff">using</span> System;</li> <li style="background: #f3f3f3"><span style="color:#0000ff">using</span> System.Collections.Generic;</li> <li><span style="color:#0000ff">using</span> System.Text;</li> <li style="background: #f3f3f3"><span style="color:#0000ff">using</span> System.IO;</li> <li><span style="color:#0000ff">using</span> System.Xml;</li> <li style="background: #f3f3f3"> </li> <li><span style="color:#0000ff">namespace</span> WixHarvest</li> <li style="background: #f3f3f3">{</li> <li>    <span style="color:#0000ff">class</span> <span style="color:#2b91af">Program</span></li> <li style="background: #f3f3f3">    {</li> <li>        <span style="color:#0000ff">static</span> <span style="color:#0000ff">string</span> MakeId(<span style="color:#0000ff">string</span> id)</li> <li style="background: #f3f3f3">        {</li> <li>            <span style="color:#0000ff">return</span> id.Replace(<span style="color:#a31515">"_"</span>, <span style="color:#a31515">"."</span>).Replace(<span style="color:#a31515">"-"</span>, <span style="color:#a31515">"."</span>);</li> <li style="background: #f3f3f3">        }</li> <li> </li> <li style="background: #f3f3f3">        <span style="color:#0000ff">const</span> <span style="color:#2b91af">String</span> wixns = <span style="color:#a31515">"http://schemas.microsoft.com/wix/2006/wi"</span>;</li> <li> </li> <li style="background: #f3f3f3">        <span style="color:#0000ff">static</span> <span style="color:#2b91af">List</span>&lt;<span style="color:#2b91af">String</span>&gt; GenerateFragment(<span style="color:#2b91af">XmlDocument</span> doc, <span style="color:#2b91af">XmlNode</span> parent, <span style="color:#2b91af">DirectoryInfo</span> dir, <span style="color:#2b91af">DirectoryInfo</span> root)</li> <li>        {</li> <li style="background: #f3f3f3">            <span style="color:#2b91af">List</span>&lt;<span style="color:#2b91af">String</span>&gt; componentIds = <span style="color:#0000ff">new</span> <span style="color:#2b91af">List</span>&lt;<span style="color:#0000ff">string</span>&gt;();</li> <li> </li> <li style="background: #f3f3f3">            <span style="color:#2b91af">XmlNode</span> directory = (doc.FirstChild == parent)</li> <li>                ? parent.AppendChild(doc.CreateElement(<span style="color:#a31515">"DirectoryRef"</span>, wixns))</li> <li style="background: #f3f3f3">                : parent.AppendChild(doc.CreateElement(<span style="color:#a31515">"Directory"</span>, wixns));</li> <li> </li> <li style="background: #f3f3f3">            <span style="color:#0000ff">string</span> id = <span style="color:#a31515">""</span>;</li> <li>            <span style="color:#0000ff">if</span> (parent.Attributes[<span style="color:#a31515">"Id"</span>] != <span style="color:#0000ff">null</span>) id = parent.Attributes[<span style="color:#a31515">"Id"</span>].Value.Replace(<span style="color:#a31515">".D"</span>, <span style="color:#a31515">""</span>) + <span style="color:#a31515">"."</span>;</li> <li style="background: #f3f3f3">            id += dir.Name + <span style="color:#a31515">".D"</span>;</li> <li> </li> <li style="background: #f3f3f3">            directory.Attributes.Append(doc.CreateAttribute(<span style="color:#a31515">"Id"</span>)).Value = MakeId(id);</li> <li>            <span style="color:#0000ff">if</span> (doc.FirstChild != parent)</li> <li style="background: #f3f3f3">            {</li> <li>                directory.Attributes.Append(doc.CreateAttribute(<span style="color:#a31515">"Name"</span>)).Value = dir.Name;</li> <li style="background: #f3f3f3">            }</li> <li> </li> <li style="background: #f3f3f3">            <span style="color:#2b91af">FileInfo</span>[] files = dir.GetFiles();</li> <li>            <span style="color:#2b91af">List</span>&lt;<span style="color:#2b91af">DirectoryInfo</span>&gt; subdirs = <span style="color:#0000ff">new</span> <span style="color:#2b91af">List</span>&lt;<span style="color:#2b91af">DirectoryInfo</span>&gt;(dir.GetDirectories());</li> <li style="background: #f3f3f3">            <span style="color:#0000ff">for</span> (<span style="color:#0000ff">int</span> i = subdirs.Count - 1; i &gt;= 0; i--)</li> <li>            {</li> <li style="background: #f3f3f3">                <span style="color:#0000ff">if</span> (subdirs<em>.Name == <span style="color:#a31515">".svn"</span>)</em></li> <li>                {</li> <li style="background: #f3f3f3">                    subdirs.RemoveAt(i);</li> <li>                }</li> <li style="background: #f3f3f3">            }</li> <li>            </li> <li style="background: #f3f3f3">            <span style="color:#0000ff">if</span> (files.Length == 0 && subdirs.Count == 0)</li> <li>            {</li> <li style="background: #f3f3f3">                <span style="color:#2b91af">XmlNode</span> component = directory.AppendChild(doc.CreateElement(<span style="color:#a31515">"Component"</span>, wixns));</li> <li>                <span style="color:#0000ff">string</span> componentId = id.Replace(<span style="color:#a31515">".D"</span>, <span style="color:#a31515">"."</span>) + <span style="color:#a31515">"C"</span>;</li> <li style="background: #f3f3f3">                componentIds.Add(componentId);</li> <li>                component.Attributes.Append(doc.CreateAttribute(<span style="color:#a31515">"Id"</span>)).Value = MakeId(componentId);</li> <li style="background: #f3f3f3">                component.Attributes.Append(doc.CreateAttribute(<span style="color:#a31515">"Guid"</span>)).Value = <span style="color:#2b91af">Guid</span>.NewGuid().ToString();</li> <li>                component.AppendChild(doc.CreateElement(<span style="color:#a31515">"CreateFolder"</span>, wixns));</li> <li style="background: #f3f3f3">            }</li> <li>            <span style="color:#0000ff">else</span> <span style="color:#0000ff">if</span> (files.Length &gt; 0)</li> <li style="background: #f3f3f3">            {</li> <li>                <span style="color:#2b91af">XmlNode</span> component = directory.AppendChild(doc.CreateElement(<span style="color:#a31515">"Component"</span>, wixns));</li> <li style="background: #f3f3f3">                <span style="color:#0000ff">string</span> componentId = id.Replace(<span style="color:#a31515">".D"</span>, <span style="color:#a31515">"."</span>) + <span style="color:#a31515">"C"</span>;</li> <li>                componentIds.Add(componentId);</li> <li style="background: #f3f3f3">                component.Attributes.Append(doc.CreateAttribute(<span style="color:#a31515">"Id"</span>)).Value = MakeId(componentId);</li> <li>                component.Attributes.Append(doc.CreateAttribute(<span style="color:#a31515">"Guid"</span>)).Value = <span style="color:#2b91af">Guid</span>.NewGuid().ToString();</li> <li style="background: #f3f3f3">                <span style="color:#0000ff">foreach</span> (<span style="color:#2b91af">FileInfo</span> file <span style="color:#0000ff">in</span> files)</li> <li>                {</li> <li style="background: #f3f3f3">                    <span style="color:#2b91af">XmlNode</span> node = component.AppendChild(doc.CreateElement(<span style="color:#a31515">"File"</span>, wixns));</li> <li>                    node.Attributes.Append(doc.CreateAttribute(<span style="color:#a31515">"Id"</span>)).Value = MakeId(id.Replace(<span style="color:#a31515">".D"</span>, <span style="color:#a31515">"."</span>) + file.Name);</li> <li style="background: #f3f3f3">                    node.Attributes.Append(doc.CreateAttribute(<span style="color:#a31515">"Source"</span>)).Value =</li> <li>                        <span style="color:#a31515">"$(var."</span> + <span style="color:#2b91af">Path</span>.GetFileName(root.FullName) + <span style="color:#a31515">"Dir)\\"</span> + </li> <li style="background: #f3f3f3">                        file.FullName.Substring(root.FullName.Length).TrimStart(<span style="color:#a31515">'\\'</span>);</li> <li>                }</li> <li style="background: #f3f3f3">            }</li> <li> </li> <li style="background: #f3f3f3">            <span style="color:#0000ff">foreach</span> (<span style="color:#2b91af">DirectoryInfo</span> subdir <span style="color:#0000ff">in</span> subdirs)</li> <li>            {</li> <li style="background: #f3f3f3">                componentIds.AddRange(GenerateFragment(doc, directory, subdir, root));</li> <li>            }</li> <li style="background: #f3f3f3"> </li> <li>            <span style="color:#0000ff">return</span> componentIds;</li> <li style="background: #f3f3f3">        }</li> <li> </li> <li style="background: #f3f3f3">        <span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> Main(<span style="color:#0000ff">string</span>[] args)</li> <li>        {</li> <li style="background: #f3f3f3">            <span style="color:#0000ff">try</span></li> <li>            {</li> <li style="background: #f3f3f3">                <span style="color:#0000ff">if</span> (args.Length == 0)</li> <li>                {</li> <li style="background: #f3f3f3">                    <span style="color:#0000ff">throw</span> <span style="color:#0000ff">new</span> <span style="color:#2b91af">ArgumentException</span>(<span style="color:#a31515">"Missing dir"</span>);</li> <li>                }</li> <li style="background: #f3f3f3"> </li> <li>                <span style="color:#2b91af">XmlDocument</span> doc = <span style="color:#0000ff">new</span> <span style="color:#2b91af">XmlDocument</span>();</li> <li style="background: #f3f3f3">                doc.LoadXml(<span style="color:#a31515">"&lt;Include xmlns=\"http://schemas.microsoft.com/wix/2006/wi\" /&gt;"</span>);</li> <li>                <span style="color:#2b91af">DirectoryInfo</span> root = <span style="color:#0000ff">new</span> <span style="color:#2b91af">DirectoryInfo</span>(args[0]);</li> <li style="background: #f3f3f3">                <span style="color:#2b91af">List</span>&lt;<span style="color:#2b91af">String</span>&gt; componentIds = GenerateFragment(doc, doc.FirstChild, root, root);</li> <li>                <span style="color:#2b91af">XmlNode</span> featureRef = doc.FirstChild.AppendChild(doc.CreateElement(<span style="color:#a31515">"Feature"</span>, wixns));</li> <li style="background: #f3f3f3">                featureRef.Attributes.Append(doc.CreateAttribute(<span style="color:#a31515">"Id"</span>)).Value = MakeId(root.Name);</li> <li>                featureRef.Attributes.Append(doc.CreateAttribute(<span style="color:#a31515">"Level"</span>)).Value = <span style="color:#a31515">"1"</span>;</li> <li style="background: #f3f3f3">                featureRef.Attributes.Append(doc.CreateAttribute(<span style="color:#a31515">"Title"</span>)).Value = root.Name;</li> <li>                <span style="color:#0000ff">foreach</span> (<span style="color:#2b91af">String</span> componentId <span style="color:#0000ff">in</span> componentIds)</li> <li style="background: #f3f3f3">                {</li> <li>                    <span style="color:#2b91af">XmlNode</span> node = featureRef.AppendChild(doc.CreateElement(<span style="color:#a31515">"ComponentRef"</span>, wixns));</li> <li style="background: #f3f3f3">                    node.Attributes.Append(doc.CreateAttribute(<span style="color:#a31515">"Id"</span>)).Value = MakeId(componentId);</li> <li>                }</li> <li style="background: #f3f3f3">                <span style="color:#2b91af">Console</span>.WriteLine(doc.OuterXml);</li> <li>            }</li> <li style="background: #f3f3f3">            <span style="color:#0000ff">catch</span> (<span style="color:#2b91af">Exception</span> ex)</li> <li>            {</li> <li style="background: #f3f3f3">                <span style="color:#2b91af">Console</span>.WriteLine(<span style="color:#a31515">"ERROR: {0}"</span>, ex.Message);</li> <li>            }</li> <li style="background: #f3f3f3">        }</li> <li>    }</li> <li style="background: #f3f3f3">}</li> </ol> </div> </div> </div></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=97">Read</a></div></html>
         ]]>
       </description>
       <category>wix</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=97</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/97</guid>
      </item>
     
      <item>
       <title>JNDI: Naming and Directory Services with OpenDS</title>
       <pubDate>Tue, 13 Apr 2010 15:07:34 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p>I often hear from .NET programmers “I’d like to get into Java, not the language, but all that J2EE stuff …”. I am one of those people so I try to use any opportunity to try something I’ve never touched before.</p>  <p>We’re moving to a SOA model with the product at my <a href="http://www.appsecinc.com">day job</a>. One of the fundamental questions is: <em>“How does a service find another service?”.</em> The standard answer is to use a naming and directory service and in Java you talk to one of these things with <a href="http://java.sun.com/products/jndi/">JNDI</a>.</p>  <p>First, a few basics.</p>  <ul>   <li><strong>Naming service </strong>is a fundamental facility in any computing system. It’s the means by which names are associated with objects and objects are found based on their names. For example, to access a file on the computer you must provide its name.</li>    <li><strong>Directory Service</strong> is an extension of the naming services. A directory service associates names with objects and also allows such objects to have <em>attributes</em>. Thus, you not only can look up an object by its name but also get the object's attributes or search for the object based on its attributes.</li> </ul>  <p>By using a directory service, you can simplify applications and their administration by centralizing the storage of shared information. For our purposes such information includes SOAP service URIs. For example, you can find demoService (a previously agreed-upon name of the demo service) at <a href="http://localhost:20080/demo">http://localhost:20080/demo</a>. </p>  <p><strong>Client & Server</strong></p>  <p>I picked up <a href="http://www.opends.org/">OpenDS</a>, on open-source server from Sun. After a straightforward installation (set <em>OPENDS_JAVA_HOME</em> to a JRE location and run <em>setup.bat</em>) I had an LDAP server running as a Windows Service (OpenDS) on port 389. There’s a handy <em>bat\control-panel.bat</em> that launches a schema and object browser.</p>  <p>We can now access this server with JNDI, which comes standard with Java Platform 1.1.2 or later.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li>Hashtable&lt;String, String&gt; env = <span style="color:#0000ff">new</span> Hashtable&lt;String, String&gt;();</li> <li style="background: #f3f3f3">env.put(Context.INITIAL_CONTEXT_FACTORY, <span style="color:#a31515">"com.sun.jndi.ldap.LdapCtxFactory"</span>);</li> <li>env.put(Context.PROVIDER_URL, <span style="color:#a31515">"ldap://localhost:389/dc=example,dc=com"</span>);</li> <li style="background: #f3f3f3">env.put(Context.SECURITY_AUTHENTICATION, <span style="color:#a31515">"simple"</span>);</li> <li>env.put(Context.SECURITY_PRINCIPAL, <span style="color:#a31515">"cn=Directory Manager"</span>);</li> <li style="background: #f3f3f3">env.put(Context.SECURITY_CREDENTIALS, <span style="color:#a31515">"password"</span>);</li> <li>DirContext ctx = <span style="color:#0000ff">new</span> InitialDirContext(env);</li> <li style="background: #f3f3f3">Attributes attrs = ctx.getAttributes(<span style="color:#a31515">""</span>);</li> <li>NamingEnumeration&lt;? extends Attribute&gt; e = attrs.getAll();</li> <li style="background: #f3f3f3"><span style="color:#0000ff">while</span>(e.hasMore()) {</li> <li>    System.out.println(e.next());</li> <li style="background: #f3f3f3">}</li> <li>ctx.close();</li> </ol> </div> </div> </div>   <p>This outputs the attributes of my initial domain context that was created at setup time.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li>dc: appsecinc </li> <li style="background: #f3f3f3">objectClass: domain, top</li> </ol> </div> </div> </div>   <p><strong>The Goal</strong></p>  <p>Let’s create a directory for our SOAP services. The goal is to be able to store a collection of service objects, each containing a well-defined URL and retrieve service URLs using the service names.</p>  <p><strong>Extending the Schema</strong></p>  <p>The OpenDS schema is stored in .ldif files in the config\schema directory. The directory schema can be extended by importing LDIF files, modifying those in the schema directory or programmatically with JNDI. I’ll write an import an .ldif file.</p>  <p>There’re several RFCs with various well-known attribute types, such as <em>name</em> or <em>uid</em>. We’re only missing <em>serviceUri</em>, which we can define as a custom attribute.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li>attributeTypes: ( 1.2.840.113556.1.8000.2554.999999.1 NAME <span style="color:#a31515">'serviceUri'</span> </li> <li style="background: #f3f3f3">    DESC <span style="color:#a31515">'service URI'</span> EQUALITY caseIgnoreMatch ORDERING caseIgnoreOrderingMatch </li> <li>    SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )</li> </ol> </div> </div> </div>   <p>Our <em>Service</em> type is defined as follows: an object with a common name (cn), a humanly readable name (name), an object class (Service), a unique identifier (uid) and an url to the service (serviceUri).</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li>objectClasses: ( 1.2.840.113556.1.8000.2554.999999.2 NAME <span style="color:#a31515">'Service'</span> </li> <li style="background: #f3f3f3">    DESC <span style="color:#a31515">'a SOAP Service'</span> SUP top </li> <li>    STRUCTURAL MUST ( cn $ name $ objectClass $ uid $ serviceUri ) )</li> </ol> </div> </div> </div>   <p><strong>OIDs</strong></p>  <p>You can generate a root OID using <a href="http://msdn.microsoft.com/en-us/library/ms677620.aspx">this script</a> (save the script to disk and run <em>cscript script.vbs</em>) and keep adding numbers to it. It’s just a globally unique number that identifies an attribute or a class. I generated OID 1.2.840.113556.1.8000.2554.999999.</p>  <p><strong>Service in Java </strong></p>  <p>Lets define a Service Java class that can be used to read and write objects to the directory.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li>package com.example.jndi;</li> <li style="background: #f3f3f3"> </li> <li>import javax.naming.NameNotFoundException;</li> <li style="background: #f3f3f3">import javax.naming.NamingException;</li> <li>import javax.naming.directory.Attribute;</li> <li style="background: #f3f3f3">import javax.naming.directory.Attributes;</li> <li>import javax.naming.directory.BasicAttribute;</li> <li style="background: #f3f3f3">import javax.naming.directory.BasicAttributes;</li> <li> </li> <li style="background: #f3f3f3"><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> Service extends UnimplementedDirContext {</li> <li>    String _name;</li> <li style="background: #f3f3f3">    String _serviceUri;</li> <li>    String _uid;</li> <li style="background: #f3f3f3">    </li> <li>    <span style="color:#0000ff">public</span> Service(String uid, String name, String uri) {        </li> <li style="background: #f3f3f3">        _uid = uid;</li> <li>        _name = name;</li> <li style="background: #f3f3f3">        _serviceUri = uri;        </li> <li>    }</li> <li style="background: #f3f3f3">    </li> <li>    <span style="color:#0000ff">public</span> Service(Attributes inAttrs) {</li> <li style="background: #f3f3f3">        _name = inAttrs.get(<span style="color:#a31515">"name"</span>).toString();</li> <li>        _serviceUri = inAttrs.get(<span style="color:#a31515">"serviceUri"</span>).toString();</li> <li style="background: #f3f3f3">        _uid = inAttrs.get(<span style="color:#a31515">"uid"</span>).toString();</li> <li>    }</li> <li style="background: #f3f3f3">    </li> <li>    @Override</li> <li style="background: #f3f3f3">    <span style="color:#0000ff">public</span> Attributes getAttributes(String name) throws NamingException {</li> <li>        <span style="color:#0000ff">if</span> (! name.equals(<span style="color:#a31515">""</span>)) {</li> <li style="background: #f3f3f3">            <span style="color:#0000ff">throw</span> <span style="color:#0000ff">new</span> NameNotFoundException();</li> <li>        }</li> <li style="background: #f3f3f3"> </li> <li>        Attributes attrs = <span style="color:#0000ff">new</span> BasicAttributes(<span style="color:#0000ff">true</span>);  <span style="color:#008000">// Case ignore</span></li> <li style="background: #f3f3f3">        Attribute oc = <span style="color:#0000ff">new</span> BasicAttribute(<span style="color:#a31515">"objectclass"</span>);</li> <li>        oc.add(<span style="color:#a31515">"extensibleObject"</span>);</li> <li style="background: #f3f3f3">        oc.add(<span style="color:#a31515">"top"</span>);</li> <li>        attrs.put(oc);</li> <li style="background: #f3f3f3">        attrs.put(<span style="color:#a31515">"objectclass"</span>, <span style="color:#a31515">"Service"</span>);</li> <li>        attrs.put(<span style="color:#a31515">"name"</span>, _name);</li> <li style="background: #f3f3f3">        attrs.put(<span style="color:#a31515">"uid"</span>, _uid);</li> <li>        attrs.put(<span style="color:#a31515">"serviceUri"</span>, _serviceUri);</li> <li style="background: #f3f3f3">        <span style="color:#0000ff">return</span> attrs;</li> <li>    }</li> <li style="background: #f3f3f3"> </li> <li>    <span style="color:#0000ff">public</span> String toString() {</li> <li style="background: #f3f3f3">        <span style="color:#0000ff">return</span> _name + <span style="color:#a31515">" @ "</span> + _serviceUri;</li> <li>    }</li> <li style="background: #f3f3f3">}</li> </ol> </div> </div> </div>   <p>This is a simple container for attributes. The UnimplementedDirContext is an empty class that throws NotImplementedException on two dozen methods that are required by a full DirContext.</p>  <p><strong>A Services Organization</strong></p>  <p>We’d like to organize services under a Services organization. I’ve created that manually in the directory. The full directory path to the OU is <em>o=Services,dc=example,dc=com</em>.</p>  <p><strong>Writing to the Directory</strong></p>  <p>A write is a call to <em>bind</em>. Binding means connecting a <em>name</em> to an <em>object</em>. You can <em>rebind</em>, ie. either create or update an existing object.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li>Service demoService = <span style="color:#0000ff">new</span> Service(</li> <li style="background: #f3f3f3">        <span style="color:#a31515">"{F6E978E7-A0BC-47ae-95A9-219CD40C5993}"</span>, </li> <li>        <span style="color:#a31515">"demoService"</span>, </li> <li style="background: #f3f3f3">        <span style="color:#a31515">"http://localhost:20080/demo/"</span>);</li> <li>ctx.rebind(<span style="color:#a31515">"cn=demoService,o=Services"</span>, demoService);</li> </ol> </div> </div> </div>   <p>Here’s what we have in the directory now (this is the <em>Manage Entries</em> UI from the control panel tool that comes with OpenDS).</p>  <p><a href="http://code.dblock.org/ShowPicture.aspx?id=35&ShowThumbnail=false"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://code.dblock.org/ShowPicture.aspx?id=36&ShowThumbnail=false" width="642" height="324" /></a> </p>  <p><strong>Retrieving from the Directory</strong></p>  <p>In order to retrieve a strongly typed object from the directory we must supply an object factory. When the factory encounters an object with an <em>objectClass=Service</em>, it will create an instance of such.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li>package com.example.jndi;</li> <li style="background: #f3f3f3"> </li> <li>import javax.naming.*;</li> <li style="background: #f3f3f3">import javax.naming.directory.*;</li> <li>import javax.naming.spi.DirObjectFactory;</li> <li style="background: #f3f3f3">import java.util.Hashtable;</li> <li> </li> <li style="background: #f3f3f3"><span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> ServiceFactory implements DirObjectFactory {</li> <li>    </li> <li style="background: #f3f3f3">    <span style="color:#0000ff">public</span> ServiceFactory() {</li> <li>        </li> <li style="background: #f3f3f3">    }</li> <li> </li> <li style="background: #f3f3f3">    <span style="color:#0000ff">public</span> Object getObjectInstance(Object obj, Name name, Context ctx, </li> <li>            Hashtable&lt;?, ?&gt; env, Attributes inAttrs) throws Exception {</li> <li style="background: #f3f3f3"> </li> <li>        <span style="color:#0000ff">if</span> (obj instanceof DirContext) {</li> <li style="background: #f3f3f3">            Attribute objectClass = inAttrs.get(<span style="color:#a31515">"objectClass"</span>);</li> <li>            NamingEnumeration&lt;?&gt; ne = objectClass.getAll();</li> <li style="background: #f3f3f3">            <span style="color:#0000ff">while</span>(ne.hasMore()) {</li> <li>                <span style="color:#0000ff">if</span> (ne.next().equals(<span style="color:#a31515">"Service"</span>)) {</li> <li style="background: #f3f3f3">                    <span style="color:#0000ff">return</span> <span style="color:#0000ff">new</span> Service(inAttrs);                    </li> <li>                }</li> <li style="background: #f3f3f3">            }</li> <li>        }</li> <li style="background: #f3f3f3">        </li> <li>        <span style="color:#0000ff">return</span> null;</li> <li style="background: #f3f3f3">    }</li> <li> </li> <li style="background: #f3f3f3">    <span style="color:#0000ff">public</span> Object getObjectInstance(Object obj, Name name, Context ctx, Hashtable&lt;?, ?&gt; env) throws Exception {</li> <li>        <span style="color:#0000ff">return</span> getObjectInstance(obj, name, ctx, env, null);</li> <li style="background: #f3f3f3">    }</li> <li>}</li> </ol> </div> </div> </div>   <p>The initial directory context must be told to use this factory.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li>env.put(Context.OBJECT_FACTORIES, <span style="color:#a31515">"com.example.jndi.ServiceFactory"</span>);</li> </ol> </div> </div> </div>   <p>Finally, the retrieval becomes a simple lookup.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li>Service demoService = (Service) ctx.lookup(<span style="color:#a31515">"cn=demoService,o=Services"</span>);</li> </ol> </div> </div> </div>   <p><strong>Deleting Directory Objects</strong></p>  <p>To complete the picture, lets delete a directory object. This is the opposite of <em>bind</em>, <em>unbind</em>.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li>ctx.unbind(<span style="color:#a31515">"cn=demoService,o=Services"</span>);</li> </ol> </div> </div> </div>   <p><strong>A Word on XML</strong></p>  <p>All this requires server-side Java code and keeping the LDAP port 389 open.</p>  <p>Alternatively, OpenDS provides an implementation of Directory Services Markup Language (DSML), an XML API to directory services. It’s then possible to switch JNDI client code from LDAP to DSML using <a href="http://java.sun.com/developer/earlyAccess/jndi/">a Sun early access JNDI client for DSML</a>.</p>  <p><strong>Links</strong></p>  <ul>   <li><a href="http://java.sun.com/products/jndi/tutorial/TOC.html">Naming and Directory Services Tutorial</a> </li>    <li><a href="http://www.opends.org/">OpenDS Directory Server</a> </li>    <li><a href="http://svn.vestris.com/listing.php?repname=Vestris+SVN&path=%2Fcodeproject%2FJndiDemo%2F#path_codeproject_JndiDemo_">Source Code for this Article</a></li>    <ul>     <li><a href="http://svn.vestris.com/filedetails.php?repname=Vestris+SVN&path=%2Fcodeproject%2FJndiDemo%2Fsrc%2Fcom%2Fexample%2Fjndi%2FService.java">Service.java</a></li>      <li><a href="http://svn.vestris.com/filedetails.php?repname=Vestris+SVN&path=%2Fcodeproject%2FJndiDemo%2Fsrc%2Fcom%2Fexample%2Fjndi%2FUnimplementedDirContext.java">UnimplementedDirContext.java</a></li>      <li><a href="http://svn.vestris.com/filedetails.php?repname=Vestris+SVN&path=%2Fcodeproject%2FJndiDemo%2Fsrc%2Fcom%2Fexample%2Fjndi%2FServiceFactory.java">ServiceFactory.java</a></li>   </ul> </ul></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=96">Read</a></div></html>
         ]]>
       </description>
       <category>soa</category><category>jndi</category><category>java</category><category>active directory</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=96</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/96</guid>
      </item>
     
      <item>
       <title>Pure Java Waffle</title>
       <pubDate>Thu, 08 Apr 2010 12:53:46 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p><a href="http://waffle.codeplex.com/"><img align="absMiddle" src="http://download.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=waffle&DownloadId=108853&Build=16429" /></a></p>  <p>I finally got to porting <a href="http://waffle.codeplex.com/">Waffle</a> to pure java with <a href="https://jna.dev.java.net/">JNA</a>. This means you don’t need .NET framework or COM to call Waffle from Java. It’s pure java.</p>  <p>Waffle is a thin interface that simplifies Windows authentication and authorization, therefore providing a practical and workable back-end for NTLM, Negotiate, Kerberos and other <a href="http://en.wikipedia.org/wiki/SPNEGO">SPNEGOs</a>. Here’re some scenarios that you can now do without any headache directly in Java.</p>  <p><strong>Logon a user: get his local and domain groups</strong></p>  <p>This calls Win32 LogonUser, examines the user token and extracts all local and domain group memberships from it. This obviously includes nested groups. For more details of how this is implemented in JNA see <a href="http://code.dblock.org/ShowPost.aspx?id=89">this earlier post</a>.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li>IWindowsAuthProvider prov = <span style="color:#0000ff">new</span> WindowsAuthProviderImpl();</li> <li style="background: #f3f3f3">IWindowsIdentity identity = prov.logonUser(<span style="color:#a31515">"username"</span>, <span style="color:#a31515">"password"</span>);</li> <li>System.out.println(<span style="color:#a31515">"User identity: "</span> + identity.getFqn());</li> <li style="background: #f3f3f3"><span style="color:#0000ff">for</span>(IWindowsAccount group : identity.getGroups()) {</li> <li>    System.out.println(<span style="color:#a31515">" "</span> + group.getFqn() + <span style="color:#a31515">" ("</span> + group.getSidString() + <span style="color:#a31515">")"</span>);</li> <li style="background: #f3f3f3">}</li> </ol> </div> </div> </div>   <p>Here’re the first lines of output for my current user:</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li>User identity: dblock-green\dblock</li> <li style="background: #f3f3f3"> dblock-green\None (S-1-5-21-3442045183-1395134217-4167419351-513)</li> <li> Everyone (S-1-1-0)</li> <li style="background: #f3f3f3"> dblock-green\HomeUsers (S-1-5-21-3442045183-1395134217-4167419351-2418)</li> <li> BUILTIN\Administrators (S-1-5-32-544)</li> <li style="background: #f3f3f3"> BUILTIN\Users (S-1-5-32-545)</li> <li> NT AUTHORITY\NETWORK (S-1-5-2)</li> </ol> </div> </div> </div>   <p><strong>Active directory: get the list of trusted domains</strong></p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li>IWindowsAuthProvider prov = <span style="color:#0000ff">new</span> WindowsAuthProviderImpl();</li> <li style="background: #f3f3f3">IWindowsDomain[] domains = prov.getDomains();</li> <li><span style="color:#0000ff">for</span>(IWindowsDomain domain : domains) {</li> <li style="background: #f3f3f3">    System.out.println(domain.getFqn() + <span style="color:#a31515">": "</span> + domain.getTrustDirectionString());</li> <li>}</li> </ol> </div> </div> </div>   <p>The typical scenario is presenting a dropdown in front of the user to choose domains he can logon to. This list includes the current domain and all domain trusts.</p>  <p><strong>Active directory: is this computer joined to a domain?</strong></p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li>IWindowsAuthProvider prov = <span style="color:#0000ff">new</span> WindowsAuthProviderImpl();</li> <li style="background: #f3f3f3">IWindowsComputer computer = prov.getCurrentComputer();</li> <li>System.out.println(computer.getComputerName());</li> <li style="background: #f3f3f3">System.out.println(computer.getJoinStatus());</li> <li>System.out.println(computer.getMemberOf());</li> </ol> </div> </div> </div>   <p>For systems that run both with and without active directory you need to programmatically figure out whether a computer is joined to a domain or a workgroup. If it’s joined to a domain or a workgroup you want to know what domain the computer is joined to.</p>  <p><strong>Local machine: enumerate local groups</strong></p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li>IWindowsAuthProvider prov = <span style="color:#0000ff">new</span> WindowsAuthProviderImpl();</li> <li style="background: #f3f3f3">IWindowsComputer computer = prov.getCurrentComputer();</li> <li>String[] localGroups = computer.getGroups();</li> <li style="background: #f3f3f3"><span style="color:#0000ff">for</span>(String localGroup : localGroups) {</li> <li>    System.out.println(<span style="color:#a31515">" "</span> + localGroup);</li> <li style="background: #f3f3f3">}</li> </ol> </div> </div> </div>   <p><strong>Negotiate: single sign-on</strong></p>  <p>This is the sweetest waffle, both the client and the server-side of the Negotiate protocol made super easy. You would typically split this code in two halves and do the work of transmitting the tokens between client and server. In the end, the user is logged on to the server side and you can examine his local and domain groups.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li>String securityPackage = <span style="color:#a31515">"Negotiate"</span>;</li> <li style="background: #f3f3f3"><span style="color:#008000">// client credentials handle</span></li> <li>IWindowsCredentialsHandle clientCredentials = WindowsCredentialsHandleImpl.getCurrent(</li> <li style="background: #f3f3f3">        securityPackage);</li> <li>clientCredentials.initialize();</li> <li style="background: #f3f3f3"><span style="color:#008000">// initial client security context</span></li> <li>WindowsSecurityContextImpl clientContext = <span style="color:#0000ff">new</span> WindowsSecurityContextImpl();</li> <li style="background: #f3f3f3">clientContext.setPrincipalName(Advapi32Util.getUserName());</li> <li>clientContext.setCredentialsHandle(clientCredentials.getHandle());</li> <li style="background: #f3f3f3">clientContext.setSecurityPackage(securityPackage);</li> <li>clientContext.initialize();</li> <li style="background: #f3f3f3"><span style="color:#008000">// accept on the server</span></li> <li>WindowsAuthProviderImpl provider = <span style="color:#0000ff">new</span> WindowsAuthProviderImpl();</li> <li style="background: #f3f3f3">IWindowsSecurityContext serverContext = null;</li> <li><span style="color:#0000ff">do</span></li> <li style="background: #f3f3f3">{            </li> <li>    <span style="color:#0000ff">if</span> (serverContext != null) {</li> <li style="background: #f3f3f3">        <span style="color:#008000">// initialize on the client</span></li> <li>        SecBufferDesc continueToken = <span style="color:#0000ff">new</span> SecBufferDesc(Sspi.SECBUFFER_TOKEN, serverContext.getToken());</li> <li style="background: #f3f3f3">        clientContext.initialize(clientContext.getHandle(), continueToken);</li> <li>    }    </li> <li style="background: #f3f3f3">    <span style="color:#008000">// accept the token on the server</span></li> <li>    serverContext = provider.acceptSecurityToken(clientContext.getToken(), securityPackage);</li> <li style="background: #f3f3f3">} <span style="color:#0000ff">while</span> (clientContext.getContinue() || serverContext.getContinue());</li> <li> </li> <li style="background: #f3f3f3">System.out.println(serverContext.getIdentity().getFqn());</li> <li><span style="color:#0000ff">for</span> (IWindowsAccount group : serverContext.getIdentity().getGroups()) {</li> <li style="background: #f3f3f3">    System.out.println(<span style="color:#a31515">" "</span> + group.getFqn());</li> <li>}            </li> <li style="background: #f3f3f3"> </li> <li>serverContext.dispose();</li> <li style="background: #f3f3f3">clientContext.dispose();</li> <li>clientCredentials.dispose();</li> </ol> </div> </div> </div>   <p><strong>Integration and Download</strong></p>  <p>Waffle now has the same (or very similar) interface in C#, COM, Jacob and pure Java. So you can use it in a variety of applications. For COM we supply a merge module for your installer. For C#, reference <strong>Waffle.Windows.AuthProvider.dll</strong>. For Java, reference <strong>waffle-jna-auth.jar</strong> and include jna.jar and platform.jar in your distribution.</p>  <ul>   <li><a href="http://waffle.codeplex.com/releases/view/43113">Download Waffle 1.3</a></li> </ul></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=95">Read</a></div></html>
         ]]>
       </description>
       <category>waffle</category><category>jna</category><category>security</category><category>java</category><category>active directory</category><category>win32</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=95</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/95</guid>
      </item>
     
      <item>
       <title>dotNetInstaller 1.9 Released</title>
       <pubDate>Mon, 05 Apr 2010 11:43:26 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p><a href="http://dotnetinstaller.codeplex.com/releases/view/39966"><img align="absMiddle" src="http://download.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=dotnetinstaller&DownloadId=94426&Build=16429" /></a></p>  <p>dotNetInstaller 1.9 was released today, April 5th, 2010.</p>  <p>Features include support for windows patch installers (.msp), many improvements to uninstall support, improved registry checks and registry variable substitutions, improvements in CABing performance and reliability and numerous bug fixes. <a href="http://dotnetinstaller.codeplex.com/releases/view/39966">Download build 1.9.5931.0</a>.</p></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=94">Read</a></div></html>
         ]]>
       </description>
       <category>dotnetinstaller</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=94</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/94</guid>
      </item>
     
      <item>
       <title>JNA: Working with Unions</title>
       <pubDate>Fri, 02 Apr 2010 17:23:29 GMT</pubDate>
       <description>
         <![CDATA[
          <link rel="stylesheet" href='http://code.dblock.org/Style.css' />
          <html><div><stripped><p><strong>The Grey Rat</strong></p>  <p>There’s a giant grey rat outside of my window and a bunch of non-union workers laboring in the rain. The union guy who’s guarding the rat and giving away flyers got too cold and went inside the building. But I digress, the post is about working with Unions in <a href="https://jna.dev.java.net/">Java Native Access (JNA).</a></p>  <p><strong>Preamble</strong></p>  <p>I was trying to retrieve Active Directory forest trust information via <a href="http://msdn.microsoft.com/en-us/library/ms675988(VS.85).aspx">DsGetForestTrustInformationW</a>. The function takes a pointer to a <a href="http://msdn.microsoft.com/en-us/library/aa378335(VS.85).aspx">PLSA_FOREST_TRUST_INFORMATION</a>, a pointer to a pointer to an <a href="http://msdn.microsoft.com/en-us/library/aa378335(VS.85).aspx">LSA_FOREST_TRUST_INFORMATION</a> structure. So far so good, we just need to pay attention to the several levels of indirection: whenever we want the value of a pointer to something, it’s a ByReference.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li><span style="color:#0000ff">public</span> <span style="color:#0000ff">int</span> DsGetForestTrustInformation(String serverName, String trustedDomainName, <span style="color:#0000ff">int</span> Flags, </li> <li style="background: #f3f3f3">        PLSA_FOREST_TRUST_INFORMATION.ByReference ForestTrustInfo);</li> </ol> </div> </div> </div>   <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li><span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">class</span> PLSA_FOREST_TRUST_INFORMATION extends Structure {        </li> <li style="background: #f3f3f3">    <span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">class</span> ByReference extends PLSA_FOREST_TRUST_INFORMATION </li> <li>        implements Structure.ByReference {        </li> <li style="background: #f3f3f3">    }</li> <li>    <span style="color:#0000ff">public</span> LSA_FOREST_TRUST_INFORMATION.ByReference fti;        </li> <li style="background: #f3f3f3">}</li> </ol> </div> </div> </div>   <p></p>  <p><a href="http://msdn.microsoft.com/en-us/library/aa378335(VS.85).aspx">LSA_FOREST_TRUST_INFORMATION</a> is a structure that contains a RecordCount number of <a href="http://msdn.microsoft.com/en-us/library/aa378336(v=VS.85).aspx">PLSA_FOREST_TRUST_RECORD</a> items. Those are pointers, so Entries is an array of pointers. Since we want the value of a pointer, we use ByReference again.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li><span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">class</span> LSA_FOREST_TRUST_INFORMATION extends Structure {</li> <li style="background: #f3f3f3">    <span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">class</span> ByReference extends LSA_FOREST_TRUST_INFORMATION </li> <li>        implements Structure.ByReference {            </li> <li style="background: #f3f3f3">    }</li> <li> </li> <li style="background: #f3f3f3">    <span style="color:#0000ff">public</span> NativeLong RecordCount;</li> <li>    <span style="color:#0000ff">public</span> PLSA_FOREST_TRUST_RECORD.ByReference Entries;</li> <li style="background: #f3f3f3">    <span style="color:#0000ff">public</span> PLSA_FOREST_TRUST_RECORD[] getEntries() {</li> <li>        <span style="color:#0000ff">return</span> (PLSA_FOREST_TRUST_RECORD[]) Entries.toArray(RecordCount.intValue());</li> <li style="background: #f3f3f3">    }</li> <li>}</li> </ol> </div> </div> </div>   <p>A pointer to a record is simply a structure that contains a pointer to the record.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li><span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">class</span> PLSA_FOREST_TRUST_RECORD extends Structure {</li> <li style="background: #f3f3f3">    <span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">class</span> ByReference extends PLSA_FOREST_TRUST_RECORD </li> <li>        implements Structure.ByReference {            </li> <li style="background: #f3f3f3">    }    </li> <li>    <span style="color:#0000ff">public</span> LSA_FOREST_TRUST_RECORD.ByReference tr;    </li> <li style="background: #f3f3f3">}</li> </ol> </div> </div> </div>   <p><strong>Union inside a Structure?</strong></p>  <p>Still with me? The record is declared like this:</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li><span style="color:#0000ff">typedef</span> <span style="color:#0000ff">struct</span> _LSA_FOREST_TRUST_RECORD {</li> <li style="background: #f3f3f3">    ULONG Flags;</li> <li>    LSA_FOREST_TRUST_RECORD_TYPE ForestTrustType; <span style="color:#008000">// type of record</span></li> <li style="background: #f3f3f3">    LARGE_INTEGER Time;</li> <li>    <span style="color:#0000ff">union</span> { <span style="color:#008000">// actual data</span></li> <li style="background: #f3f3f3">        LSA_UNICODE_STRING TopLevelName;</li> <li>        LSA_FOREST_TRUST_DOMAIN_INFO DomainInfo;</li> <li style="background: #f3f3f3">        LSA_FOREST_TRUST_BINARY_DATA Data; <span style="color:#008000">// used for unrecognized types</span></li> <li>    } ForestTrustData;</li> <li style="background: #f3f3f3">} LSA_FOREST_TRUST_RECORD;</li> </ol> </div> </div> </div>   <p>Note that MSDN has a mistake <a href="http://msdn.microsoft.com/en-us/library/aa378336(VS.85).aspx">here</a>, missing the Time field, which gave me lots of headache and wasted hours of my time. Got to use definitions in platform SDK.</p>  <p>This is a union. How do you declare this in JNA?</p>  <p>A union is just like a structure, except that every field lives at an offset zero. In JNA, you must tell the union which field to use before reading the value.</p>  <p>   </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #fff; overflow: auto"> <ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;"> <li><span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">class</span> LSA_FOREST_TRUST_RECORD extends Structure {    </li> <li style="background: #f3f3f3">    <span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">class</span> ByReference extends LSA_FOREST_TRUST_RECORD </li> <li>        implements Structure.ByReference {</li> <li style="background: #f3f3f3">    }</li> <li>    <span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">class</span> UNION extends Union {</li> <li style="background: #f3f3f3">        <span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">class</span> ByReference extends UNION </li> <li>            implements Structure.ByReference {</li> <li style="background: #f3f3f3">        }</li> <li>        <span style="color:#0000ff">public</span> LSA_UNICODE_STRING TopLevelName;</li> <li style="background: #f3f3f3">        <span style="color:#0000ff">public</span> LSA_FOREST_TRUST_DOMAIN_INFO DomainInfo;</li> <li>        <span style="color:#0000ff">public</span> LSA_FOREST_TRUST_BINARY_DATA Data;</li> <li style="background: #f3f3f3">    }</li> <li>    <span style="color:#0000ff">public</span> NativeLong Flags;</li> <li style="background: #f3f3f3">    <span style="color:#0000ff">public</span> <span style="color:#0000ff">int</span> ForestTrustType;</li> <li>    <span style="color:#0000ff">public</span> LARGE_INTEGER Time;    </li> <li style="background: #f3f3f3">    <span style="color:#0000ff">public</span> UNION u;    </li> <li>    <span style="color:#0000ff">public</span> <span style="color:#0000ff">void</span> read() {</li> <li style="background: #f3f3f3">        super.read();        </li> <li>        <span style="color:#0000ff">switch</span>(ForestTrustType) {</li> <li style="background: #f3f3f3">        <span style="color:#0000ff">case</span> NTSecApi.ForestTrustTopLevelName:</li> <li>        <span style="color:#0000ff">case</span> NTSecApi.ForestTrustTopLevelNameEx:</li> <li style="background: #f3f3f3">            u.setType(LSA_UNICODE_STRING.<span style="color:#0000ff">class</span>);</li> <li>            <span style="color:#0000ff">break</span>;</li> <li style="background: #f3f3f3">        <span style="color:#0000ff">case</span> NTSecApi.ForestTrustDomainInfo:</li> <li>            u.setType(LSA_FOREST_TRUST_DOMAIN_INFO.<span style="color:#0000ff">class</span>);</li> <li style="background: #f3f3f3">            <span style="color:#0000ff">break</span>;</li> <li>        <span style="color:#0000ff">default</span>:</li> <li style="background: #f3f3f3">            u.setType(LSA_FOREST_TRUST_BINARY_DATA.<span style="color:#0000ff">class</span>);</li> <li>            <span style="color:#0000ff">break</span>;</li> <li style="background: #f3f3f3">        }        </li> <li>        u.read();</li> <li style="background: #f3f3f3">    }</li> <li>}</li> </ol> </div> </div> </div>   <p></p>  <p>In our case we override read() and set the type depending on the ForestTrustType value. Then re-read the union from memory. Voila.</p>  <p><strong>Notes</strong></p>  <p>Committed to JNA under <em>com.sun.jna.platform.win32</em> in rev. 1060.</p></stripped></div><div><a href="http://code.dblock.org/ShowPost.aspx?id=93">Read</a></div></html>
         ]]>
       </description>
       <category>jna</category><category>java</category><category>active directory</category><category>win32</category>
       <link>http://code.dblock.org/ShowPost.aspx?Id=93</link>
       <guid isPermaLink="false">http://code.dblock.org/Post/93</guid>
      </item>
         
  </channel>
</rss>
