<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>David Valeri&#039;s Blog</title>
	<atom:link href="http://davidvaleri.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidvaleri.wordpress.com</link>
	<description>Adventures in SOA, middleware, and open-source</description>
	<lastBuildDate>Mon, 23 Jan 2012 23:26:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='davidvaleri.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>David Valeri&#039;s Blog</title>
		<link>http://davidvaleri.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://davidvaleri.wordpress.com/osd.xml" title="David Valeri&#039;s Blog" />
	<atom:link rel='hub' href='http://davidvaleri.wordpress.com/?pushpress=hub'/>
		<item>
		<title>How I learned to stop worrying and love OS X Lion for Java development</title>
		<link>http://davidvaleri.wordpress.com/2011/09/29/how-i-learned-to-stop-worrying-and-love-os-x-lion-for-java-development/</link>
		<comments>http://davidvaleri.wordpress.com/2011/09/29/how-i-learned-to-stop-worrying-and-love-os-x-lion-for-java-development/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 13:40:29 +0000</pubDate>
		<dc:creator>David Valeri</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://davidvaleri.wordpress.com/?p=224</guid>
		<description><![CDATA[I&#8217;ve been humming along using OS X 10.6 for the better part of a year now. For the most part, the tool suite I identified in my earlier post has served me well.  Having just released a major project for &#8230; <a href="http://davidvaleri.wordpress.com/2011/09/29/how-i-learned-to-stop-worrying-and-love-os-x-lion-for-java-development/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvaleri.wordpress.com&amp;blog=15062177&amp;post=224&amp;subd=davidvaleri&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been humming along using OS X 10.6 for the better part of a year now. For the most part, the tool suite I identified in my <a title="How I learned to stop worrying and love OS X for Java development" href="http://davidvaleri.wordpress.com/2010/12/23/how-i-learned-to-stop-worrying-and-love-os-x-for-java-development/" target="_blank">earlier post</a> has served me well.  Having just released a major project for a client, I decided now would be a good time to upgrade to OS X Lion.  Considering that I am months behind the curve, I figured it would be simple and that any issues would already have been addressed by the blogosphere.  <del datetime="2011-10-06T19:57:29+00:00">Everything went well except for getting a JDK with with source code and JavaDocs.  This post describes how to get a JDK installation with source and JavaDoc after the upgrade or a clean install.</del> Everything went well except for a couple issues. This post describes the issues I encountered with my environment.<span id="more-224"></span></p>
<h1>JDK Repair</h1>
<p>The upgrade process kindly removed all of my previously installed JDKs under /Library/Java/JavaVirtualMachines.  This deletion had the added benefit of messing up my installed JVMs in Eclipse.  Since the built-in JVM does not contain source code, I had to reinstall the developer package for the JDK.   After a little venting about the intelligence of the engineer who made that decision, I was off to connect.apple.com to look for the OS X 10.7 JDK installer.  Luckily the fix is the same as the process I described in the <em>Installing the JDK</em> and the <em>Looking at the JDK files</em> sections my <a title="How I learned to stop worrying and love OS X for Java development" href="http://davidvaleri.wordpress.com/2010/12/23/how-i-learned-to-stop-worrying-and-love-os-x-for-java-development/" target="_blank">earlier post</a>, and I was up and running without too much additional frustration.</p>
<p>One thing of note is that the JDK installers did not appear in the download list when I first logged in, even after using the site&#8217;s search feature.  If you find yourself in a similar position, the direct download link for the &#8220;Java for Mac OS X 10.7 Developer Package&#8221; installer as of the publishing of this post is <a href="https://developer.apple.com/downloads/download.action?path=Java/java_for_mac_os_x_10.7_developer_package/javadeveloper_for_mac_os_x_10.7__11a511.dmg" target="_blank">https://developer.apple.com/downloads/download.action?path=Java/java_for_mac_os_x_10.7_developer_package/javadeveloper_for_mac_os_x_10.7__11a511.dmg</a></p>
<h1>Insomia X</h1>
<p>The upgrade breaks InsomniaX.  For me it would still start, but it would not prevent the laptop from going to sleep.  <a href="http://semaja2.net/archives/206" target="_blank">InsomniaX 2.0</a> adds Lion support.</p>
<h1>Git</h1>
<p>It looks like the upgrade may have also removed a symbolic link to my Git installation.  The installation was not removed, but I had to create or recreate a link in /usr/local/bin.</p>
<br /> Tagged: <a href='http://davidvaleri.wordpress.com/tag/java/'>java</a>, <a href='http://davidvaleri.wordpress.com/tag/os-x/'>os x</a>, <a href='http://davidvaleri.wordpress.com/tag/tools/'>tools</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvaleri.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvaleri.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvaleri.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvaleri.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvaleri.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvaleri.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvaleri.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvaleri.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvaleri.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvaleri.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvaleri.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvaleri.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvaleri.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvaleri.wordpress.com/224/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvaleri.wordpress.com&amp;blog=15062177&amp;post=224&amp;subd=davidvaleri&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvaleri.wordpress.com/2011/09/29/how-i-learned-to-stop-worrying-and-love-os-x-lion-for-java-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bcc5eab278c97ad0d3adb502001031bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dvaleri</media:title>
		</media:content>
	</item>
		<item>
		<title>Deploying Spring MVC Based Web Applications to OSGi Using Apache ServiceMix</title>
		<link>http://davidvaleri.wordpress.com/2011/08/17/deploying-spring-mvc-based-web-applications-to-osgi-using-apache-servicemix/</link>
		<comments>http://davidvaleri.wordpress.com/2011/08/17/deploying-spring-mvc-based-web-applications-to-osgi-using-apache-servicemix/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 04:52:41 +0000</pubDate>
		<dc:creator>David Valeri</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[karaf]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[servicemix]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://davidvaleri.wordpress.com/?p=181</guid>
		<description><![CDATA[The OSGi specification defines appropriate bundle manifest headers and mechanisms for the deployment of servlet-based WAR packaged applications into an OSGi container. As with most APIs, programming a modern application using the Servlet specification requires copious amounts of boilerplate code &#8230; <a href="http://davidvaleri.wordpress.com/2011/08/17/deploying-spring-mvc-based-web-applications-to-osgi-using-apache-servicemix/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvaleri.wordpress.com&amp;blog=15062177&amp;post=181&amp;subd=davidvaleri&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The OSGi specification defines appropriate bundle manifest headers and mechanisms for the deployment of servlet-based WAR packaged applications into an OSGi container. As with most APIs, programming a modern application using the Servlet specification requires copious amounts of boilerplate code that any number of Web application frameworks can reduce. The <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html" target="_blank">Spring MVC</a> framework is among these Web application frameworks. As with many of the capabilities of an OSGi container, the hooks for integrating the WAR with the capabilities of the container, such as OSGi services; modularity; configuration; and class loading, requires programming copious amounts of boilerplate code to OSGi APIs. Unlike the world of Web applications, there are far fewer frameworks for simplifying deployment in an OSGi container. The <a href="http://www.springsource.org/osgi" target="_blank">Spring DM</a> framework is among this small group. This article discusses how to leverage the Spring MVC framework together with the capabilities of Spring DM in order to take full advantage of the value added features of both frameworks. This article uses <a href="http://servicemix.apache.org/home.html" target="_blank">Apache ServiceMix</a> as the target platform.<br />
<span id="more-181"></span></p>
<h1>The Project and Build Structure</h1>
<p>One of the easiest ways to assemble an OSGi ready WAR is to use Maven in conjunction with the WAR and Felix Bundle Plug-ins. The WAR Plug-in allows the build to produce a WAR artifact while the Bundle Plug-in simplifies the creation of the OSGi manifest. The following Maven POM snippet illustrates the key points of the Maven build. The <a href="http://davidvaleri.googlecode.com/svn/projects/examples/spring-mvc-smx/tags/spring-mvc-smx-1.0/pom.xml" target="_blank">complete POM</a> can be found in the source code repository.</p>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; ...&gt;
  ...
  &lt;packaging&gt;war&lt;/packaging&gt;
  ...
  &lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
        &lt;configuration&gt;
          &lt;!-- Make a skinny WAR --&gt;
          &lt;packagingExcludes&gt;WEB-INF/lib/*.jar&lt;/packagingExcludes&gt;
          &lt;archive&gt;
            &lt;manifestFile&gt;${basedir}/target/bnd/MANIFEST.MF&lt;/manifestFile&gt;
          &lt;/archive&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
        &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.3.5&lt;/version&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;id&gt;bundle-manifest&lt;/id&gt;
            &lt;phase&gt;process-classes&lt;/phase&gt;
            &lt;goals&gt;
              &lt;goal&gt;manifest&lt;/goal&gt;
            &lt;/goals&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
        &lt;configuration&gt;
          &lt;supportedProjectTypes&gt;
            &lt;supportedProjectType&gt;war&lt;/supportedProjectType&gt;
          &lt;/supportedProjectTypes&gt;
          &lt;manifestLocation&gt;target/bnd&lt;/manifestLocation&gt;
          &lt;instructions&gt;
            &lt;Webapp-Context&gt;spring-mvc-smx&lt;/Webapp-Context&gt;
            &lt;Web-ContextPath&gt;spring-mvc-smx&lt;/Web-ContextPath&gt;
            &lt;Export-Package&gt;!*&lt;/Export-Package&gt;
            &lt;Import-Package&gt;
              javax.servlet; version=&quot;[2.4.0, 4.0.0)&quot;,
              javax.servlet.http; version=&quot;[2.4.0, 4.0.0)&quot;,
              javax.servlet.jsp.jstl.core; version=&quot;[1.2,2.0)&quot;,
              javax.servlet.resources; version=&quot;[2.4.0, 4.0.0)&quot;,
              &lt;!-- Just import EVERYTHING from Apache standard JSTL impl. --&gt;
              org.apache.taglibs.standard; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.extra.spath; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.functions; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.lang.jstl; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.lang.jstl.parser; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.lang.jstl.test; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.lang.jstl.test.beans; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.lang.support; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.resources; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.tag.common.core; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.tag.common.fmt; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.tag.common.sql; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.tag.common.xml; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.tag.el.core; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.tag.el.fmt; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.tag.el.sql; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.tag.el.xml; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.tag.rt.core; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.tag.rt.fmt; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.tag.rt.sql; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.tag.rt.xml; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.tei; version=&quot;[1.2.0,2)&quot;,
              org.apache.taglibs.standard.tlv; version=&quot;[1.2.0,2)&quot;,
              org.springframework.beans.factory.config,
              org.springframework.osgi.web.context.support; version=&quot;[1.2,2.0)&quot;,
              org.springframework.stereotype,
              org.springframework.web.bind.annotation,
              org.springframework.web.servlet,
              org.springframework.web.servlet.view,
              *
            &lt;/Import-Package&gt;
            &lt;Bundle-ClassPath&gt;
              WEB-INF/classes,
              &lt;!-- Have to use this for PAX Web 0.7.4 to find JSPs since it uses classpath. --&gt;
              .
            &lt;/Bundle-ClassPath&gt;
          &lt;/instructions&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
      ...
    &lt;/plugins&gt;
  &lt;/build&gt;
&lt;/project&gt;
</pre></p>
<ul>
<li><strong>Line 4</strong> – This line is the standard way in which you instruct Maven to construct a WAR artifact instead of the default JAR packaging.</li>
<li><strong>Line 13</strong> – This line instructs the WAR Plug-in to exclude all dependencies from the WAR. The resulting WAR imports all of its dependencies from the OSGi class loader and is therefore significantly smaller than a traditional WAR.</li>
<li><strong>Line 15</strong> – This line instructs the WAR Plug-in to use an externally generated manifest file instead of the one that is automatically generated by default.</li>
<li><strong>Line 28</strong> – This line instructs the Felix Bundle Plug-in to generate a manifest file on the file system when the plug-in is executed. Normally, the plug-in injects the manifest directly into the artifact; however, this behavior conflicts with that of the WAR plug-in so we configure this plug-in to write the file to disk and we configure the WAR Plug-in to use the manifest file from the file system.</li>
<li><strong>Line 34</strong> – This line instructs the Felix Bundle Plug-in to execute for projects with the WAR packaging type. The plug-in will not execute for this type of packaging by default.</li>
<li><strong>Line 36</strong> – This line indicates where the Felix Bundle Plug-in should write the manifest file. Note that this location aligns with the location that the WAR Plug-in reads the manifest file from.</li>
<li><strong>Lines 38-39</strong> – These lines provide the context path for the Web application when it is deployed. The context path is the portion of the path preceding the application specific path. In this case, all application URLs will start with http://HOST:PORT/spring-mvc-smx. This property is specified twice in order to support a wider range of PAX Web Extender versions. Web-ContextPath is the official OSGi header while Webapp-Context is the PAX Web Extender specific header supported in earlier versions of PAX Web. PAX Web is the implementation of the WAR related OSGi capabilities that is used in ServiceMix. This library is responsible or connecting the WAR to the underlying OSGi framework as well as publishing the WAR to the OSGi HTTP Service.</li>
<li><strong>Lines 42-45</strong> – These lines indicate that the OSGi container, through its class loading mechanism, should provide the standard Servlet API classes. Much like standard WAR deployments, the container frequently provides these API classes to the class path.</li>
<li><strong>Lines 46-69</strong> – These lines indicate that the OSGi container should provide the Apache implementation of the JSTL to the WAR. In this case, we simply import all of the packages that the Apache “standard” JSTL implementation library exports. These package imports are required if your application includes JSPs that leverage the JSTL tags, but may vary if you choose to use a different implementation. Providing these packages from the container instead of WEB-INF/lib means that your WAR size can be reduced and the implementation library can be shared across multiple WARs. As these packages are not directly referenced from compiled code, they are not automatically detected by the plug-in and therefore must be manually specified.</li>
<li><strong>Line 70-75</strong> – These lines indicate that the OSGi container should provide the necessary Spring MVC classes from the OSGi class loader and not from WEB-INF/lib. As with the Apache JSTL implementation, these packages are not directly referenced from compiled code and are therefore not detected by the Felix Bundle Plug-in. These packages must be imported from the OSGi container to ensure a consistent class space with the Spring DM OsgiBundleXmlWebApplicationContext class.</li>
<li><strong>Lines 79-81</strong> – These lines indicate that the bundle/WAR class path should also include the contents of specific locations within the WAR. The WEB-INF/classes folder provides the implementation classes for the WAR while the “.” entry is required to enable the PAX Web Extender to locate JSPs within the WAR. Some versions of the PAX Web Extender search for the JSP path using the WAR/bundle class path in lieu of searching the actual bundle/WAR contents. As such, including the root folder of the bundle/WAR on the class path ensures that JSPs can be resolved over a broader range of PAX Web versions.</li>
</ul>
<p>The project folder structure is as follows:</p>
<ul>
<li><strong>/src/main/java</strong> – This folder contains the source code for the WAR.</li>
<li><strong>/src/main/features</strong> – This folder contains the source file for the project Karaf Feature Descriptor.</li>
<li><strong>/src/main/webapp</strong> – This folder contains the contents that are copied into the root of the WAR. This folder contains JSPs, web.xml, and the Spring MVC application context file.</li>
</ul>
<h1>Spring MVC In an OSGi World</h1>
<p>Spring MVC typically uses an XmlWebApplicationContext instance with the DispatcherServlet. Together, these two classes provide a means to bootstrap a Servlet container aware application context and to wire the Servlet container to the Spring MVC controllers. XmlWebApplicationContext is however, unaware of the OSGi container. For this reason, Spring DM provides an OsgiBundleXmlWebApplicationContext that can be substituted for XmlWebApplicationContext when deploying the WAR in an OSGi container. OsgiBundleXmlWebApplicationContext makes the application context in the WAR aware of the OSGi container and provides access to the capabilities provided by the container as well as the BundleContext of the deployed bundle/WAR. One specifies that the DispatcherServlet should use the OSGi aware version of the application context in the web.xml file of the bundle/WAR. The following web.xml snippet illustrates the relevant configuration. After this small change, the standard features of Spring and Spring MVC, including annotation based controllers and component scanning, are available within the OSGi deployed WAR. The complete <a href="http://davidvaleri.googlecode.com/svn/projects/examples/spring-mvc-smx/tags/spring-mvc-smx-1.0/src/main/webapp/WEB-INF/web.xml" target="_blank">web.xml</a> can be found in the source code repository.</p>
<p><pre class="brush: xml; wrap-lines: false;">
…
  &lt;servlet&gt;
    &lt;servlet-name&gt;spring-mvc-smx&lt;/servlet-name&gt;
    &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
    &lt;init-param&gt;
      &lt;param-name&gt;contextClass&lt;/param-name&gt;
      &lt;param-value&gt;org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext&lt;/param-value&gt;
    &lt;/init-param&gt;
  &lt;/servlet&gt;
…
</pre></p>
<ul>
<li><strong>Lines 5-8</strong> – Illustrate using an init-param for the DispatcherServlet to override the implementation class for the application context used by the servlet.</li>
</ul>
<h1>Tag Libraries in an OSGi World</h1>
<p>Normally, tag libraries can be auto-detected from the WEB-INF/lib folder or specified in the web.xml file. As this example does not specify any JAR files from WEB-INF/lib in the Bundle-Classpath manifest header, the tag library implementation must be provided by the OSGi container class loader through a package import. While this approach does not require the tag library implementation to be included in the WAR itself, it does create a small issue with auto-discovery of the .tld files for the tag library. Tag library descriptor files reside in the META-INF folder of the JAR. When this JAR is not in the WEB-INF/lib folder and its packages are instead supplied by OSGi package imports, these files are not detected. The workaround for this limitation is to include the tag library descriptor files directly in the WAR and to reference them from web.xml. The following web.xml snippet illustrates the relevant configuration settings for including the JSTL .tld files from withing the WAR itself. The complete <a href="http://davidvaleri.googlecode.com/svn/projects/examples/spring-mvc-smx/tags/spring-mvc-smx-1.0/src/main/webapp/WEB-INF/web.xml" target="_blank">web.xml</a> can be found in the source code repository.</p>
<p><pre class="brush: xml; wrap-lines: false;">
…
  &lt;jsp-config&gt;
    &lt;taglib&gt;
      &lt;taglib-uri&gt;http://java.sun.com/jstl/core&lt;/taglib-uri&gt;
      &lt;taglib-location&gt;/WEB-INF/tld/c.tld&lt;/taglib-location&gt;
    &lt;/taglib&gt;
    &lt;taglib&gt;
      &lt;taglib-uri&gt;http://java.sun.com/jsp/jstl/fmt&lt;/taglib-uri&gt;
      &lt;taglib-location&gt;/WEB-INF/tld/fmt.tld&lt;/taglib-location&gt;
    &lt;/taglib&gt;
    &lt;taglib&gt;
      &lt;taglib-uri&gt;http://java.sun.com/jsp/jstl/fmt&lt;/taglib-uri&gt;
      &lt;taglib-location&gt;/WEB-INF/tld/fmt.tld&lt;/taglib-location&gt;
    &lt;/taglib&gt;
    &lt;taglib&gt;
      &lt;taglib-uri&gt;http://java.sun.com/jsp/jstl/functions&lt;/taglib-uri&gt;
      &lt;taglib-location&gt;/WEB-INF/tld/fn.tld&lt;/taglib-location&gt;
    &lt;/taglib&gt;
    &lt;taglib&gt;
      &lt;taglib-uri&gt;http://java.sun.com/jsp/jstl/xml&lt;/taglib-uri&gt;
      &lt;taglib-location&gt;/WEB-INF/tld/x.tld&lt;/taglib-location&gt;
    &lt;/taglib&gt;
  &lt;/jsp-config&gt;
…
</pre></p>
<ul>
<li><strong>Lines 2-23</strong> – These lines provide the location for the TLD files of the JSTL. The files were copied from the implementation JAR that the bundle/WAR imports the JSTL implementation packages from. Alternatively, the JSTL implementation JAR can be included in the WAR and added to the Bundle-Classpath manifest header; however, the bundle/WAR will then need to import the package dependencies from the implementation JAR or also add those dependencies to the Bundle-Classpath manifest header.</li>
</ul>
<h1>Bridging the OSGi WAR Gap</h1>
<p>So far this article has discussed how to get Spring MVC to act like Spring MVC in an OSGi deployed WAR. If there were nothing more, the keener reader’s out there would be asking, “why would I go through all this trouble when Servlet container XXX will do just fine?” Don’t worry if you didn’t ask this question, you are already researching this topic and reading a blog. That makes you more keen than not. Because the WAR is using OsgiBundleXmlWebApplicationContext from Spring DM, all of the OSGi goodness that Spring DM brings to Spring is also available to the Spring MVC based applications. Service implementations for Spring MVC controllers can be looked up in the OSGi service registry, configuration options can be managed and updated through the OSGi Configuration Admin service, and previously insurmountable class space collisions can be overcome. The following Spring application context snippet illustrates one of the many convenient integration points that Spring DM can provide to the Web application. More examples of the Spring DM capabilities are available in the Spring DM documentation. The complete <a href="http://davidvaleri.googlecode.com/svn/projects/examples/spring-mvc-smx/tags/spring-mvc-smx-1.0/src/main/webapp/WEB-INF/spring-mvc-smx-servlet.xml" target="_blank">context file</a> can be found in the source code repository.</p>
<p><pre class="brush: xml; wrap-lines: false;">
...
&lt;osgi:reference id=&quot;configurationAdmin&quot;
                  interface=&quot;org.osgi.service.cm.ConfigurationAdmin&quot;/&gt;
...
</pre></p>
<ul>
<li><strong>Lines 2-3</strong> – This line illustrates how to retrieve a service from the OSGi registry. In this case, the service is the Configuration Admin service. The controller in the example application uses this service to list all of the configurations available in the OSGi container.</li>
</ul>
<p>Once available in the application context, the bean can be used just as any other locally defined bean. The following Java snippet illustrates how the bean is injected into a controller and used to render the view.  The complete <a href="http://davidvaleri.googlecode.com/svn/projects/examples/spring-mvc-smx/tags/spring-mvc-smx-1.0/src/main/java/valeri/blog/examples/spring_mvc_smx/HomeController.java">controller source</a> is available in the source repository.</p>
<p><pre class="brush: java; wrap-lines: false;">
...

@Controller
@RequestMapping(value = &amp;quot;/&amp;quot;)
public class HomeController {

    @Autowired
    BundleContext bundleContext;

    @Autowired
    ConfigurationAdmin configurationAdmin;

    RequestMapping(method = {RequestMethod.GET})
    public ModelAndView home() throws Exception {

        ModelAndView mav = new ModelAndView(&amp;quot;home&amp;quot;);

        Bundle[] bundles = bundleContext.getBundles();
        mav.addObject(&amp;quot;bundles&amp;quot;, bundles);

        Configuration[] configurations = configurationAdmin.listConfigurations(null);
        mav.addObject(&amp;quot;configurations&amp;quot;, configurations);
        return mav;
    }

    public BundleContext getBundleContext() {
        return bundleContext;
    }

    public void setBundleContext(BundleContext bundleContext) {
        this.bundleContext = bundleContext;
    }

    public ConfigurationAdmin getConfigurationAdmin() {
        return configurationAdmin;
    }

    public void setConfigurationAdmin(ConfigurationAdmin configurationAdmin) {
        this.configurationAdmin = configurationAdmin;
    }
}
</pre></p>
<ul>
<li><strong>Line 11</strong> – This line declares an instance of the Configuration Admin interface as an instance variable that is set using Spring’s auto-wiring.</li>
<li><strong>Lines 14-23</strong> – These lines query the Configuration Admin service and add the results to the model for rendering.</li>
</ul>
<h1>Deploying in Apache ServiceMix</h1>
<p>In order to deploy a WAR using Spring MVC and the Apache JSTL implementation, several additional OSGi bundles must be provisioned in an out-of-the-box ServiceMix instance. The easiest and most repeatable way to provision these bundles is to use a Karaf feature descriptor to describe the bundles to be provisioned. The following feature descriptor snippet illustrates the additional provisioning activities that are needed. The complete <a href="http://davidvaleri.googlecode.com/svn/projects/examples/spring-mvc-smx/tags/spring-mvc-smx-1.0/src/main/features/features.xml" target="_blank">feature descriptor</a> can be found in the source code repository.</p>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;features name=&quot;spring-mvc-smx-${project.version}&quot;&gt;
  &lt;feature name=&quot;spring-mvc-smx&quot; version=&quot;${project.version}&quot;&gt;
    &lt;feature&gt;spring&lt;/feature&gt;
    &lt;feature&gt;spring-dm&lt;/feature&gt;
    &lt;feature&gt;war&lt;/feature&gt;

    &lt;bundle&gt;mvn:${project.groupId}/spring-mvc-smx/${project.version}/war&lt;/bundle&gt;

    &lt;bundle&gt;mvn:org.springframework.osgi/spring-osgi-web/1.2.0&lt;/bundle&gt;
    &lt;bundle&gt;mvn:org.springframework/spring-web/3.0.5.RELEASE&lt;/bundle&gt;
    &lt;bundle&gt;mvn:org.springframework/spring-webmvc/3.0.5.RELEASE&lt;/bundle&gt;

    &lt;bundle&gt;mvn:javax.servlet/com.springsource.javax.servlet.jsp.jstl/1.2.0.v20110728&lt;/bundle&gt;
  &lt;/feature&gt;
&lt;/features&gt;
</pre></p>
<ul>
<li><strong>Lines 4-6</strong> – These lines ensure that the core Spring bundles, the core Spring DM bundles, and the PAX Web bundles are provisioned in the container.</li>
<li><strong>Lines 10-12</strong> – These lines provision the additional Spring DM and Spring MVC bundles required to deploy a WAR using Spring MVC.</li>
<li><strong>Line 14</strong> – These lines provision the bundle related to the Apache implementation of the JSTL.</li>
</ul>
<h1>Building and Deploying the Example Code</h1>
<p>Build Pre-requisites</p>
<ul>
<li>Java 1.5+</li>
<li><a href="http://maven.apache.org/" target="_blank">Maven 3.0+</a></li>
<li><a href="http://subversion.apache.org/" target="_blank">Subversion</a></li>
</ul>
<p>Deploy Pre-requisites</p>
<ul>
<li><a href="http://servicemix.apache.org/download.html" target="_blank">Apache ServiceMix 4.3.0</a></li>
</ul>
<h2>Building</h2>
<ol>
<li>Checkout the source code from<a href="https://davidvaleri.googlecode.com/svn/projects/examples/spring-mvc-smx/tags/spring-mvc-smx-1.0" target="_blank"> https://davidvaleri.googlecode.com/svn/projects/examples/spring-mvc-smx/tags/spring-mvc-smx-1.0</a> using your Subversion client.</li>
<li>Build the source code by executing the following command from the checkout folder:
<pre>mvn clean install</pre>
</li>
</ol>
<p><strong>Deploying</strong></p>
<ol>
<li>Start Apache ServiceMix 4.3.0</li>
<li>In the ServiceMix shell, add the feature descriptor for the example application by executing the following command:
<pre>features:addurl mvn:valeri.blog.examples/spring-mvc-smx/1.0/xml/features</pre>
<p>NOTE: If you did not build the example locally, you will need to add the Maven repository for this blog to the ServiceMix configuration. Edit SERVICEMIX_HOME/etc/org.ops4j.pax.url.mvn.cfg and add <a href="http://davidvaleri.googlecode.com/svn/repo/" target="_blank">http://davidvaleri.googlecode.com/svn/repo/</a> to the org.ops4j.pax.url.mvn.repositories property.</li>
<li>Provision the example WAR by executing the following command in the ServiceMix shell:<br />
features:install spring-mvc-smx</li>
<li>Confirm the installation by executing the following command in the ServiceMix shell:<br />
osgi:list</li>
<li>The output should resemble the following:
<pre>[ 202] [Active ] [ ] [ ] [ 60] David Valeri's Blog :: Examples :: Spring MVC In ServiceMix (1.0.0)
[ 203] [Active ] [ ] [ ] [ 60] spring-osgi-web (1.2.0)
[ 204] [Active ] [ ] [ ] [ 60] Spring Web (3.0.5.RELEASE)
[ 205] [Active ] [ ] [ ] [ 60] Spring Web Servlet (3.0.5.RELEASE)
[ 206] [Active ] [ ] [ ] [ 60] JavaServer Pages (TM) TagLib API and Implementation (1.2.0.v20110728)</pre>
</li>
<li>Navigate to <a href="http://localhost:8181/spring-mvc-smx/" target="_blank">http://localhost:8181/spring-mvc-smx/</a> using the browser of your choice.</li>
<li>The displayed page contains information retrieved from the OSGi bundle context as well as from an OSGi service retrieved from the OSGi service registry. If you receive an error message or no page is displayed, try refreshing the WAR bundle as it may have loaded before the other newly provisioned bundles. Execute the refresh in the ServiceMix shell using the ID of the bundle with the name “David Valeri&#8217;s Blog :: Examples :: Spring MVC In ServiceMix (1.0.0)”. If you still receive an error message, refer to the ServiceMix log files and feel free to post a comment below.</li>
</ol>
<br /> Tagged: <a href='http://davidvaleri.wordpress.com/tag/karaf/'>karaf</a>, <a href='http://davidvaleri.wordpress.com/tag/osgi/'>osgi</a>, <a href='http://davidvaleri.wordpress.com/tag/servicemix/'>servicemix</a>, <a href='http://davidvaleri.wordpress.com/tag/spring/'>spring</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvaleri.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvaleri.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvaleri.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvaleri.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvaleri.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvaleri.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvaleri.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvaleri.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvaleri.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvaleri.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvaleri.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvaleri.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvaleri.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvaleri.wordpress.com/181/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvaleri.wordpress.com&amp;blog=15062177&amp;post=181&amp;subd=davidvaleri&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvaleri.wordpress.com/2011/08/17/deploying-spring-mvc-based-web-applications-to-osgi-using-apache-servicemix/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bcc5eab278c97ad0d3adb502001031bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dvaleri</media:title>
		</media:content>
	</item>
		<item>
		<title>Simplified TLS Configuration in Apache Camel</title>
		<link>http://davidvaleri.wordpress.com/2011/07/26/simplified-tls-configuration-in-apache-camel/</link>
		<comments>http://davidvaleri.wordpress.com/2011/07/26/simplified-tls-configuration-in-apache-camel/#comments</comments>
		<pubDate>Tue, 26 Jul 2011 17:07:33 +0000</pubDate>
		<dc:creator>David Valeri</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[camel]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://davidvaleri.wordpress.com/?p=172</guid>
		<description><![CDATA[As you can probably tell from some of my previous blog posts on the subject of security, I’ve spent some time mired deep in the muck that is TLS configuration in the JVM.  Over time, I have found that many &#8230; <a href="http://davidvaleri.wordpress.com/2011/07/26/simplified-tls-configuration-in-apache-camel/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvaleri.wordpress.com&amp;blog=15062177&amp;post=172&amp;subd=davidvaleri&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As you can probably tell from some of my previous blog posts on the subject of security, I’ve spent some time mired deep in the muck that is TLS configuration in the JVM.  Over time, I have found that many libraries and frameworks provide poor support for customizing the finer points of TLS.  The greatest offenders simply support global configuration through the JSSE system properties.  Others allow you to specify a pre-configured SSLContext or SSLEngine but don’t allow you to easily configure the sockets that actually get used by the library or framework.  Still others provide a slew of configuration options, unique to the framework, that are used to instantiate an SSLContext for you.  While these solutions to configuring TLS are workable, they impose limitations on your application and require developers to learn different configuration mechanisms for every framework that they need to configure with TLS.</p>
<p>One of Camel’s greatest strengths is to abstract the complexity of framework boilerplate code away from one’s application.  Unfortunately, when it comes to TLS configuration, Camel just wasn’t doing enough to prevent developers needing to configure TLS for a component from having to implement framework specific interfaces, learn framework specific configuration options, and generally curse TLS and JSSE.  This observation coupled with a healthy does of frustration served as the impetuous for creating the JSSE Configuration Utility in Apache Camel.</p>
<p>The key goals of the configuration utility are:</p>
<ol>
<li>Provide a uniform framework for complete customization of JSSE/TLS configuration options from key stores, to algorithms, to protocols, to sockets.</li>
<li>Provide an easy way to configure these options through code, Spring, and Blueprint.</li>
<li>Provide extensibility to allow for the addition of future configuration options.</li>
<li>Provide support for the configuration utility across a number of key networking related Camel components.</li>
</ol>
<p>The JSSE Configuration Utility is available in Camel 2.8 and above.  You can read about the capabilities of the JSSE Configuration Utility and see a list of components with support for the utility on the <a href="http://camel.apache.org/camel-configuration-utilities.html" target="_blank">Apache Camel Wiki</a>.  Support for the new Camel Asynchronous HTTP Client component is planed for Camel 2.9.  If you are looking for an enterprise-ready, validated, and supported distribution of Apache Camel, try <a title="Fuse Mediation Router - Based on Apache Camel" href="http://fusesource.com/products/enterprise-camel/" target="_blank">Fuse Mediation Router which is based on Apache Camel</a>.</p>
<br /> Tagged: <a href='http://davidvaleri.wordpress.com/tag/camel/'>camel</a>, <a href='http://davidvaleri.wordpress.com/tag/security/'>security</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvaleri.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvaleri.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvaleri.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvaleri.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvaleri.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvaleri.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvaleri.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvaleri.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvaleri.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvaleri.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvaleri.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvaleri.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvaleri.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvaleri.wordpress.com/172/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvaleri.wordpress.com&amp;blog=15062177&amp;post=172&amp;subd=davidvaleri&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvaleri.wordpress.com/2011/07/26/simplified-tls-configuration-in-apache-camel/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bcc5eab278c97ad0d3adb502001031bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dvaleri</media:title>
		</media:content>
	</item>
		<item>
		<title>Secrets of The Felix Bundle Plug-in Macros Revealed</title>
		<link>http://davidvaleri.wordpress.com/2011/04/07/secrets-of-the-felix-bundle-plug-in-macros-revealed/</link>
		<comments>http://davidvaleri.wordpress.com/2011/04/07/secrets-of-the-felix-bundle-plug-in-macros-revealed/#comments</comments>
		<pubDate>Fri, 08 Apr 2011 01:52:30 +0000</pubDate>
		<dc:creator>David Valeri</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[servicemix]]></category>

		<guid isPermaLink="false">http://davidvaleri.wordpress.com/?p=152</guid>
		<description><![CDATA[I was recently dealing with some client concerns regarding package import scopes in their Maven-built artifact using the Felix Bundle Plug-in. The client was curious about strategies for dealing with package import version ranges as well as how to manage &#8230; <a href="http://davidvaleri.wordpress.com/2011/04/07/secrets-of-the-felix-bundle-plug-in-macros-revealed/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvaleri.wordpress.com&amp;blog=15062177&amp;post=152&amp;subd=davidvaleri&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was recently dealing with some client concerns regarding package import scopes in their Maven-built artifact using the Felix Bundle Plug-in.  The client was curious about strategies for dealing with package import version ranges as well as how to manage the creation of these ranges within their Maven builds.  This article discusses some strategies for managing package import versions using the Felix Bundle Plug-in and the versioning related macros.</p>
<p><span id="more-152"></span>Before we begin, this article assumes that you have a working knowledge of OSGi bundles and a basic understanding of how to use the Felix Bundle Plug-in with a Maven build.  For more information on OSGi and the Felix Bundle Plug-in, refer to the links below.</p>
<ul>
<li><a href="http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html">http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html</a></li>
<li><a href="http://www.aqute.biz/Bnd/Bnd">http://www.aqute.biz/Bnd/Bnd</a></li>
<li><a href="http://www.google.com/search?q=osgi+tutorial">http://www.google.com/search?q=osgi+tutorial</a></li>
</ul>
<h2>The Default Plug-in Behavior</h2>
<p>The simplest strategy that comes to mind is to just let the bundle plug-in loose on your build and let it choose the version range on each package import.  The bundle plug-in’s default behavior is to create a range from a dependency&#8217;s current version, truncated to only the major and minor version, up to but not including the next major version number.  For example, if your project depends on package x.y.z from another OSGi bundle with the package export version 1.2.3.4, the resulting import will use the version range from 1.2 up to, but not including, 2.  The import will look like this:</p>
<pre>x.y.z; version="[1.2,2)"</pre>
<h2>Manually Specifying Versions</h2>
<p>The next level of control over the package imports in your bundle is to use Maven properties in your POM to define version numbers and to use token replacement in the configuration of the Felix Bundle Plug-in.  You can also just hard-code the literals in the bundle plug-in, but this requires a little more attention to detail when performing POM maintenance.  This approach allows you to manually set a variable representing the version of a given library and to reuse it a number of times across multiple configurations of the Felix Bundle Plug-in.  This approach looks something like the following POM snippet.</p>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;&gt;
  …
  &lt;properties&gt;
    &lt;camel.version&gt;2.6.0-fuse-01-09&lt;/camel.version&gt;
  &lt;/properties&gt;
  …
  &lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
        &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.3.4&lt;/version&gt;
        &lt;extensions&gt;true&lt;/extensions&gt;
        &lt;configuration&gt;
          &lt;instructions&gt;
            &lt;Import-Package&gt;
              org.apache.camel*; version=&quot;${camel.version}&quot;,
              *
            &lt;/Import-Package&gt;
          &lt;/instructions&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
  …
&lt;/project&gt;
</pre></p>
<p>This POM snippet instructs the Felix Bundle Plug-in to import all Camel related packages with a strict version requirement on the version represented by the value of the camel.version property in the POM,  2.6.0-fuse-01-09 in this example.  All other packages will be imported using the default range chosen by the Felix Bundle Plug-in.</p>
<p>This approach quickly becomes tedious to maintain if you want to retain ranges on your package imports as you would need to define properties for both the upper and lower bounds of every import as well as keep all those properties properly sorted in your POM.</p>
<h2>Using the BND Macros</h2>
<p>The <a href="http://www.aqute.biz/Bnd/Bnd">BND</a> tool, the underlying utility that the Felix Bundle Plug-in is built on, provides a number of predefined macros for working with version numbers on package imports.  The most common macros, are @, version, and range.  These macros represent the version of the package as supplied by your maven resolved dependencies, a configurable mask applied to a version number, and a range built using a mask applied to a version number, respectively.  While these macro capabilities sound great, the BND tool documentation isn’t always up to date nor does the Felix Bundle Plug-in describe the use of these macros in much detail.  The following examples should help to clarify the behavior of the Felix Bundle Plug-in (version 2.3.4) and the use these macros in the context of the plug-in as it isn’t always obvious and there are a couple gotchas. Before I continue, I’d like to thank Fintan Bolton, tech writer extraordinaire from <a href="http://fusesource.com">FuseSource</a>.  Fintan helped to put some of the pieces in place and I am happy to say that the following information already appears in, or will appear shortly, in the <a href="http://fusesource.com/products/enterprise-servicemix/">FuseSource documentation on Apache ServiceMix and OSGi</a>.</p>
<h3>Caveat Emptor</h3>
<h4>The First Gotcha</h4>
<p>Maven uses the ${} pattern for its own token replacement mechanism.  While the BND tool also allows the ${} pattern to be used for its macros, keep in mind that Maven will process the plug-in configuration first and happily replace your ${@} macro usage with its own value for the @ property.<br />
So this in your POM:</p>
<pre>org.slf4j;version="${@}</pre>
<p>Results in this in your bundle manifest:</p>
<pre>org.slf4j;version=null</pre>
<p>Suitable substitutes for ${} in the Felix Bundle Plug-in are: $() and $&lt;&gt;.  Note that when using &lt;&gt;  as your macro delimiters, you either need to escape &lt; with &amp;lt; or wrap the contents of the  element with CDATA as shown below.  The CDATA approach is far more manageable over the long term as it is much easier to read and maintain.</p>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;Import-Package&gt;&lt;![CDATA[
  *;version=&quot;$&lt;@&gt;&quot;]]&gt;
&lt;/Import-Package&gt;
</pre></p>
<h4>The Second Gotcha</h4>
<p>The plug-in and BND are not looking out for dependencies that are a plain JAR.  For example, the JSR 303 API JAR in the Maven repo is not an OSGi bundle.  If you attempt to use one of the macros on any package from this JAR, you will get the literal text of the macro instead of a version number in your bundle manifest.<br />
This in your POM:</p>
<pre>javax.validation;version="$(@)"</pre>
<p>Results in this in your bundle manifest:</p>
<pre>javax.validation;version="${@}"</pre>
<h4>The Third Gotcha</h4>
<p>The plug-in and BND are not looking out for dependencies that that do not define a version on their exported packages.  For example, WSS4J 1.5.8 is packaged as an OSGi bundle, but its package exports do not define a version number in the bundle manifest.  A reference to a package from WSS4J using one of the three macros discussed in this article will also result in the literal text of the macro instead of a version number in your bundle manifest.<br />
This in your POM:</p>
<pre>org.apache.ws.security;version="$(@)"</pre>
<p>Results in this in your bundle manifest:</p>
<pre>org.apache.ws.security;version="${@}"</pre>
<h2>The @ Macro</h2>
<p>This macro will inject the version of a package as it is provided in a Maven defined dependency in the build classpath.  In the following POM, the source code leverages packages from SLF4J.</p>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;&gt;
  …
  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
      &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
      &lt;version&gt;1.5.8&lt;/version&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;
  …
  &lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
        &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.3.4&lt;/version&gt;
        &lt;extensions&gt;true&lt;/extensions&gt;
        &lt;configuration&gt;
          &lt;instructions&gt;
            &lt;Import-Package&gt;
              *;version=&quot;$(@)&quot;
            &lt;/Import-Package&gt;
          &lt;/instructions&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
&lt;/project&gt;
</pre></p>
<p>The resulting bundle manifest will contain the following:</p>
<pre>Import-Package: org.slf4j;version="1.5.8"</pre>
<h2>The Version Macro</h2>
<p>This macro will inject the version of a package, either defined by the version as it is provided in a Maven defined dependency or as supplied as a literal, after it has had a mask applied to it.  The mask allows you to easily alter a package version declaratively during the build process.  The “=” mask indicates to leave that portion of the version alone, the “+” mask indicates to increment that portion of the version, and the “-“ filter indicates to decrement that portion of the version.</p>
<p>For example if package x.y.z has the version 1.2.3.4, the mask ==== would result in the version 1.2.3.4, the mask =+ would result in the version 1.3, and the mask =- would result in the version 1.1.</p>
<p>The syntax for this macro in version 2.3.4 of the Felix Bundle Plug-in is a little different than described in the BND documentation.  The syntax is version;MASK[;LITERAL].  Where MASK is a combination of mask  characters and ;LITERAL represents an optional literal version number string.  If the literal version number string is omitted, an implicit @ macro is used.  The following package import is a valid example of the version macro in 2.3.4.</p>
<pre>org.slf4j*;version="[$(version;==),$(version;+;1.5.8))"</pre>
<p>This configuration indicates to construct a version range with the lower bound containing only the major and minor version number of the version defined in the SL4J dependency resolved by Maven and the upper bound containing only the major version number, incremented by one, of the literal version string 1.5.8.  The literal value can also be supplied by Maven token replacement.  So the line from the above example becomes:</p>
<pre>org.slf4j*;version="[$(version;==),$(version;+;${slf4j.version}))"</pre>
<p>While one can use the version macro to define a version rage for package imports, the range macro makes this task even simpler in many cases.</p>
<h2>The Range Macro</h2>
<p>The range macro works much like the version macro by applying a mask to a version number; however, this macro also allows you to inject the inclusive/exclusive wrapper characters of the OSGi version range syntax.  The following POM snippet illustrates how to create a version range for the SLF4J packages used throughout this article.  The module source code contains imports for packages supplied by SLF4J.</p>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;&gt;
  …
  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
      &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
      &lt;version&gt;1.5.8&lt;/version&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;
  …
  &lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
        &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.3.4&lt;/version&gt;
        &lt;extensions&gt;true&lt;/extensions&gt;
        &lt;configuration&gt;
          &lt;instructions&gt;
            &lt;Import-Package&gt;&lt;![CDATA[
              org.slf4j*;version=&quot;$&lt;range;[==,=+)&gt;&quot;
              ]]&gt;
            &lt;/Import-Package&gt;
          &lt;/instructions&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
&lt;/project&gt;
</pre></p>
<p>The resulting bundle manifest will contain the following:</p>
<pre>Import-Package: org.slf4j;version="[1.5,1.6)"</pre>
<p>In this case, the implicit @ macro was used to determine the version number to apply the masks to.  Just like the version macro, you can also specify a version number as a string literal or using a Maven property and token replacement.</p>
<p>Note also that the  &lt; and &gt; characters were chosen as the separators in this case.  This is because the ) character used to close the version range will confuse the parser if the ( and ) characters are used to demarcate the range macro.</p>
<p>This configuration using the ( and ) characters to demarcate the range:</p>
<pre>org.slf4j*;version="$(range;[==,=+))"</pre>
<p>Results in the following error message during the build:</p>
<pre>[INFO] [bundle:bundle {execution: default-bundle}]
[WARNING] Warning building bundle example:bundle-plugin-macros:bundle:1.0 : No translation found for macro: range;[==,=+
[ERROR] Error building bundle example:bundle-plugin-macros:bundle:1.0 : null, for cmd: range, arguments; [range, [==,=+]
[ERROR] Error(s) found in bundle configuration
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error(s) found in bundle configuration</pre>
<h2>Conclusion</h2>
<p>While the documentation on these macros and the Felix Bundle Plug-in may not provide a massive amount of detail, once you understand the syntax and pitfalls of the macros, they can be combined in a number of ways to provide rich control over package imports in your bundles.</p>
<br /> Tagged: <a href='http://davidvaleri.wordpress.com/tag/maven/'>maven</a>, <a href='http://davidvaleri.wordpress.com/tag/osgi/'>osgi</a>, <a href='http://davidvaleri.wordpress.com/tag/servicemix/'>servicemix</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvaleri.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvaleri.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvaleri.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvaleri.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvaleri.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvaleri.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvaleri.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvaleri.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvaleri.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvaleri.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvaleri.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvaleri.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvaleri.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvaleri.wordpress.com/152/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvaleri.wordpress.com&amp;blog=15062177&amp;post=152&amp;subd=davidvaleri&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvaleri.wordpress.com/2011/04/07/secrets-of-the-felix-bundle-plug-in-macros-revealed/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bcc5eab278c97ad0d3adb502001031bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dvaleri</media:title>
		</media:content>
	</item>
		<item>
		<title>How I learned to stop worrying and love OS X for Java development</title>
		<link>http://davidvaleri.wordpress.com/2010/12/23/how-i-learned-to-stop-worrying-and-love-os-x-for-java-development/</link>
		<comments>http://davidvaleri.wordpress.com/2010/12/23/how-i-learned-to-stop-worrying-and-love-os-x-for-java-development/#comments</comments>
		<pubDate>Fri, 24 Dec 2010 03:57:16 +0000</pubDate>
		<dc:creator>David Valeri</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://davidvaleri.wordpress.com/?p=118</guid>
		<description><![CDATA[I recently acquired a nice 17 inch MacBook Pro to replace my not too old but way too bogged down Windows machine.  I&#8217;ve primarily been developing in Java on the Windows platform for eight years.  In that time, I&#8217;ve come &#8230; <a href="http://davidvaleri.wordpress.com/2010/12/23/how-i-learned-to-stop-worrying-and-love-os-x-for-java-development/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvaleri.wordpress.com&amp;blog=15062177&amp;post=118&amp;subd=davidvaleri&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently acquired a nice 17 inch MacBook Pro to replace my not too old but way too bogged down Windows machine.  I&#8217;ve primarily been developing in Java on the Windows platform for eight years.  In that time, I&#8217;ve come across a lot of tips, tricks, and tools to increase productivity and generally make life easier.  This post discusses some of the equivalent tips, tricks, and applications in OS X with a focus on free solutions.</p>
<p><span id="more-118"></span><a href="http://davidvaleri.files.wordpress.com/2010/12/command_key.png"><img class="alignright size-full wp-image-146" title="command_key" src="http://davidvaleri.files.wordpress.com/2010/12/command_key.png?w=640" alt=""   /></a>Having spent so much time in Windows, I was somewhat nervous about how I would adapt to the Mac way of doing things.  I am certainly not what you would call a Steve Jobs fan-boy and I was ready to slap Linux/Windows on the thing after a couple weeks if it wasn&#8217;t working out.  Overall, the migration has been relatively painless and there are only a few nagging things I feel like I need to resolve.  I don&#8217;t hate Windows, but the amount of superfluous corporate bloat on the Windows machine made the simple act of rebooting into a 5 minute ordeal, not to mention the mess that 20 Subversion based source code checkouts caused when compounded with the virus scanner and the backup software.</p>
<p>Being an open source developer and loving anything free, as in beer and speech, this article will focus on free applications even if there is a more capable commercial solution available.  I hope this article saves you some time on your journey from Windows to OS X as your Java development platform.</p>
<h2>Java Development Tools</h2>
<h3>Installing the JDK</h3>
<p>It is pre-installed.  The version you get depends on the version of OS X you have installed.  I&#8217;m lucky and only need Java 1.6 right now so I haven&#8217;t had to deal with the concurrent Java versions problems that don&#8217;t seem to be going away any time soon; however, there is no free lunch in software development.  The system JDK does not come with src.jar, nor should you probably go mucking around in there customizing the endorsed directory or other common developer tweaks.</p>
<p>Since the bundled JVM isn&#8217;t the blessing it initially appears to be, I ended up downloading the JDK again from Apple at <a href="http://connect.apple.com/" target="_blank">http://connect.apple.com</a>.  This site requires registration.  You can register for free as a &#8220;Registered Apple Developer&#8221;.  This may not be immediately obvious as most pages only mention the paid options.  Got to <a href="http://developer.apple.com/programs/register/" target="_blank">http://developer.apple.com/programs/register/</a> to create your account and then go back to connect.apple.com to download a JDK for your version of OS X.  This JDK will install in /Library/Java/JavaVirtualMachines instead of /System/Library/Java/JavaVirtualMachines.  This JDK also comes with src.jar.  You will want to use this JDK in Eclipse or associate its src.jar with the JARs in the bundled JDK if they are the same version and you don&#8217;t want to use the self-installed JDK for some reason.</p>
<h3>Looking at the JDK files</h3>
<p>Java installations on OS X are packaged in what appears as a file ending with .jdk in Finder.  If you right-click in Finder and select &#8220;Show Package Contents&#8221;, you can get at the guts of the installation in Finder.  The .jdk &#8220;file&#8221; is just a directory and you can navigate to it and through it in the shell without issue.  The typical folder structure you see on Windows is located in the Contents/Home folder inside of the .jdk &#8220;file&#8221;.  This is the path you would point Eclipse to when adding a JDK.  Note that you will likely need to paste the path into Eclipse because the Java file browser wouldn&#8217;t navigate into the .jdk file when I tried to do it that way.  Just paste the complete path into Eclipse, for example /Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk/Contents/Home.</p>
<h3>Picking the default Java version</h3>
<p>In general, this is controlled by the Java Preferences application located in /Applications/Utilities.  You can launch it from the Dock or from a shell with the following command</p>
<pre>open /Applications/Utilities/Java\ Preferences.app/</pre>
<p>By the way, applications in OS X appear as a .app file.  Just like the .jdk file, they are really a directory that appears as a file in Finder.  You can view the contents in Finder the same way you would view the contents of a .jdk file.  There are other, more brute force approaches to changing the Java version, but I thankfully haven&#8217;t had to use them.  I can&#8217;t comment on how well they work so I won&#8217;t include a discussion of them here.</p>
<h2>Maven and Ant</h2>
<p>Maven and Ant were pre-installed on my OS X 10.6 installation.  The pre-installed versions I got thankfully aligned with the versions I am currently using for development so I haven&#8217;t needed to mess with either of these yet.</p>
<h3>IDEs</h3>
<p>I primarily use Eclipse these days.  Just download extract and run Eclipse.app.  Install your regular plug-in set and you are on your way to developing in Java on OS X.  I cover installing Subclipse in the version control section later in the article.</p>
<h2>General Tools</h2>
<ul>
<li><strong>Instant Messaging (AIM, Jabber, etc.)</strong> &#8211; I was using Pidgin so <a href="http://adium.im/" target="_blank">Adium</a> was the natural choice on OS X.  I have been very happy with it so far.</li>
<li><strong>IRC</strong> &#8211; I was using X-Chat on Windows and found that it did what I needed it to do.  There is a <a href="http://sourceforge.net/projects/xchataqua/" target="_blank">X-Chat Aqua</a> for OS X; however, I found its notification configuration to be a bit daunting.  I don&#8217;t watch the chat traffic unless I get mentioned and I found that <a href="http://colloquy.info/" target="_blank">Colloquy</a> made it very straight forward to configure notifications.  If you play with the themes a little you can also configure the layout to mimic X-Chat or mIRC.</li>
<li><strong>New Feeds / RSS</strong> &#8211; I was using FeedDemon on Windows.  <a href="http://netnewswireapp.com/" target="_blank">NetNewsWire</a> comes close to the feature set of FeedDemon with Google Reader integration, but it currently lacks OAuth support so you can&#8217;t use it to read your Twitter stream.</li>
<li><strong>SSH / Putty</strong> &#8211; OS X, being all unix like, has SSH already available from the shell.  One thing I liked about Putty was that it was easy to store configurations for server names, tunnels, etc.   <a href="http://www.grepsoft.net/jellyfissh.html" target="_blank">JellyFiSSH</a> provides a nice session management GUI over the ssh program.</li>
<li><strong>File Transfer / SCP/ SFTP</strong> &#8211; On Windows, I found WinSCP to provide a nice GUI for managing files on a remote system.  In OS X, <a href="http://cyberduck.ch/" target="_blank">Cyberduck</a> provides the same features and more.</li>
<li><strong>Task Manager</strong> &#8211; The OS X equivalent is called Activity Monitor.  It is in /Applications/Utilities.  Activity Monitor provides everything that was available in Task Manager and a lot more.  This is a nice GUI alternative to using <em>ps</em> in a shell.</li>
<li><strong>Multiple Monitor Utilities</strong> &#8211; On Windows I&#8217;ve used a number of tools over the years to mimic Exposé/Spaces and to put a fully functional task bar on my second monitor.  Exposé and Spaces are part of OS X; however, I found it annoying to have to go back to the primary monitor any time I wanted to use a menu in a program.  <a href="http://blog.boastr.net/?page_id=79" target="_blank">SecondBar</a> clones most of the primary menu bar and lets you move it wherever you want.  Sometimes it gets out of synch with the current app and you have to switch focus from the app and back again to update it.  Otherwise, it does what I want.</li>
<li><strong>Archive File / WinZip</strong> &#8211; While later versions of Windows have built-in support for .zip files, WinZip was great for opening .jar files and doing more advanced archival operations.  OS X has native support for archives; however, this support only seems to include the ability to make them and extract them in their entirety.  <a href="http://www.zipeg.com/" target="_blank">Zipeg</a> allows you to explore a number of archive formats and extract portions.  Zipeg does not provide Quick Look support though nor does it have every feature under the sun.  <a href="http://macitbetter.com/" target="_blank">BetterZip</a>, a commercial application, has more features than Zipeg but will cost you $20.  As I mentioned earlier, I am a big fan of free, so I use the free <a href="http://macitbetter.com/BetterZip-Quick-Look-Generator" target="_blank">BetterZip Quick Look Generator</a> for quick look support and Zipeg when I actually need to dig into an archive and muck around.</li>
<li><strong>Text Editing / Notepad++</strong> &#8211; On Windows I loved Notepad++ and the many plug-ins available for it.  I do a lot of work with XML messages and output files so something with tabs, syntaxt highlighting, and compare/diff support is critical.  On the free front, <a href="http://www.barebones.com/products/textwrangler/">TextWrangler</a> gets the job done.  Since a lot of the XML I work with is not formatted for human consumption, the ability to pretty print XML is a must have.  Text Wranger does not have this capability out of the box, but it can <a href="http://www.entropy.ch/blog/Developer/2008/04/23/XML-Pretty-Printing-in-BBEdit-and-vi-With-xmllint.html">integrate with shell scripts</a> to get the job done.</li>
<li><strong>Open Command Here</strong> &#8211; On Windows, the Open Command Here Power Toy was a life saver. Ever need a shell opened to a folder you were browsing in Explorer?  This little context menu addition made it a snap.  There are a number of Finder droplets that will perform this action in OS X; however, I prefer the action to reside in the context menu and I couldn&#8217;t stand how the droplets interpreted the root folder in list view as the current folder even when I highlighted another folder.  <a href="http://blog.leenarts.net/2009/09/03/open-service-here/">Open Terminal Here Service</a> to the rescue.  This one places the entry in the context menu and works with the folder you right-clicked on.</li>
</ul>
<h2>Version Control</h2>
<h3>Subversion</h3>
<p>On Windows, TortoiseSVN coupled with the command line tools and <a href="http://www.orcaware.com/svn/wiki/Svnmerge.py">svnmerge</a> covered my needs.  Svnmerge is written in Python and transitions to OS X without a hitch, unfortunately, there is no full featured free alternative to TortoiseSVN.  I got close enough using a combination of the following tools:</p>
<ol>
<li><a href="http://subclipse.tigris.org/servlets/ProjectProcess?pageID=p4wYuA">Subclipse</a> &#8211; The fantastic Eclipse plug-in that you should be using even if you aren&#8217;t on OS X.</li>
<li><a href="http://www.open.collab.net/downloads/community/">Subversion</a> &#8211; Aside from being the easiest way to get Subclipse working, this also provides the rest of Subversion in binary form.</li>
<li><a href="http://www.lachoseinteractive.net/en/community/subversion/svnx/features">SvnX</a> &#8211; Not quite TortoiseSVN; however, it does have a repository browser and support for working with local Subversion working copies.  This is a nice tool when you don&#8217;t want to fire up Eclipse just to browse a remote repository.</li>
<li><a href="http://scplugin.tigris.org/">SCPlugin</a> &#8211; This aims at providing TortoiseSVN like features for OS X, but is still way too immature to make the comparison. The directory icons don&#8217;t work in OS X 10.6; however, the Finder droplet does work and provides a quick way to do simple SVN commands in Finder until you are ready to just move completely to the command line.  This one will likely be removed in the next couple weeks as I don&#8217;t use it often.</li>
</ol>
<h3>Git</h3>
<p>I was not a big Git user on Windows; however, everyone seems to be in a love affair with Git so I will cover it here.  My Git environment on OS X is as follows:</p>
<ol>
<li><a href="http://www.eclipse.org/egit/">EGit</a> &#8211; This is like Subclipse, but for Git.</li>
<li><a href="http://code.google.com/p/git-osx-installer/">Git</a> &#8211; This provides the command line tooling for Git.</li>
<li><a href="https://github.com/brotherbard/gitx/downloads">GitX</a> &#8211; GitX provides a polished GUI when compared to the GUI bundled with the Git tooling and also provides a GUI for helping you to stage files for a commit.  There is some overlap with what EGit provides, but as with TortoiseSVN and SvnX, it is nice to have a tool outside of Eclipse sometimes.</li>
<li><a href="http://code.google.com/p/git-osx-installer/wiki/OpenInGitX">OpenInGitX</a> &#8211; Not the context menu item I long for, but it does provide a droplet for Finder that allows you to launch GitX on a folder from the Gui.</li>
</ol>
<h2>Things that OS X just doesn&#8217;t make easy</h2>
<h3>Closing the lid without going to sleep</h3>
<p>Every time you close the lid, OS X puts the laptop to sleep.  I really hate this because I often move around in the same building and I don&#8217;t want all of my network connection to time out when I do.  Digging out key fobs to reconnect to a VPN and finding that the 600MB .iso download died gets old fast.  <a href="http://www.macupdate.com/app/mac/22211/insomniax">InsomniaX</a> lets you shut the lid without putting the machine to sleep.</p>
<h3>Locking the laptop without logging out</h3>
<p>You don&#8217;t want to log out and close all of your running applications every time that you need to get a drink, stretch your legs, or go to the bathroom.  I&#8217;ve found two main ways to deal with this.</p>
<ol>
<li>If you have the system configured to lock the laptop when resuming from screensaver/screen blank, you can press Shitf-Control-Eject to turn off the monitor.  The machine will lock after the grace period defined in your system preferences.</li>
<li>You can enable fast user switching or use any of the couple other methods outlined <a href="http://www.macworld.com/article/49080/2006/01/lockscreen.html">here</a>.</li>
</ol>
<h3>Setting environment variables for shell and GUI applications</h3>
<p>For the shell, you can simply use any of the well-known ways to set environment variables.  But what do you do if your GUI application requires the variables too.  OS X stores variables in ~/.MacOSX/environment.plist (note you won&#8217;t be able to see this in Finder by default and you will probably have to create it yourself).  Plist files are XML files these days, but it helps to have an editor.  There is an editor in the XCode bundle, but that is 650MB that expands to several GBs of stuff that you probably won&#8217;t use a lot.  <a href="http://www.nightproductions.net/prefsetter.html">Pref Setter</a> is a lightweight editor for .plist files that also shows you many of the .plist files on your system that are waiting for you to tweak.  This <a href="http://developer.apple.com/library/mac/#qa/qa2001/qa1067.html">article</a> discusses creating an environment.plist file.  Keep in mind that you will need to log out and back in before the changes take place.</p>
<h3>Showing hidden files in Finder</h3>
<p>Finder doesn&#8217;t show you hidden file.  Finder doesn&#8217;t have an accessible configuration option to show you hidden files.  Finder drives me crazy most of the time.  With this tip, you can bend Finder to your will and hopefully stay sane a little longer.  From a shell, you can execute the following commands to enable how and hide hidden files in Finder, respectively.</p>
<pre>defaults write com.apple.Finder AppleShowAllFiles TRUE

defaults write com.apple.Finder AppleShowAllFiles FALSE</pre>
<p>After making this change, you will need to restart finder.  You can do that by option clicking on Finder in the dock and selecting relaunch.  I wrote a simple shell script that sets the property and put it in a folder on the path.  This makes it simple to run the script from anywhere in a shell, although I don&#8217;t think I have turned hiding back on for weeks now.</p>
<h3>Setting the title of a Terminal window</h3>
<p>I usually have more than one Terminal window open and often I have a couple tabs in each window.  With so many sessions open and nothing really differentiating between them visually in Exposé, I find it nice to name the windows/tabs for easy identification.  In Windows, the <em>title</em> command allowed you to easily set the window title.  The following command will change the title of the Terminal window or tab.</p>
<pre>echo -n -e "&#092;033]0;&lt;YOUR_TITLE_HERE&gt;&#092;007"</pre>
<p>That is a lot to remember so I recommend replacing &lt;YOUR_TITLE_HERE&gt; with $1 and putting this in a script named title.  Put the script on the path and you can execute</p>
<pre>title &lt;YOUR_TITLE_HERE&gt;</pre>
<p>from anywhere in a shell.</p>
<h3>Opening two instances of the same application</h3>
<p>Click on the alias or the .app file as many times as you like, OS X isn&#8217;t going to do it.  I often run two copies of Eclipse, one for stuff I am working on related to this blog or an open source project, and another with client code.  I switch back and forth and don&#8217;t always want to close one instance and lose its current state.  My machine has 8GB of memory so it really doesn&#8217;t care if I leave another copy of Eclipse running all day on another screen.  You can launch a separate instance of Eclipse from the shell using the following command.</p>
<pre>open -n &lt;PATH_TO_APP_FILE&gt;</pre>
<h3>How Trash works on your hard disk and on removable media</h3>
<p><a href="http://www.thexlab.com/faqs/trash.html">This</a> article explains how Trash works in general and on removable media of varying types.  I was a little surprised when I deleted a file off of a thumb stick only to find that the stick was still full because the file ended up in the trash folder on the thumb stick.  Give the article a read so you know what to expect.</p>
<h2>Things I haven&#8217;t figured out yet</h2>
<p>The following is a short list of stuff that I wish worked or for which I haven&#8217;t yet found a way around.</p>
<ol>
<li>Native VPN client support for split DNS.  Support for this configuration in OS X 10.6 is just broken.</li>
<li>Finder kills me sometimes.  I wish it had tabs, dual view, or at the very least a folder tree view like Explorer did in Windows.  I&#8217;ve seen a number of commercial add-ons or replacements, but haven&#8217;t tried any yet.</li>
<li>A &#8220;move to other monitor and resize proportional&#8221; button in the title bar of windows.  UltraMon had this in Windows and I found it very useful since I have my external monitor in portrait orientation and windows moved from one monitor are often inappropriately sized on the other.</li>
<li>Deleting something from Finder without going through the trash first, as with shift-delete in Windows.  I&#8217;ve seen a number of scripts, but I haven&#8217;t been brave enough to try any yet.</li>
</ol>
<p>If anyone has recommendations for these unresolved items, or suggestions relating to any of the things mentioned in this article, leave a comment and I will check it out.</p>
<br /> Tagged: <a href='http://davidvaleri.wordpress.com/tag/git/'>git</a>, <a href='http://davidvaleri.wordpress.com/tag/java/'>java</a>, <a href='http://davidvaleri.wordpress.com/tag/os-x/'>os x</a>, <a href='http://davidvaleri.wordpress.com/tag/svn/'>svn</a>, <a href='http://davidvaleri.wordpress.com/tag/tools/'>tools</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvaleri.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvaleri.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvaleri.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvaleri.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvaleri.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvaleri.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvaleri.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvaleri.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvaleri.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvaleri.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvaleri.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvaleri.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvaleri.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvaleri.wordpress.com/118/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvaleri.wordpress.com&amp;blog=15062177&amp;post=118&amp;subd=davidvaleri&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvaleri.wordpress.com/2010/12/23/how-i-learned-to-stop-worrying-and-love-os-x-for-java-development/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bcc5eab278c97ad0d3adb502001031bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dvaleri</media:title>
		</media:content>

		<media:content url="http://davidvaleri.files.wordpress.com/2010/12/command_key.png" medium="image">
			<media:title type="html">command_key</media:title>
		</media:content>
	</item>
		<item>
		<title>Using NSS for FIPS 140-2 compliant message security in CXF</title>
		<link>http://davidvaleri.wordpress.com/2010/12/16/using-nss-for-fips-140-2-compliant-message-security-in-cxf/</link>
		<comments>http://davidvaleri.wordpress.com/2010/12/16/using-nss-for-fips-140-2-compliant-message-security-in-cxf/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 11:00:36 +0000</pubDate>
		<dc:creator>David Valeri</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cxf]]></category>
		<category><![CDATA[nss]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[ws-*]]></category>
		<category><![CDATA[ws-s]]></category>

		<guid isPermaLink="false">http://davidvaleri.wordpress.com/?p=101</guid>
		<description><![CDATA[If you have ever supported a client in the US Government, civil or otherwise, you have probably heard of the FIPS 140-2 compliance requirements for cryptographic operations.  If you haven’t, stick around a little longer and it will eventually ruin &#8230; <a href="http://davidvaleri.wordpress.com/2010/12/16/using-nss-for-fips-140-2-compliant-message-security-in-cxf/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvaleri.wordpress.com&amp;blog=15062177&amp;post=101&amp;subd=davidvaleri&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you have ever supported a client in the US Government, civil or  otherwise, you have probably heard of the FIPS 140-2 compliance  requirements for cryptographic operations.  If you haven’t, stick around  a little longer and it will eventually ruin your day.  This article  discusses how to use free open-source software to provide FIPS 140-2  compliant message-level security in Apache CXF’s SOAP over HTTP Web  services.</p>
<p>This article builds on the setup described in my previous article <a title="Using NSS for FIPS 140-2 compliant transport security in CXF" href="http://davidvaleri.wordpress.com/2010/10/19/using-nss-for-fips-140-2-compliant-transport-security-in-cxf/" target="_blank">Using NSS for FIPS 140-2 compliant transport security in CXF</a> by adding a WS-Security compliant digital signature over portions of the message as well as using WS-Security to encrypt portions of the message.  Refer to my previous post for details on FIPS and configuring NSS in Java.</p>
<p>These same features are also available in <a href="http://fusesource.com/products/enterprise-cxf/" target="_blank">FUSE Services Framework</a>, a freely distributed  enterprise ready distribution of CXF available with various <a href="http://fusesource.com/enterprise-support/support-offerings/" target="_blank">subscription options</a>.</p>
<p><span id="more-101"></span></p>
<h2>It all worked in the article about NSS, TLS, and FIPS, does it all just work with WS-Security too?</h2>
<p>In short, no.  There are a couple of important aspects/features/limitations of the Sun PKCS#11 provider that prevents things from just working with WSS4J and NSS in all cases.  If you are using NSS as the key store, any case where WSS4J needs to resolve a public certificate in the key store that is not paired with a private key causes issues.</p>
<p>The rundown of what works and what doesn&#8217;t work is as follows:</p>
<ol>
<li>Creating signatures with an embedded security token (e.g. an embedded BinarySecurityToken containing an X509 certificate) works</li>
<li>Verifying signatures with an embedded security token (e.g. an embedded BinarySecurityToken containing an X509 certificate) works</li>
<li>Creating signatures with an external security token (e.g. an Issuer Serial reference to an X509 certificate) reference works</li>
<li>Verifying signatures with an external security token reference (e.g. an Issuer Serial reference to a X509 certificate) does <strong>not</strong> work</li>
<li>Creating encrypted content that uses the public part of an asymmetric key pair to conceal a symmetric key does <strong>not</strong> work</li>
<li>Verifying encrypted content works</li>
</ol>
<p>The reason some of the above scenarios don&#8217;t work has to do with the Sun PKCS#11 provider and how it interacts with end-user certificates in the NSS database.  That is, certificates that are not paired with a private key and are not a CA certificate.</p>
<p>Item 4 in Appendix B of the PKCS#11 guide states:</p>
<blockquote><p>Each certificate not part of a private key entry (as the end entity certificate) is checked whether it is trusted. If the CKA_TRUSTED attribute is true, then a KeyStore trusted certificate entry is created with the CKA_LABEL value as the KeyStore alias. If the certificate has no CKA_LABEL, or if multiple certificates share the same CKA_LABEL, then the alias is derived as described above.If the CKA_TRUSTED attribute is not supported then no trusted certificate entries are created.</p></blockquote>
<p>This statement would indicate that in the ideal case, an alias will be added to the Java KeyStore object for each &#8220;trusted&#8221; certificate in the NSS database.  In practice, when using the NSS provider in FIPS mode, any end-user certificate that is not paired with a private key in the database and is not a CA certificate, will be excluded from the listed aliases in the Java KeyStore.  Consequently, WSS4J will not be able to perform the needed certificate look up for verification of externally referenced security tokens using the NSS provided key store.  If you need support for this type of token reference, the only option is to extend  WSS4J&#8217;s <em>org.apache.ws.security.components.crypto.Merlin</em> class or one of its ancestors to provide an alternate mechanism for resolving external security token references.  This is not a bug in CXF, WSS4J, or NSS.  NSS exposes the trusted end-user certificates to the JVM.  It is the Sun PKCS#11 provider that chooses not to expose the end-user certificates through the created Java KeyStore.</p>
<h2>Putting it all together – Setting up NSS, the JVM, WSS4J, and CXF</h2>
<h3>Quick Links</h3>
<p>This section contains a single location for links to the major resources mentioned in the <em>Putting it all together</em> section.</p>
<ul>
<li>Explanation of FIPS and how to configure NSS in the JVM &#8211; <a title="Using NSS for FIPS 140-2 compliant transport security in CXF" href="http://davidvaleri.wordpress.com/2010/10/19/using-nss-for-fips-140-2-compliant-transport-security-in-cxf/" target="_blank">Using NSS for FIPS 140-2 compliant transport security in CXF</a></li>
<li>Example Source Code SVN Location – <a href="https://davidvaleri.googlecode.com/svn/projects/examples/cxf-wss-fips/tags/cxf-wss-fips-1.0" target="_blank">https://davidvaleri.googlecode.com/svn/projects/examples/cxf-wss-fips/tags/cxf-wss-fips-1.0</a></li>
<li>WS-Security Specification &#8211; <a href="http://www.oasis-open.org/committees/download.php/16790/wss-v1.1-spec-os-SOAPMessageSecurity.pdf" target="_blank">http://www.oasis-open.org/committees/download.php/16790/wss-v1.1-spec-os-SOAPMessageSecurity.pdf</a></li>
</ul>
<h3>Setting up NSS and setting up the JVM</h3>
<p>Read the sections titled Setting up NSS and Setting Up the JVM in my <a href="http://davidvaleri.wordpress.com/2010/10/19/using-nss-for-fips-140-2-compliant-transport-security-in-cxf/" target="_blank">previous post</a> about NSS.</p>
<h3>Setting up WSS4J</h3>
<p>CXF uses the WSS4J library to provide WS-Security operations over SOAP messages.  WSS4J provides configuration options that allow for the use of custom key store providers as well as algorithm sources.  By default, WSS4J installs the <a href="http://www.bouncycastle.org/java.html" target="_blank">Bouncy Castle</a> provider and the <a href="http://incubator.apache.org/projects/juice.html" target="_blank">JuiCE</a> provider if they are available on the classpath.  As Bouncy Castle is not a FIPS approved crypto implementation, the first step to achieving compliance is to remove the provider JAR from the class path.  The following XML fragment excludes the Bouncy Castle artifact from the Maven 2 transitive dependency resolution process.</p>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;dependency&gt;
  &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
  &lt;artifactId&gt;cxf-rt-ws-security&lt;/artifactId&gt;
  &lt;version&gt;${cxf.version}&lt;/version&gt;
  &lt;scope&gt;runtime&lt;/scope&gt;
  &lt;exclusions&gt;
    &lt;exclusion&gt;
      &lt;groupId&gt;org.bouncycastle&lt;/groupId&gt;
      &lt;artifactId&gt;bcprov-jdk15&lt;/artifactId&gt;
    &lt;/exclusion&gt;
  &lt;/exclusions&gt;
&lt;/dependency&gt;
</pre></p>
<p>Once Bouncy Castle is off the class path, the built-in provider can still provide algorithm implementations for some algorithms used by WSS4J.  If you are not replacing the built-in provider, WSS4J needs to be configured to retrieve its algorithm implementations from a specific provider.  The following code fragment demonstrates how to configure the provider that WSS4J will use.</p>
<p><pre class="brush: java; wrap-lines: false;">

JCEMapper.setProviderId(&quot;SunPKCS11-nss-client&quot;);

</pre></p>
<p>Line 1 in the above code fragment sets the provider name used by WSS4J when retrieving algorithm implementations.  The provider name specified is derived from the name property in the PKCS#11 configuration file that loads NSS into the JVM.  Refer to my earlier blog post for details on the contents of this file.</p>
<p>The configuration options above direct WSS4J to use the proper provider for retrieving algorithm implementations; however, we still need to configure WSS4J to use the NSS PKCS#11 provider as a key and trust store.  The following XML fragment represents the WSS4J configuration properties needed to use the NSS key store.</p>
<p><pre class="brush: xml; wrap-lines: false;">

&lt;!-- Define a Properties object with the properties required by the
 org.apache.ws.security.components.crypto.Merlin WSS4j Crypto implementation.
 This crypto config is used for signature creation and validation. --&gt;
&lt;util:properties id=&quot;signatureProperties&quot;&gt;
  &lt;!-- Defines the implementation class. --&gt;
  &lt;prop key=&quot;org.apache.ws.security.crypto.provider&quot;&gt;org.apache.ws.security.components.crypto.Merlin&lt;/prop&gt;
  &lt;!-- Defines the location, on the classpath, of the keystore file.  Also
       takes URL or file path. Not applicable when using PKCS 11. --&gt;
  &lt;!-- &lt;prop key=&quot;org.apache.ws.security.crypto.merlin.file&quot;&gt;&lt;/prop&gt;  --&gt;
  &lt;!-- The type of the keystore pointed to by org.apache.ws.security.crypto.merlin.file. --&gt;
  &lt;prop key=&quot;org.apache.ws.security.crypto.merlin.keystore.type&quot;&gt;PKCS11&lt;/prop&gt;
  &lt;!-- The crypto provider that can load the keystore. --&gt;
  &lt;prop key=&quot;org.apache.ws.security.crypto.merlin.keystore.provider&quot;&gt;SunPKCS11-nss-client&lt;/prop&gt;
  &lt;!-- The password for the keystore file. --&gt;
  &lt;prop key=&quot;org.apache.ws.security.crypto.merlin.keystore.password&quot;&gt;Password12345!&lt;/prop&gt;
  &lt;!-- The alias for the default private key to use.  Not required.
  &lt;prop key=&quot;org.apache.ws.security.crypto.merlin.keystore.alias&quot;&gt;&lt;/prop&gt; --&gt;
  &lt;prop key=&quot;org.apache.ws.security.crypto.merlin.cert.provider&quot;&gt;&lt;/prop&gt;
  &lt;!-- If the JVM cacerts file contents should be loaded into the trust chain. --&gt;
  &lt;prop key=&quot;org.apache.ws.security.crypto.merlin.load.cacerts&quot;&gt;false&lt;/prop&gt;
  &lt;!-- If the JVM cacerts file is used, the password for the file.
  &lt;prop key=&quot;org.apache.ws.security.crypto.merlin.cacerts.password&quot;&gt;&lt;/prop&gt; --&gt;
&lt;/util:properties&gt;
</pre></p>
<ul>
<li>Line 11 &#8211; This line indicates that WSS4J should use a PKCS#11 provider for its key store.</li>
<li>Line 13 &#8211; This line indicates the PKCS#11 provider name used to provide the key store.  This name matches with the name provided in the PKCS#11 configuration file used to load NSS.</li>
<li>Line 15 &#8211; This line provides the password needed to access the key store.</li>
</ul>
<h2>Running the example code</h2>
<p>To run the example code you must have the following:</p>
<ol>
<li>Maven 2.2.1</li>
<li>Java 1.6</li>
<li>NSS 3.12.4</li>
</ol>
<p>To run the example, you must first install or build NSS.  Get the binary or source distribution from the <a href="ftp://ftp.mozilla.org/pub/mozilla.org/security/nss/releases/NSS_3_12_4_RTM/" target="_blank">Mozilla FTP server</a> and follow the instructions above for configuring the needed environment variables.</p>
<p>Create an environment variable named “NSS_HOME” and set its value to  be the path to the directory containing the NSS libraries.  The example  project uses this environment variable to locate your NSS installation  directory and generate configuration files for the PKCS#11 provider for  you.</p>
<p>Next, checkout the code from <a href="https://davidvaleri.googlecode.com/svn/projects/examples/cxf-wss-fips/tags/cxf-wss-fips-1.0" target="_blank">https://davidvaleri.googlecode.com/svn/projects/examples/cxf-wss-fips/tags/cxf-wss-fips-1.0</a> using a subversion client of your choice.</p>
<p>From the checkout folder, use a shell to execute:</p>
<pre> mvn -P server</pre>
<p>From the checkout folder, use another shell to execute:</p>
<pre>mvn -P client</pre>
<p>The server log output is written to the file at <em>target/surefire-reports/valeri.blog.examples.cxf_wss_fips.CustomerServiceRunner.out</em></p>
<h3>Additional Options</h3>
<ul>
<li>You can enable JSSE log output by adding -Djsse.debug=all to either of the commands above.</li>
<li>You can modify the log output to contain more details by editing the log4j.properties file in <a href="https://davidvaleri.googlecode.com/svn/projects/examples/cxf-wss-fips/tags/cxf-wss-fips-1.0/src/test/resources/" target="_blank">src/test/resources</a>.</li>
<li>You can access the service WSDL at <a href="https://localhost:8443/services/CustomerService?wsdl" target="_blank">https://localhost:8443/services/CustomerService?wsdl</a> using a Web browser.  You will want to add the example’s CA certificate  to your browser’s trust store and add the client’s identity to your  client’s key store.  The .crt and .pk12 files, as well as JKS files that  contain these certificates and keys are available in <a href="https://davidvaleri.googlecode.com/svn/projects/examples/cxf-wss-fips/tags/cxf-wss-fips-1.0/src/test/resources/" target="_blank">src/test/resources</a>.   The password for these files is “password”.  Note that you should  remove the example CA from your browser when finished to avoid a  potential security threat.  The example CA key used here is available in  the Subversion repository and could be used by anyone to generate  additional client or server certificates for malicious purposes.   Leaving the CA in your browser’s trust store leaves you vulnerable.</li>
</ul>
<h2>What else should I know?</h2>
<ol>
<li>If you are this concerned about cryptographic operations, You really  should be running a security manager to prevent application code from  altering the container JVM’s security configuration.</li>
<li>You may be required to remove additional non-FIPS validated providers from the JVM to meet accreditation guidelines.</li>
<li>This is just an example and I am not claiming that it will be 100% in-line with your security requirements.</li>
</ol>
<br /> Tagged: <a href='http://davidvaleri.wordpress.com/tag/cxf/'>cxf</a>, <a href='http://davidvaleri.wordpress.com/tag/nss/'>nss</a>, <a href='http://davidvaleri.wordpress.com/tag/security/'>security</a>, <a href='http://davidvaleri.wordpress.com/tag/ws/'>ws-*</a>, <a href='http://davidvaleri.wordpress.com/tag/ws-s/'>ws-s</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvaleri.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvaleri.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvaleri.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvaleri.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvaleri.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvaleri.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvaleri.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvaleri.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvaleri.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvaleri.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvaleri.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvaleri.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvaleri.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvaleri.wordpress.com/101/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvaleri.wordpress.com&amp;blog=15062177&amp;post=101&amp;subd=davidvaleri&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvaleri.wordpress.com/2010/12/16/using-nss-for-fips-140-2-compliant-message-security-in-cxf/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bcc5eab278c97ad0d3adb502001031bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dvaleri</media:title>
		</media:content>
	</item>
		<item>
		<title>Using NSS for FIPS 140-2 compliant transport security in CXF</title>
		<link>http://davidvaleri.wordpress.com/2010/10/19/using-nss-for-fips-140-2-compliant-transport-security-in-cxf/</link>
		<comments>http://davidvaleri.wordpress.com/2010/10/19/using-nss-for-fips-140-2-compliant-transport-security-in-cxf/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 03:49:07 +0000</pubDate>
		<dc:creator>David Valeri</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cxf]]></category>
		<category><![CDATA[nss]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://davidvaleri.wordpress.com/?p=75</guid>
		<description><![CDATA[If you have ever supported a client in the US Government, civil or otherwise, you have probably heard of the FIPS 140-2 compliance requirements for cryptographic operations.  If you haven&#8217;t, stick around a little longer and it will eventually ruin &#8230; <a href="http://davidvaleri.wordpress.com/2010/10/19/using-nss-for-fips-140-2-compliant-transport-security-in-cxf/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvaleri.wordpress.com&amp;blog=15062177&amp;post=75&amp;subd=davidvaleri&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you have ever supported a client in the US Government, civil or otherwise, you have probably heard of the FIPS 140-2 compliance requirements for cryptographic operations.  If you haven&#8217;t, stick around a little longer and it will eventually ruin your day.  This article discusses how to use free open-source software to provide FIPS 140-2 compliant transport layer security (TLS) in Apache CXF&#8217;s HTTP Web services.  This article is also useful for describing the general steps needed to configure NSS as a security provider in a JVM.</p>
<p><strong>Update:</strong> At the publishing of this article, PKCS#11 support within CXF&#8217;s HTTP/Jetty transports was only available in snapshot releases of 2.4 and 2.3.1.  Now that CXF 2.3.1 has been released, the examples in this post have been updated to use CXF 2.3.1.  This capability also appears in <a href="http://fusesource.com/products/enterprise-cxf/" target="_blank">FUSE Services Framework</a>.</p>
<p><span id="more-75"></span></p>
<h2>What is this FIPS thing?</h2>
<p>FIPS, or the Federal Information Processing Standards, is a collection of documents published by the National Institute of Standards and Technology (NIST) providing guidance on range of computer and telecommunications related topics and standards.  <a href="http://csrc.nist.gov/publications/fips/fips140-2/fips1402.pdf" target="_blank">FIPS publication 140-2</a>, <em>Security Requirements for Cryptographic Modules</em>, deals specifically with cryptography related standards.  Along with the requirements dictated by the publication, there is also the Cryptographic Module Validation Program (CMVP) which certifies cryptography modules against the FIPS 140-2 requirements.  You can see a list of vendors with validated modules at <a href="http://csrc.nist.gov/groups/STM/cmvp/documents/140-1/1401vend.htm" target="_blank">http://csrc.nist.gov/groups/STM/cmvp/documents/140-1/1401vend.htm</a>.  Stated simply, FIPS 140-2 compliant TLS requires using a limited set of algorithms and a validated implementation of said algorithms.</p>
<h2>So what is the rub?</h2>
<p>This is all fine and well if you have a hardware cryptography device, an application server, and/or a commercial software library that provides a FIPS 140-2 validated cryptography module.  But what if, on the off chance, you are working on a project with no budget or you don&#8217;t have one of the aforementioned solutions?  Therein lies the rub.</p>
<h2>Java and NSS to the rescue</h2>
<p>Starting in Java 5, several changes to the cryptographic APIs made it possible to have a Java application interact with tokens and algorithms provided through <a href="http://www.rsa.com/rsalabs/node.asp?id=2133" target="_blank">PKCS#11</a>, the Cryptographic Token Interface Standard.  For more details about the use of the Sun PKCS#11 provider and how to interact with PKCS#11 tokens/algorithms, refer to the <a href="http://download-llnw.oracle.com/javase/6/docs/technotes/guides/security/p11guide.html" target="_blank">Java PKCS#11 Reference Guide</a>.  But JVM PKCS#11 support is only half of the equation.  In order to be FIPS 140-2 compliant, we still need a PKCS#11 implementation that has been through the CMVP.  This is where <a href="http://www.mozilla.org/projects/security/pki/nss/" target="_blank">Network Security Services</a> (NSS) comes in.  NSS is a PKCS#11 compliant cryptographic library from Mozilla that also happens to have passed through the CMVP.  NSS is distributed under the GPL, LGPL, and the MPL.  You can view the CMVP information for NSS on the <a href="http://csrc.nist.gov/groups/STM/cmvp/documents/140-1/1401val2010.htm#1278" target="_blank">NIST  Web site</a>.</p>
<h2>Putting it all together &#8211; Setting up NSS, the JVM, JSSE, and CXF</h2>
<h3>Quick Links</h3>
<p>This section contains a single location for links to the major resources mentioned in the <em>Putting it all together</em> section.</p>
<ul>
<li>NSS Source and Binary Download &#8211; <a href="ftp://ftp.mozilla.org/pub/mozilla.org/security/nss/releases/NSS_3_12_4_RTM/" target="_blank">ftp://ftp.mozilla.org/pub/mozilla.org/security/nss/releases/NSS_3_12_4_RTM/</a></li>
<li>NSS Utility Documentation &#8211; <a href="http://www.mozilla.org/projects/security/pki/nss/tools/modutil.html" target="_blank">modutil</a>, <a href="http://www.mozilla.org/projects/security/pki/nss/tools/certutil.html" target="_blank">certutil</a>, and <a href="http://www.mozilla.org/projects/security/pki/nss/tools/pk12util.html" target="_blank">pk12util</a></li>
<li>Example Source Code SVN Location &#8211; <a href="https://davidvaleri.googlecode.com/svn/projects/examples/cxf-tls-fips/tags/cxf-tls-fips-1.0" target="_blank">https://davidvaleri.googlecode.com/svn/projects/examples/cxf-tls-fips/tags/cxf-tls-fips-1.0</a></li>
<li>Java PKCS#11 Reference Guide &#8211; <a href="http://download-llnw.oracle.com/javase/6/docs/technotes/guides/security/p11guide.html" target="_blank">Java PKCS#11 Reference Guide</a></li>
</ul>
<h3>Setting up NSS</h3>
<p>The first step in putting all the pieces together is to configure NSS.  NSS is a native library which means you will either need to compile it from source or download a compiled binary for your platform.  The latest version to appear in the NIST CMVP list is 3.12.4.  You can find compiled binaries and source for 3.12.4 at <a href="ftp://ftp.mozilla.org/pub/mozilla.org/security/nss/releases/NSS_3_12_4_RTM/" target="_blank">ftp://ftp.mozilla.org/pub/mozilla.org/security/nss/releases/NSS_3_12_4_RTM/</a>.</p>
<p>Once you have built the binaries, or extracted them from the downloaded archive, you will want to 1) add the NSS libraries to the LD_LIBRARY_PATH or PATH environment variable depending on your operating system and 2) add the NSS utilities to the PATH environment variable.  Once installed, you will use the <a href="http://www.mozilla.org/projects/security/pki/nss/tools/modutil.html" target="_blank">modutil</a>, <a href="http://www.mozilla.org/projects/security/pki/nss/tools/certutil.html" target="_blank">certutil</a>, and <a href="http://www.mozilla.org/projects/security/pki/nss/tools/pk12util.html" target="_blank">pk12util</a> utilities to create a database and populate it with key information.  Note that NSS can also be used purely as an algorithm provider without a database.  Refer to the <a href="http://download-llnw.oracle.com/javase/6/docs/technotes/guides/security/p11guide.html" target="_blank">Java PKCS#11 Reference Guide</a> for more details on alternative usage modes.</p>
<p>The following sequence of commands illustrates how to create the database, enable FIPS compliance, and populate the database with some certificates and keys.</p>
<ol>
<li>
<pre>modutil -create -dbdir ./client</pre>
</li>
<li>
<pre>modutil -fips true -dbdir ./client</pre>
</li>
<li>
<pre>modutil -changepw "NSS FIPS 140-2 Certificate DB" -dbdir ./client</pre>
</li>
<li>
<pre>certutil -A -d ./client -t "TCu,,TCu" -n "Test CA 1" -i ./pki/test-ca-1.crt</pre>
</li>
<li>
<pre>pk12util -i ./pki/test-user-1.p12 -n test-user-1 -d ./client</pre>
</li>
</ol>
<p>Command 1 creates a new database in the client directory relative to where the command is executed.  Command 2 enables FIPS compliant mode in the database.  Command 3 changes the password of the FIPS token.  Keep in mind that there are password complexity requirements when FIPS mode is enabled and that the utility will simply report that it was unable to set the password when these minimum complexity requirements are not met.  Command 4 imports a CA certificate into the database under the alias &#8220;Test CA 1&#8243; and sets the trusted usages for the certificate.  Command 5 imports a private key and certificate into the database under the alias &#8220;test-user-1&#8243;.  This sequence of commands can be used to create and populate a database for use on a client or server.  The resulting database can be seen in the example source code in the <em><a href="https://davidvaleri.googlecode.com/svn/projects/examples/cxf-tls-fips/tags/cxf-tls-fips-1.0/src/test/pkcs11/client" target="_blank">src/test/pkcs11/client</a></em> folder.  The password for the database is &#8220;Password12345!&#8221;.</p>
<h3>Setting up the JVM</h3>
<p>Once NSS is installed and an NSS database exists for your client/server, the next step is to configure a JVM to use it.  Java 1.6 provides great support for NSS and will be used exclusively in this example.  One may configure a PKCS#11 provider in the JVM dynamically at runtime or statically in the JVM configuration files.  We will explore both approaches.</p>
<p>Before we can create a PKCS#11 provider in the JVM, we must first create a configuration file for the provider.  The configuration file is a simple text file containing key-value pairs for the relevant configuration options.  There are many options described in the <a href="http://download-llnw.oracle.com/javase/6/docs/technotes/guides/security/p11guide.html" target="_blank">Java PKCS#11 Reference Guide</a>, but this example only needs to use a few.  The example configuration below provides a name for the provider, the location of the library files for NSS and the path to the database that was created earlier.</p>
<pre>name = nss-client
nssLibraryDirectory = /path/to/nss/lib
nssSecmodDirectory = /path/to/db/dir</pre>
<p>Dynamic configuration is performed using the static utility methods of java.security.Security.  The following <a href="https://davidvaleri.googlecode.com/svn/projects/examples/cxf-tls-fips/tags/cxf-tls-fips-1.0/src/test/java/valeri/blog/examples/cxf_tls_fips/SecurityUtil.java" target="_blank">code fragment from the example source code </a>illustrates how to add the PKCS#11 provider and to reconfigure the Java Secure Socket Extension (JSSE) provider to leverage the PKCS#11 provider for FIPS compliant operations.  Note that this code works on the Sun JVM.  Your mileage will vary if you use a different JSSE provider in your JVM or a non-Sun JVM.</p>
<p><pre class="brush: java; wrap-lines: false;">
Provider nss = new sun.security.pkcs11.SunPKCS11(configFile);
Security.addProvider(nss);

int sunJssePosition = -1;
int currentIndex = 0;
for (Provider provider : Security.getProviders()) {
    if (&quot;SunJSSE&quot;.equals(provider.getName())) {
        sunJssePosition = currentIndex + 1;
        break;
    }

    currentIndex++;
}

Security.removeProvider(&quot;SunJSSE&quot;);

Provider sunJsse = new com.sun.net.ssl.internal.ssl.Provider(nss);
if (sunJssePosition == -1) {
    Security.addProvider(sunJsse);
}
else {
    Security.insertProviderAt(sunJsse, sunJssePosition);
}
</pre></p>
<p>The constructor on line 1 creates an instance of the PKCS#11 provider using the configuration file specified by the configFile variable.  This variable represents the file system path to the NSS configuration file described earlier.  Note that the above code must be executed before any network connections using JSSE are established and that the above code requires the correct permissions when a security manager is in place.  For these reasons, dynamic configuration should usually be avoided when running inside of a container or framework such as OSGi and JEE.  Note that the example that accompanies this article uses dynamic configuration simply to reduce the amount of setup required to run the example.</p>
<p>Static configuration is possible at the JVM level.  The $JAVA_HOME/lib/security/java.security file contains definitions of the providers that will be started with the JVM.  The file will have a section resembling the following example.</p>
<pre>security.provider.1=sun.security.provider.Sun
security.provider.2=sun.security.rsa.SunRsaSign
security.provider.3=com.sun.net.ssl.internal.ssl.Provider
security.provider.4=com.sun.crypto.provider.SunJCE
security.provider.5=sun.security.jgss.SunProvider
security.provider.6=com.sun.security.sasl.Provider
security.provider.7=org.jcp.xml.dsig.internal.dom.XMLDSigRI
security.provider.8=sun.security.smartcardio.SunPCSC
security.provider.9=sun.security.mscapi.SunMSCAPI</pre>
<p>To enable the PKCS#11 provider and reconfigure the JSSE provider, change the configuration file to resemble the following.</p>
<pre>security.provider.1=sun.security.provider.Sun
security.provider.2=sun.security.rsa.SunRsaSign
security.provider.3=com.sun.net.ssl.internal.ssl.Provider SunPKCS11-nss-client
security.provider.4=com.sun.crypto.provider.SunJCE
security.provider.5=sun.security.jgss.SunProvider
security.provider.6=com.sun.security.sasl.Provider
security.provider.7=org.jcp.xml.dsig.internal.dom.XMLDSigRI
security.provider.8=sun.security.smartcardio.SunPCSC
security.provider.9=sun.security.mscapi.SunMSCAPI
security.provider.10=sun.security.pkcs11.SunPKCS11 /path/to/nss/config/file</pre>
<p>In the above example, the last line adds the PKCS#11 provider with the appropriate configuration file while the third line configures the JSSE provider to use the PKCS#11 provider for cryptographic operations.  The value &#8220;SunPKCS11-nss-client&#8221; was created by concatenating &#8220;SunPKCS11-&#8221; with the value of the name property from the PKCS#11 configuration file.  In the example configuration file above, the name is nss-client, resulting in the provider name &#8220;SunPKCS11-nss-client&#8221;.</p>
<h3>Configuring the CXF HTTP Transport</h3>
<p>For the server-side configuration, we will be using the PKCS#11 provider with the name configuration attribute of &#8220;nss-server&#8221;.  The configuration uses the CXF Jetty Transport&#8217;s Spring namespace handler for configuration.  More details about this configuration mechanism can be found in the <a href="http://cxf.apache.org/docs/jetty-configuration.html" target="_blank">CXF Jetty Transport documentation</a>.  The relevant lines are described after the following XML fragment.  Click <a href="https://davidvaleri.googlecode.com/svn/projects/examples/cxf-tls-fips/tags/cxf-tls-fips-1.0/src/test/resources/valeri/blog/examples/cxf_tls_fips/service-context.xml" target="_blank">here </a>to view this fragment in context.</p>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;!-- Define the Jetty HTTP server configuration for the CXF bus. --&gt;
&lt;httpj:engine-factory bus=&quot;cxf&quot;&gt;
  &lt;httpj:identifiedTLSServerParameters id=&quot;secure&quot;&gt;
    &lt;httpj:tlsServerParameters secureSocketProtocol=&quot;TLS&quot;&gt;
      &lt;sec:clientAuthentication required=&quot;true&quot; want=&quot;true&quot;/&gt;
      &lt;!-- Define the keystore for the server identity as a classpath resource.
           In a production system, these properties would be encrypted/obfuscated using
           a library such as Jasypt (http://www.jasypt.org/) and Spring's property placeholder
           capabilities. --&gt;
      &lt;sec:keyManagers&gt;
        &lt;sec:keyStore type=&quot;PKCS11&quot; provider=&quot;SunPKCS11-nss-server&quot; password=&quot;Password12345!&quot;/&gt;
      &lt;/sec:keyManagers&gt;
      &lt;sec:trustManagers&gt;
        &lt;!-- In a production system, these properties would be encrypted/obfuscated using
             a library such as Jasypt (http://www.jasypt.org/) and Spring's property placeholder
             capabilities. --&gt;
        &lt;sec:keyStore type=&quot;PKCS11&quot; provider=&quot;SunPKCS11-nss-server&quot; password=&quot;Password12345!&quot;/&gt;
      &lt;/sec:trustManagers&gt;
      &lt;sec:cipherSuitesFilter&gt;
        &lt;sec:include&gt;SSL_RSA_WITH_3DES_EDE_CBC_SHA&lt;/sec:include&gt;
        &lt;sec:include&gt;SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA&lt;/sec:include&gt;
        &lt;sec:include&gt;TLS_RSA_WITH_AES_128_CBC_SHA&lt;/sec:include&gt;
        &lt;sec:include&gt;TLS_DHE_DSS_WITH_AES_128_CBC_SHA&lt;/sec:include&gt;
        &lt;sec:include&gt;TLS_DHE_RSA_WITH_AES_128_CBC_SHA&lt;/sec:include&gt;
        &lt;sec:include&gt;TLS_RSA_WITH_AES_256_CBC_SHA&lt;/sec:include&gt;
        &lt;sec:include&gt;TLS_DHE_DSS_WITH_AES_256_CBC_SHA&lt;/sec:include&gt;
        &lt;sec:include&gt;TLS_DHE_RSA_WITH_AES_256_CBC_SHA&lt;/sec:include&gt;
        &lt;!-- The suites below have been disabled due to
             http://bugs.sun.com/view_bug.do?bug_id=6763530 --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDH_RSA_WITH_AES_128_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDH_RSA_WITH_AES_256_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA&lt;/sec:include&gt;  --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDH_anon_WITH_AES_128_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDH_anon_WITH_AES_256_CBC_SHA&lt;/sec:include&gt; --&gt;
      &lt;/sec:cipherSuitesFilter&gt;
    &lt;/httpj:tlsServerParameters&gt;
  &lt;/httpj:identifiedTLSServerParameters&gt;
  &lt;!-- Define the HTTPS port, crypto configuration, and other properties. --&gt;
  &lt;httpj:engine port=&quot;8443&quot;&gt;
    &lt;httpj:tlsServerParametersRef id=&quot;secure&quot; /&gt;
    &lt;httpj:threadingParameters minThreads=&quot;5&quot; maxThreads=&quot;15&quot; /&gt;
  &lt;/httpj:engine&gt;
&lt;/httpj:engine-factory&gt;
</pre></p>
<ul>
<li>Line 4 &#8211; This line&#8217;s secureSocketProtocol attribute identifies TLS as the desired protocol.  TLS is the only protocol available when in FIPS mode.</li>
<li>Line 5 &#8211; This line specifies that mutual authentication is required.  Not all secure HTTP connections need to use mutual authentication, but this example uses it to demonstrate configuring a key store on the client side as well as on the server side.</li>
<li>Line 11 &#8211; This line specifies the type of key store in use and how to access it for the server&#8217;s identity.  Typically you use a JKS file, but in this example we are using the NSS database accessed through the PKCS#11 provider configured against the NSS database.  Note the provider name identifies the PKCS#11 provider configuration we created for the server NSS database.</li>
<li>Line 18 &#8211; This line specifies the type of key store in use and how to  access it for the server&#8217;s trust configuration.  Typically you use a JKS file, but  in this example we are using the NSS database accessed through the  PKCS#11 provider configured against the NSS database.  Note the provider name identifies the PKCS#11 provider configuration we created for the server NSS database.</li>
<li>Line 21 &#8211; This line and the nested XML content identifies a white list of cipher suites that will be enabled if available.  When configured the JSSE is configured against NSS operating in FIPS mode, only FIPS approved cipher suites will be available; however, some cipher suites trigger issues with the PKCS#11 support in the JVM and are disabled for compatibility reasons.  This configuration is shown as a white list, but could just as easily be configured as a black list using the &lt;sec:exclude&gt; element.</li>
</ul>
<p>For the client-side configuration, we will be using the PKCS#11 provider  with the name configuration attribute of &#8220;nss-client&#8221;.  The  configuration uses the CXF HTTP Transport&#8217;s Spring namespace handler  for configuration.  More details about this configuration mechanism can  be found in the <a href="http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html" target="_blank">CXF HTTP Transport documentation</a>.  The relevant lines are described after the following XML fragment.  Click <a href="https://davidvaleri.googlecode.com/svn/projects/examples/cxf-tls-fips/tags/cxf-tls-fips-1.0/src/test/resources/valeri/blog/examples/cxf_tls_fips/CxfCustomerServiceTest-context.xml" target="_blank">here </a>to view this fragment in context.</p>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;!-- Define the HTTP client configuration for all target service invocations. --&gt;
&lt;http:conduit name=&quot;*.http-conduit&quot;&gt;
  &lt;!-- Define the SSL info for the client connections. --&gt;
  &lt;http:tlsClientParameters secureSocketProtocol=&quot;TLS&quot;&gt;
    &lt;!-- Defines the identity info for the client's connection. --&gt;
    &lt;sec:keyManagers&gt;
      &lt;!-- In a production system, these properties would be encrypted/obfuscated using
           a library such as Jasypt (http://www.jasypt.org/) and Spring's property placeholder
           capabilities. --&gt;
      &lt;sec:keyStore type=&quot;PKCS11&quot; provider=&quot;SunPKCS11-nss-client&quot; password=&quot;Password12345!&quot; /&gt;
    &lt;/sec:keyManagers&gt;
    &lt;!-- Defines the trust info for the client's connection. --&gt;
    &lt;sec:trustManagers&gt;
      &lt;!-- In a production system, these properties would be encrypted/obfuscated using
           a library such as Jasypt (http://www.jasypt.org/) and Spring's property placeholder
           capabilities. --&gt;
      &lt;sec:keyStore type=&quot;PKCS11&quot; provider=&quot;SunPKCS11-nss-client&quot; password=&quot;Password12345!&quot; /&gt;
    &lt;/sec:trustManagers&gt;
    &lt;sec:cipherSuitesFilter&gt;
        &lt;sec:include&gt;SSL_RSA_WITH_3DES_EDE_CBC_SHA&lt;/sec:include&gt;
        &lt;sec:include&gt;SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA&lt;/sec:include&gt;
        &lt;sec:include&gt;TLS_RSA_WITH_AES_128_CBC_SHA&lt;/sec:include&gt;
        &lt;sec:include&gt;TLS_DHE_DSS_WITH_AES_128_CBC_SHA&lt;/sec:include&gt;
        &lt;sec:include&gt;TLS_DHE_RSA_WITH_AES_128_CBC_SHA&lt;/sec:include&gt;
        &lt;sec:include&gt;TLS_RSA_WITH_AES_256_CBC_SHA&lt;/sec:include&gt;
        &lt;sec:include&gt;TLS_DHE_DSS_WITH_AES_256_CBC_SHA&lt;/sec:include&gt;
        &lt;sec:include&gt;TLS_DHE_RSA_WITH_AES_256_CBC_SHA&lt;/sec:include&gt;
        &lt;!-- The suites below have been disabled due to
             http://bugs.sun.com/view_bug.do?bug_id=6763530 --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDH_RSA_WITH_AES_128_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDH_RSA_WITH_AES_256_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA&lt;/sec:include&gt;  --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDH_anon_WITH_AES_128_CBC_SHA&lt;/sec:include&gt; --&gt;
        &lt;!-- &lt;sec:include&gt;TLS_ECDH_anon_WITH_AES_256_CBC_SHA&lt;/sec:include&gt; --&gt;
      &lt;/sec:cipherSuitesFilter&gt;
  &lt;/http:tlsClientParameters&gt;
  &lt;http:client Connection=&quot;Keep-Alive&quot; /&gt;
&lt;/http:conduit&gt;
</pre></p>
<ul>
<li>Line 4 &#8211; This line&#8217;s secureSocketProtocol attribute identifies  TLS as the desired protocol.  TLS is the only protocol available when in  FIPS mode.</li>
<li>Line 10 &#8211; This line specifies the type of key store in use and how  to access it for the client&#8217;s identity.  Typically you use a JKS file,  but in this example we are using the NSS database accessed through the  PKCS#11 provider configured against the NSS database.  Note the provider name identifies the PKCS#11 provider configuration we created for the client NSS database.  Note that the key manager configuration is not necessary on clients not using mutual authentication.</li>
<li>Line 18 &#8211; This line specifies the type of key store in use and how  to  access it for the client&#8217;s trust configuration.  Typically you use a  JKS file, but  in this example we are using the NSS database accessed  through the  PKCS#11 provider configured against the NSS database.  Note  the provider name identifies the PKCS#11 provider configuration we  created for the server NSS database.</li>
<li>Line 21 &#8211; This line and the nested XML content identifies a white list of  cipher suites that will be enabled if available.  When configured the  JSSE is configured against NSS operating in FIPS mode, only FIPS  approved cipher suites will be available; however, some cipher suites  trigger issues with the PKCS#11 support in the JVM and are disabled for  compatibility reasons.  This configuration is shown as a white list, but  could just as easily be configured as a black list using the  &lt;sec:exclude&gt; element.</li>
</ul>
<h2>Running the example code</h2>
<p>To run the example code you must have the following:</p>
<ol>
<li>Maven 2.2.1</li>
<li>Java 1.6</li>
<li>NSS 3.12.4</li>
</ol>
<p>To run the example, you must first install or build NSS.  Get the binary or source distribution from the <a href="ftp://ftp.mozilla.org/pub/mozilla.org/security/nss/releases/NSS_3_12_4_RTM/" target="_blank">Mozilla FTP server</a> and follow the instructions above for configuring the needed environment variables.</p>
<p>Create an environment variable named &#8220;NSS_HOME&#8221; and set its value to be the path to the directory containing the NSS libraries.  The example project uses this environment variable to locate your NSS installation directory and generate configuration files for the PKCS#11 provider for you.</p>
<p>Next, checkout the code from <a href="https://davidvaleri.googlecode.com/svn/projects/examples/cxf-tls-fips/tags/cxf-tls-fips-1.0" target="_blank">https://davidvaleri.googlecode.com/svn/projects/examples/cxf-tls-fips/tags/cxf-tls-fips-1.0</a> using a subversion client of your choice.</p>
<p>From the checkout folder, use a shell to execute:</p>
<pre style="padding-left:30px;"> mvn -P server</pre>
<p>From the checkout folder, use another shell to execute:</p>
<pre style="padding-left:30px;">mvn -P client</pre>
<p>The server log output is written to the file at <em>target/surefire-reports/valeri.blog.examples.cxf_tls_fips.CustomerServiceRunner.out</em></p>
<h3>Additional Options</h3>
<ul>
<li>You can enable JSSE log output by adding -Djsse.debug=all to either of the commands above.</li>
<li>You can modify the log output to contain more details by editing the log4j.properties file in <a href="https://davidvaleri.googlecode.com/svn/projects/examples/cxf-tls-fips/tags/cxf-tls-fips-1.0/src/test/resources/" target="_blank">src/test/resources</a>.</li>
<li>You can access the service WSDL at <a href="https://localhost:8443/services/CustomerService?wsdl" target="_blank">https://localhost:8443/services/CustomerService?wsdl</a> using a Web browser.  You will want to add the example&#8217;s CA certificate to your browser&#8217;s trust store and add the client&#8217;s identity to your client&#8217;s key store.  The .crt and .pk12 files, as well as JKS files that contain these certificates and keys are available in <a href="https://davidvaleri.googlecode.com/svn/projects/examples/cxf-tls-fips/tags/cxf-tls-fips-1.0/src/test/resources/" target="_blank">src/test/resources</a>.  The password for these files is &#8220;password&#8221;.  Note that you should remove the example CA from your browser when finished to avoid a potential security threat.  The example CA key used here is available in the Subversion repository and could be used by anyone to generate additional client or server certificates for malicious purposes.  Leaving the CA in your browser&#8217;s trust store leaves you vulnerable.</li>
</ul>
<h2>What else should I know?</h2>
<ol>
<li>If you are this concerned about cryptographic operations, You really should be running a security manager to prevent application code from altering the container JVM&#8217;s security configuration.</li>
<li>You may be required to remove additional non-FIPS validated providers from the JVM to meet accreditation guidelines.</li>
<li>This is just an example and I am not claiming that it will be 100% in-line with your security requirements.</li>
</ol>
<div id="_mcePaste" class="mcePaste" style="position:absolute;left:-10000px;top:7192px;width:1px;height:1px;overflow:hidden;">
<ul>
<li>Line 4 &#8211; This line&#8217;s secureSocketProtocol attribute identifies  TLS as the desired protocol.  TLS is the only protocol available when in  FIPS mode.</li>
<li>Line 5 &#8211; This line specifies that mutual authentication is  required.  Not all secure HTTP connections need to use mutual  authentication, but this example uses it to demonstrate configuring a  key store on the client side as well as on the server side.</li>
<li>Line 11 &#8211; This line specifies the type of key store in use and how  to access it for the server&#8217;s identity.  Typically you use a JKS file,  but in this example we are using the NSS database accessed through the  PKCS#11 provider configured against the NSS database.  Note the provider name identifies the PKCS#11 provider configuration we created for the server NSS database.</li>
<li>Line 18 &#8211; This line specifies the type of key store in use and how  to  access it for the server&#8217;s trust configuration.  Typically you use a  JKS file, but  in this example we are using the NSS database accessed  through the  PKCS#11 provider configured against the NSS database.  Note  the provider name identifies the PKCS#11 provider configuration we  created for the server NSS database.</li>
<li>Line 21 &#8211; This line and the nested XML content identifies a white list of  cipher suites that will be enabled if available.  When configured the  JSSE is configured against NSS operating in FIPS mode, only FIPS  approved cipher suites will be available; however, some cipher suites  trigger issues with the PKCS#11 support in the JVM and are disabled for  compatibility reasons.  This configuration is show as a white list, but  could just as easily be configured as a black list using the  &lt;sec:exclude&gt; element.</li>
</ul>
</div>
<br /> Tagged: <a href='http://davidvaleri.wordpress.com/tag/cxf/'>cxf</a>, <a href='http://davidvaleri.wordpress.com/tag/nss/'>nss</a>, <a href='http://davidvaleri.wordpress.com/tag/security/'>security</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvaleri.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvaleri.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvaleri.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvaleri.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvaleri.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvaleri.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvaleri.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvaleri.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvaleri.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvaleri.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvaleri.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvaleri.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvaleri.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvaleri.wordpress.com/75/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvaleri.wordpress.com&amp;blog=15062177&amp;post=75&amp;subd=davidvaleri&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvaleri.wordpress.com/2010/10/19/using-nss-for-fips-140-2-compliant-transport-security-in-cxf/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bcc5eab278c97ad0d3adb502001031bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dvaleri</media:title>
		</media:content>
	</item>
		<item>
		<title>Signing WS-Addressing headers in Apache CXF</title>
		<link>http://davidvaleri.wordpress.com/2010/09/15/signing-ws-addressing-headers-in-apache-cxf/</link>
		<comments>http://davidvaleri.wordpress.com/2010/09/15/signing-ws-addressing-headers-in-apache-cxf/#comments</comments>
		<pubDate>Wed, 15 Sep 2010 11:00:00 +0000</pubDate>
		<dc:creator>David Valeri</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cxf]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[ws-*]]></category>

		<guid isPermaLink="false">http://davidvaleri.wordpress.com/?p=55</guid>
		<description><![CDATA[As WS-Addressing (WS-A) headers can drastically affect the behavior of a Web service, securing these headers is just as important as securing the message payload.  In many cases, these headers and other parts of the message will be integrity constrained &#8230; <a href="http://davidvaleri.wordpress.com/2010/09/15/signing-ws-addressing-headers-in-apache-cxf/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvaleri.wordpress.com&amp;blog=15062177&amp;post=55&amp;subd=davidvaleri&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As WS-Addressing (WS-A) headers can drastically affect the behavior of a Web service, securing these headers is just as important as securing the message payload.  In many cases, these headers and other parts of the message will be integrity constrained and bound to each other using a digital signature as described in the WS-Security (WS-S) specification.  The tricky part about signing WS-A headers is that they may or may not always be present in a message and WSS4J uses a static configuration value for which elements to sign.  This static configuration isn&#8217;t an issue in of itself, but when combined with WSS4J&#8217;s behavior when an element to be signed cannot be found in the message, the configuration can result in blank messages being returned from the server.  This article discusses how to dynamically detect and add the WS-A headers to the message signature.</p>
<p><span id="more-55"></span></p>
<h2>WS-Addressing Headers</h2>
<p>WS-Addressing conveys WS-Addressing message addressing properties (MAPs) in a SOAP Header.  These properties can affect the processing of the message and where/how the response message is sent.  The MAPs and their corresponding XML infoset are defined in section 3 of the <a href="http://www.w3.org/TR/ws-addr-core/#msgaddrprops" target="_blank">WS-Addressing 1.0 &#8211; Core</a> specification.  The use of MAPs in a SOAP envelope are described by the <a href="http://www.w3.org/TR/2006/REC-ws-addr-soap-20060509/" target="_blank">WS-Addressing 1.0 &#8211; SOAP Binding</a> specification.  Finally, the requirements for the inclusion of the MAPs in the messages of a WSDL defined service are defined in section 5 of the <a href="http://www.w3.org/TR/2006/WD-ws-addr-wsdl-20060216/#WSDLMEPS" target="_blank">WS-Addressing 1.0 &#8211; WSDL Binding</a> specification.  It is the default values assigned to a MAP in the core specification and the variation in required MAPs for a given WSDL MEP as defined in the WSDL binding specification that combine to create the subtle variances in the presence of the header elements in any given message.  This variance alone does not typically cause any issues unless you are trying to configure WSS4J to sign these header elements.</p>
<h2>The Signing Problem</h2>
<p>When configuring CXF without the help of WS-SecurityPolicy (WS-SP), the list of message elements to be signed is set as a configuration option on the WSS4J out interceptor.  The following code fragment illustrates a typical WSS4J configuration in CXF using CXF&#8217;s Spring integration.</p>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;!-- Configure the outbound WSS4J interceptor. --&gt;
&lt;bean id=&quot;wss4jOutInterceptor&quot;&gt;
  &lt;constructor-arg&gt;
    &lt;!-- The entry keys in this map are defined in
         org.apache.ws.security.handler.WSHandlerConstants
         but are referenced as String literals here for brevity over
         the use of the util:constant element. --&gt;
    &lt;map&gt;
      &lt;entry key=&quot;action&quot; value=&quot;Timestamp Signature&quot; /&gt;
      &lt;!-- This is the fallback user for sig/enc if the sig/enc specific
           properties are not set.  WSS4JOutInterceptor looks for it
           and fails if it is not set. --&gt;
      &lt;entry key=&quot;user&quot; value=&quot;test-service-1 (test-ca-1)&quot; /&gt;

      &lt;!-- Timestamp TTL in seconds. --&gt;
      &lt;entry key=&quot;timeToLive&quot; value=&quot;60&quot; /&gt;

      &lt;!-- The certificate alias in the signature crypto config to sign
           the message with.  The password is retrieved from the callback handler. --&gt;
      &lt;entry key=&quot;signatureUser&quot; value=&quot;test-service-1 (test-ca-1)&quot; /&gt;
      &lt;!-- Signature key attachment method.  We want to put the token
           directly in the header and not use a reference. --&gt;
      &lt;entry key=&quot;signatureKeyIdentifier&quot; value=&quot;DirectReference&quot; /&gt;
      &lt;!-- Defines the property name that contains a Properties object with the desired
           settings in it.  Better than loading a static file from the classpath when using
           Spring. --&gt;
      &lt;entry key=&quot;SignaturePropRefId&quot; value=&quot;signatureProperties&quot; /&gt;
      &lt;!-- The entry that actually contains the Properties object for
           the signature crypto configuration.  See SignaturePropRefId. --&gt;
      &lt;entry key=&quot;signatureProperties&quot; value-ref=&quot;signatureProperties&quot; /&gt;
      &lt;!-- The parts of the response to sign. --&gt;
      &lt;entry key=&quot;signatureParts&quot; value=&quot;{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body;{Element}{http://www.w3.org/2005/08/addressing}Action;{Element}{http://www.w3.org/2005/08/addressing}MessageID...&quot; /&gt;

      &lt;!-- The reference to the callback handler for retrieving passwords
           for private keys in the signature and encryption crypto configurations. --&gt;
      &lt;entry key=&quot;passwordCallbackRef&quot; value-ref=&quot;pwCallback&quot; /&gt;
    &lt;/map&gt;
  &lt;/constructor-arg&gt;
&lt;/bean&gt;
</pre></p>
<p>Line 31 of the preceding XML configures the elements to be signed by WSS4J when it creates the message signature.  If WSS4J cannot find one of the elements listed in the signatureParts configuration entry, it throws an exception.  On the server side, if this exception is throw while handling another fault, say a fault triggered by an inbound security problem, CXF simply gives up and returns an empty response message.  This message is really and truly empty, no SOAP Body, no SOAP Envelope.  Depending on what went wrong to cause the original fault, the current message exchange pattern in use, and the validity of the inbound WS-A headers, CXF can provide some or all of the WS-A headers in a response.  When CXF only provides some of the headers in the response, this static configuration breaks down.</p>
<h2>The Solution</h2>
<p>There are two solutions to this problem in CXF: 1) configure security using WS-SP and 2) dynamically configure the WS-A headers to be signed.  While option 1 solves the problem, it also introduces the complexity of WS-SP.  For those not wishing to or unable to use WS-SP, solution 2 is described below.</p>
<p>The issue above may be resolved by dynamically determining the WS-A headers in the outbound message and adding them to the WSS4J signatureParts configuration option only when present in the message.  This feat is accomplished through the use of a custom CXF interceptor.  The interceptor works by inspecting the outbound message for all possible WS-A headers and adding the present headers to the existing signatureParts configuration property value.</p>
<p>The following code fragments illustrate how to configure this custom interceptor on the server side.  The client side configuration is nearly identical and can be seen in the complete working example in Subversion.</p>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;jaxws:endpoint
  serviceName=&quot;service:CustomerServiceService&quot;
  endpointName=&quot;service:CustomerServicePort&quot;
  address=&quot;http://localhost:8080/services/CustomerService&quot;
  wsdlLocation=&quot;classpath:/wsdl/CustomerService.wsdl&quot;
  implementor=&quot;#defaultCustomerService&quot;&gt;
  &lt;jaxws:features&gt;
    &lt;!-- Configure the WS-Addressing feature. --&gt;
    &lt;addressing:addressing addressingRequired=&quot;true&quot;
      allowDuplicates=&quot;false&quot;/&gt;
  &lt;/jaxws:features&gt;
  &lt;jaxws:inInterceptors&gt;
    &lt;ref bean=&quot;wss4jInInterceptor&quot;/&gt;
  &lt;/jaxws:inInterceptors&gt;
  &lt;jaxws:outInterceptors&gt;
    &lt;ref bean=&quot;wss4jOutInterceptor&quot;/&gt;
    &lt;ref bean=&quot;dynamicWsaSignaturePartsInterceptor&quot;/&gt;
  &lt;/jaxws:outInterceptors&gt;
  &lt;jaxws:outFaultInterceptors&gt;
    &lt;ref bean=&quot;wss4jOutInterceptor&quot;/&gt;
    &lt;ref bean=&quot;dynamicWsaSignaturePartsInterceptor&quot;/&gt;
  &lt;/jaxws:outFaultInterceptors&gt;
  &lt;jaxws:properties&gt;
    &lt;!-- The parts of the response to sign.  Include: Body, token,
         timestamp at a minimum. --&gt;
    &lt;entry key=&quot;signatureParts&quot; value=&quot;{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body; Token; {Element}{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Timestamp&quot; /&gt;
  &lt;/jaxws:properties&gt;
&lt;/jaxws:endpoint&gt;

&lt;bean id=&quot;dynamicWsaSignaturePartsInterceptor&quot;
      class=&quot;valeri.blog.examples.cxf_wsa_sig.DynamicWsaSignaturePartsInterceptor&quot;/&gt;

&lt;!-- Configure the outbound WSS4J interceptor. --&gt;
&lt;bean id=&quot;wss4jOutInterceptor&quot;&gt;
  &lt;constructor-arg&gt;
    &lt;!-- The entry keys in this map are defined in
         org.apache.ws.security.handler.WSHandlerConstants
         but are referenced as String literals here for brevity over
         the use of the util:constant element. --&gt;
    &lt;map&gt;
      &lt;entry key=&quot;action&quot; value=&quot;Timestamp Signature&quot; /&gt;
      &lt;!-- This is the fallback user for sig/enc if the sig/enc specific
           properties are not set.  WSS4JOutInterceptor looks for it
           and fails if it is not set. --&gt;
      &lt;entry key=&quot;user&quot; value=&quot;test-service-1 (test-ca-1)&quot; /&gt;

      &lt;!-- Timestamp TTL in seconds. --&gt;
      &lt;entry key=&quot;timeToLive&quot; value=&quot;60&quot; /&gt;&lt;br /&gt;
      &lt;!-- The certificate alias in the signature crypto config to sign
           the message with.  The password is retrieved from the callback handler. --&gt;
      &lt;entry key=&quot;signatureUser&quot; value=&quot;test-service-1 (test-ca-1)&quot; /&gt;
      &lt;!-- Signature key attachment method.  We want to put the token
           directly in the header and not use a reference. --&gt;
      &lt;entry key=&quot;signatureKeyIdentifier&quot; value=&quot;DirectReference&quot; /&gt;
      &lt;!-- Defines the property name that contains a Properties object with the desired
           settings in it.  Better than loading a static file from the classpath when using
           Spring. --&gt;
      &lt;entry key=&quot;SignaturePropRefId&quot; value=&quot;signatureProperties&quot; /&gt;
      &lt;!-- The entry that actually contains the Properties object for
           the signature crypto configuration.  See SignaturePropRefId. --&gt;
      &lt;entry key=&quot;signatureProperties&quot; value-ref=&quot;signatureProperties&quot; /&gt;&lt;br /&gt;
      &lt;!-- The reference to the callback handler for retrieving passwords
           for private keys in the signature and encryption crypto configurations. --&gt;
      &lt;entry key=&quot;passwordCallbackRef&quot; value-ref=&quot;pwCallback&quot; /&gt;
    &lt;/map&gt;
  &lt;/constructor-arg&gt;
&lt;/bean&gt;
</pre></p>
<p>Lines 17 and 21 add the new custom interceptor to the out and outFault interceptor chains of the server.  This addition ensures that both regular and fault responses from the server are equally secure.  These lines reference the DynamicWsaSignaturePartsInterceptor instance defined on line 30.</p>
<p>The next major difference is in the relocation of the signatureParts configuration option from the properties passed to WSS4JOutInterceptor to the properties defined on the service itself.  This configuration option now appears on line 26.  Note that the relocated property value also contains no configuration relating to any WS-A header elements.  This configuration property is relocated to optimize the performance of WSS4J.  When this property is left in its original position, the DynamicWsaSignaturePartsInterceptor is forced to manipulate the service interceptor chain in a way that prevents the caching of cryptographic configuration information.  By moving the configuration location, this caching can still occur.  The DynamicWsaSignaturePartsInterceptor can handle the configuration in either location but produces a warning in the logs when the configuration is not moved to the service definition.</p>
<h2>Trying It Out</h2>
<p>You will need a Subversion client, Maven 2.2.1, Java 1.5/1.6, and  access to the Internet to retrieve the needed dependencies from the  Maven repositories in order to build the sample code and the DynamicWsaSignaturePartsInterceptor interceptor.  The following instructions will guide you through retrieving the source code, building the code, and running the example.</p>
<ol>
<li>Using a Subversion client, checkout a copy of the code from  <a href="https://davidvaleri.googlecode.com/svn/projects/examples/cxf-wsa-sig/tags/cxf-wsa-sig-1.0" target="_blank">https://davidvaleri.googlecode.com/svn/projects/examples/cxf-wsa-sig/tags/cxf-wsa-sig-1.0</a> to a local working directory.</li>
<li>Execute <span style="font-size:10pt;line-height:120%;font-family:Courier;">mvn install</span> in the local working directory.  The build output will display similar to the following
<pre>[INFO] BUILD SUCCESSFUL
[INFO] -------------------------------------------------------------
[INFO] Total time: 8 seconds
[INFO] Finished at: Tue Sep 14 21:38:41 EDT 2010
[INFO] Final Memory: 34M/254M
[INFO] -------------------------------------------------------------</pre>
</li>
<li>Execute <span style="font-size:10pt;line-height:120%;font-family:Courier;">mvn -P server</span> in the working directory.  The example server will start and listen for incoming message.</li>
<li>Using another console window, execute <span style="font-size:10pt;line-height:120%;font-family:Courier;">mvn -P client</span> in the working directory.  The example client will start and send messages to the server.  The server will log the messages to the console window for review.</li>
</ol>
<p>If you review the captured messages to and from the server, you can observe the WS-Security Signature over all WS-Addressing headers in the message.  In the example fragment below, each WS-Addressing header, on lines 23-28, contains a wsu:Id element containing an ID that is referenced from the embedded message signature on lines 6, 9, 12, and 15.</p>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;soap:Header&gt;
    &lt;wsse:Security xmlns:wsse=&quot;...&quot; soap:mustUnderstand=&quot;1&quot;&gt;
    ...
    &lt;ds:Signature xmlns:ds=&quot;...&quot; Id=&quot;Signature-39&quot;&gt;
      &lt;ds:SignedInfo&gt;
        &lt;ds:Reference URI=&quot;#id-41&quot;&gt;
          ...
        &lt;/ds:Reference&gt;
        &lt;ds:Reference URI=&quot;#id-42&quot;&gt;
          ...
        &lt;/ds:Reference&gt;
        &lt;ds:Reference URI=&quot;#id-43&quot;&gt;
          ...
        &lt;/ds:Reference&gt;
        &lt;ds:Reference URI=&quot;#id-44&quot;&gt;
          ...
        &lt;/ds:Reference&gt;
      &lt;/ds:SignedInfo&gt;
      ...
    &lt;/ds:Signature&gt;
    ...
  &lt;/wsse:Security&gt;
  &lt;Action xmlns=&quot;...&quot; xmlns:wsu=&quot;...&quot; wsu:Id=&quot;id-41&quot;&gt;http://customerservice.example.com/CustomerService/getCustomersByName&lt;/Action&gt;
  &lt;MessageID xmlns=&quot;...&quot; xmlns:wsu=&quot;...&quot; wsu:Id=&quot;id-44&quot;&gt;urn:uuid:a2d9d794-60bc-48f8-b549-d7c4fb7ca083&lt;/MessageID&gt;
  &lt;To xmlns=&quot;...&quot; xmlns:wsu=&quot;...&quot; wsu:Id=&quot;id-42&quot;&gt;http://localhost:8080/services/CustomerService&lt;/To&gt;
  &lt;ReplyTo xmlns=&quot;...&quot; xmlns:wsu=&quot;...&quot; wsu:Id=&quot;id-43&quot;&gt;
    &lt;Address&gt;http://www.w3.org/2005/08/addressing/anonymous&lt;/Address&gt;
  &lt;/ReplyTo&gt;
&lt;/soap:Header&gt;
</pre></p>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:2090px;width:1px;height:1px;overflow:hidden;">&lt;jaxws:endpoint<br />
serviceName=&#8221;service:CustomerServiceService&#8221;<br />
endpointName=&#8221;service:CustomerServicePort&#8221;<br />
address=&#8221;http://localhost:8080/services/CustomerService&#8221;<br />
wsdlLocation=&#8221;classpath:/wsdl/CustomerService.wsdl&#8221;<br />
implementor=&#8221;#defaultCustomerService&#8221;&gt;<br />
&lt;jaxws:features&gt;<br />
&lt;!&#8211; Configure the WS-Addressing feature. &#8211;&gt;<br />
&lt;addressing:addressing addressingRequired=&#8221;true&#8221;<br />
allowDuplicates=&#8221;false&#8221;/&gt;<br />
&lt;/jaxws:features&gt;<br />
&lt;jaxws:inInterceptors&gt;<br />
&lt;ref bean=&#8221;wss4jInInterceptor&#8221;/&gt;<br />
&lt;/jaxws:inInterceptors&gt;<br />
&lt;jaxws:outInterceptors&gt;<br />
&lt;ref bean=&#8221;wss4jOutInterceptor&#8221;/&gt;<br />
&lt;ref bean=&#8221;dynamicWsaSignaturePartsInterceptor&#8221;/&gt;<br />
&lt;/jaxws:outInterceptors&gt;<br />
&lt;jaxws:outFaultInterceptors&gt;<br />
&lt;ref bean=&#8221;wss4jOutInterceptor&#8221;/&gt;<br />
&lt;ref bean=&#8221;dynamicWsaSignaturePartsInterceptor&#8221;/&gt;<br />
&lt;/jaxws:outFaultInterceptors&gt;<br />
&lt;jaxws:properties&gt;<br />
&lt;!&#8211; The parts of the response to sign.  Include: Body, token,<br />
timestamp at a minimum. &#8211;&gt;<br />
&lt;entry key=&#8221;signatureParts&#8221; value=&#8221;{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body; Token; {Element}{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Timestamp&#8221; /&gt;<br />
&lt;/jaxws:properties&gt;<br />
&lt;/jaxws:endpoint&gt;&nbsp;</p>
<p>&lt;bean id=&#8221;dynamicWsaSignaturePartsInterceptor&#8221;<br />
class=&#8221;valeri.blog.examples.cxf_wsa_sig.DynamicWsaSignaturePartsInterceptor&#8221;/&gt;</p>
<p>&lt;!&#8211; Configure the outbound WSS4J interceptor. &#8211;&gt;<br />
&lt;bean id=&#8221;wss4jOutInterceptor&#8221;&gt;<br />
&lt;constructor-arg&gt;<br />
&lt;!&#8211; The entry keys in this map are defined in<br />
org.apache.ws.security.handler.WSHandlerConstants<br />
but are referenced as String literals here for brevity over<br />
the use of the util:constant element. &#8211;&gt;<br />
&lt;map&gt;<br />
&lt;entry key=&#8221;action&#8221; value=&#8221;Timestamp Signature&#8221; /&gt;<br />
&lt;!&#8211; This is the fallback user for sig/enc if the sig/enc specific<br />
properties are not set.  WSS4JOutInterceptor looks for it<br />
and fails if it is not set. &#8211;&gt;<br />
&lt;entry key=&#8221;user&#8221; value=&#8221;test-service-1 (test-ca-1)&#8221; /&gt;</p>
<p>&lt;!&#8211; Timestamp TTL in seconds. &#8211;&gt;<br />
&lt;entry key=&#8221;timeToLive&#8221; value=&#8221;60&#8243; /&gt;&lt;br /&gt;<br />
&lt;!&#8211; The certificate alias in the signature crypto config to sign<br />
the message with.  The password is retrieved from the callback handler. &#8211;&gt;<br />
&lt;entry key=&#8221;signatureUser&#8221; value=&#8221;test-service-1 (test-ca-1)&#8221; /&gt;<br />
&lt;!&#8211; Signature key attachment method.  We want to put the token<br />
directly in the header and not use a reference. &#8211;&gt;<br />
&lt;entry key=&#8221;signatureKeyIdentifier&#8221; value=&#8221;DirectReference&#8221; /&gt;<br />
&lt;!&#8211; Defines the property name that contains a Properties object with the desired<br />
settings in it.  Better than loading a static file from the classpath when using<br />
Spring. &#8211;&gt;<br />
&lt;entry key=&#8221;SignaturePropRefId&#8221; value=&#8221;signatureProperties&#8221; /&gt;<br />
&lt;!&#8211; The entry that actually contains the Properties object for<br />
the signature crypto configuration.  See SignaturePropRefId. &#8211;&gt;<br />
&lt;entry key=&#8221;signatureProperties&#8221; value-ref=&#8221;signatureProperties&#8221; /&gt;&lt;br /&gt;<br />
&lt;!&#8211; The reference to the callback handler for retrieving passwords<br />
for private keys in the signature and encryption crypto configurations. &#8211;&gt;<br />
&lt;entry key=&#8221;passwordCallbackRef&#8221; value-ref=&#8221;pwCallback&#8221; /&gt;<br />
&lt;/map&gt;<br />
&lt;/constructor-arg&gt;<br />
&lt;/bean&gt;</p>
</div>
<br /> Tagged: <a href='http://davidvaleri.wordpress.com/tag/cxf/'>cxf</a>, <a href='http://davidvaleri.wordpress.com/tag/security/'>security</a>, <a href='http://davidvaleri.wordpress.com/tag/ws/'>ws-*</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvaleri.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvaleri.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvaleri.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvaleri.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvaleri.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvaleri.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvaleri.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvaleri.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvaleri.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvaleri.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvaleri.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvaleri.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvaleri.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvaleri.wordpress.com/55/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvaleri.wordpress.com&amp;blog=15062177&amp;post=55&amp;subd=davidvaleri&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvaleri.wordpress.com/2010/09/15/signing-ws-addressing-headers-in-apache-cxf/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bcc5eab278c97ad0d3adb502001031bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dvaleri</media:title>
		</media:content>
	</item>
		<item>
		<title>Combining Karaf Features, PAX URL, and Maven to deploy a plain JAR as an OSGi bundle</title>
		<link>http://davidvaleri.wordpress.com/2010/08/13/combining-karaf-features-pax-url-and-maven-to-deploy-a-plain-jar-as-an-osgi-bundle/</link>
		<comments>http://davidvaleri.wordpress.com/2010/08/13/combining-karaf-features-pax-url-and-maven-to-deploy-a-plain-jar-as-an-osgi-bundle/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 13:30:27 +0000</pubDate>
		<dc:creator>David Valeri</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[karaf]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[servicemix]]></category>

		<guid isPermaLink="false">http://davidvaleri.wordpress.com/?p=7</guid>
		<description><![CDATA[I recently found myself in the situation where I needed to provide an easy way for a client to install a set of OSGi bundles and their dependencies.  Karaf Features allow you to name a collection of bundles and other &#8230; <a href="http://davidvaleri.wordpress.com/2010/08/13/combining-karaf-features-pax-url-and-maven-to-deploy-a-plain-jar-as-an-osgi-bundle/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvaleri.wordpress.com&amp;blog=15062177&amp;post=7&amp;subd=davidvaleri&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently found myself in the situation where I needed to provide an easy way for a client to install a set of OSGi bundles and their dependencies.  Karaf Features allow you to name a collection of bundles and other Karaf Features for easy installation using a single command.  If you&#8217;ve never heard of a Karaf Feature, refer to the Karaf <a href="http://karaf.apache.org/46-provisioning.html" target="_blank">documentation</a> for a good tutorial.  By combining a feature descriptor with the PAX URL <a href="http://wiki.ops4j.org/display/paxurl/Wrap+Protocol" target="_blank">Wrap Protocol</a> and <a href="http://wiki.ops4j.org/display/paxurl/Mvn+Protocol" target="_blank">Maven Protocol</a>, you can provide your users with a simple deployment mechanism to support provisioning existing bundles as well as creating bundles from non-OSGi ready JARs at deployment time.  While the <a href="http://www.springsource.com/repository/app/" target="_blank">Spring EBR</a> and <a href="http://repo.fusesource.com/maven2/org/apache/servicemix/bundles/" target="_blank">ServiceMix </a>both maintain a collection of non-OSGi JARs that have been converted to OSGi bundles, sometimes you need to convert a JAR that is not in one of these repositories to an OSGi bundle, or your users cannot access one of these repositories.</p>
<p>In this situation, you can either create the bundle from the JAR and distribute this bundle to your end users or you can couple PAX URL, Karaf Features, and Maven together to provide a small and easy to distribute installation descriptor.  In my case, I need a small and self-contained Zip package for distribution.  Creating bundles from the needed third-party JARs and distributing them in the Zip package would unnecessarily bloat the distribution package.  This blog post discusses how to combine the tools mentioned above to script the creation of OSGi bundles during installation of a Karaf Feature.</p>
<p><span id="more-7"></span></p>
<h2>The Karaf Feature Descriptor</h2>
<p>The code fragment below illustrates a simple feature descriptor that installs a user created bundle as well as an existing OSGi bundle from a Maven repository.</p>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;features&gt;
  &lt;feature name=&quot;myFeature&quot; version=&quot;1.0&quot;&gt;
    &lt;bundle&gt;mvn:valeri.blog.examples/karaf-wrap/1.0&lt;/bundle&gt;
    &lt;bundle&gt;mvn:commons-codec/commons-codec/1.4&lt;/bundle&gt;
  &lt;/feature&gt;
&lt;/features&gt;
</pre></p>
<p>The URLs in each bundle element are PAX URL Maven Protocol URLs.  These URLs trigger the provisioning of the Maven artifact into the OSGi framework.</p>
<p>The following code fragment illustrates a feature descriptor that leverages the Wrap Protocol from PAX URL to provision a non-OSGi-ready artifact.</p>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;features&gt;
  &lt;feature name=&quot;myFeature&quot; version=&quot;1.0&quot;&gt;
    &lt;bundle&gt;mvn:valeri.blog.examples/karaf-wrap/1.0&lt;/bundle&gt;
    &lt;bundle&gt;mvn:commons-codec/commons-codec/1.4&lt;/bundle&gt;
    &lt;bundle&gt;wrap:mvn:commons-beanutils/commons-beanutils-core/1.8.3&lt;/bundle&gt;
  &lt;/feature&gt;
&lt;/features&gt;
</pre></p>
<p>All is well and simple so far, but what if you need to customize the wrapping by providing specific configuration options.  No problem, the PAX wrap capability uses the <a href="http://www.aqute.biz/Code/Bnd" target="_blank">bnd</a> tool under the covers and the bnd tool allows you to customize the generated bundle.  For complex configuration options, the bnd tool uses .bnd files.  Luckily,  PAX URL allows you to specify the location of such a file in the Wrap URL.  For example, the Wrap URL for Commons BeanUtils Core with a custom .bnd file would be formatted as follows.</p>
<pre>wrap:mvn:commons-beanutils/commons-beanutils-core/1.8.3,file://~/myBnd.bnd</pre>
<p>The above URL is great, if you know where the .bnd file will be located on the file system.  In my case, I am distributing a Zip file containing binary artifacts and Maven metadata.  There is no way to know where this file will be unzipped to on a user&#8217;s file system.  Fortunately, the location for the .bnd file can also be a Maven URL.  The following Wrap URL specifies the Maven artifact to convert to an OSGi bundle as well as the Maven artifact that describes the configuration for the bnd tool.</p>
<pre>wrap:mvn:commons-beanutils/commons-beanutils-core/1.8.3,mvn:valeri.blog.examples/karaf-wrap/1.0/bnd/commons-beanutils-core-1.8.3</pre>
<p>While the above URL looks complex, it simply states that the .bnd file is a Maven artifact with the following properties:</p>
<ul>
<li>GroupId: valeri.blog.examples</li>
<li>ArtifactId: karaf-wrap</li>
<li>Version: 1.0</li>
<li>Type: bnd</li>
<li>Classifier: commons-beanutils-core-1.8.3</li>
</ul>
<p>By using a URL like the one above, you can avoid needing to have advanced knowledge of the location of the .bnd file and you can completely automate the conversion of the non-OSGi-ready artifact without needing to distribute the artifact yourself.  The next section will describe how to configure Maven to create and deploy the needed Karaf Feature descriptor and .bnd file.</p>
<h2>Configuring Maven to Deploy Karaf Feature Descriptors and .bnd Files</h2>
<p>The easiest way to attach these artifacts to your Maven build is to use the <a href="http://mojo.codehaus.org/build-helper-maven-plugin/" target="_blank">Build Helper Plug-in</a>.  This Maven plug-in allows you to work with the Maven build process as well as to attach arbitrary artifacts to the Maven build.  The following POM fragment adds the feature descriptor and the .bnd file to the Maven build process using the Build Helper Plug-in&#8217;s attach-artifact goal.</p>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;plugin&gt;
  &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
  &lt;artifactId&gt;build-helper-maven-plugin&lt;/artifactId&gt;
  &lt;executions&gt;
    &lt;execution&gt;
      &lt;id&gt;attach-artifacts&lt;/id&gt;
      &lt;phase&gt;package&lt;/phase&gt;
      &lt;goals&gt;
        &lt;goal&gt;attach-artifact&lt;/goal&gt;
      &lt;/goals&gt;
      &lt;configuration&gt;
        &lt;artifacts&gt;
          &lt;artifact&gt;
            &lt;file&gt;target/features/features.xml&lt;/file&gt;
            &lt;type&gt;xml&lt;/type&gt;
            &lt;classifier&gt;features&lt;/classifier&gt;
          &lt;/artifact&gt;
          &lt;artifact&gt;
            &lt;file&gt;target/bnd/commons-beanutils-core-1.8.3.bnd&lt;/file&gt;
            &lt;type&gt;bnd&lt;/type&gt;
            &lt;classifier&gt;commons-beanutils-core-1.8.3&lt;/classifier&gt;
          &lt;/artifact&gt;
        &lt;/artifacts&gt;
      &lt;/configuration&gt;
    &lt;/execution&gt;
  &lt;/executions&gt;
&lt;/plugin&gt;
</pre></p>
<p>In the above code fragment, the attached artifacts are retrieved from the target folder of the  build.  While it is possible to attach static artifacts that live in the  source tree, it is often convenient to use filtering of tokens in these  files to avoid needing to update version numbers between releases.  In this example, the .bnd files and feature descriptor are copied and filtered into the target/bnd and target/features folders, respectively.  By default, Maven copies resources into the target/classes folder.  In order to keep these files out of the bundle and off the classpath when creating the feature descriptor as part of the bundle module, two additional executions of the Maven Resources Plug-in must be configured.  The following POM fragment illustrates the configuration of these executions.</p>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;plugin&gt;
  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  &lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
  &lt;executions&gt;
    &lt;execution&gt;
      &lt;id&gt;copy-features&lt;/id&gt;
      &lt;phase&gt;generate-resources&lt;/phase&gt;
      &lt;goals&gt;
        &lt;goal&gt;copy-resources&lt;/goal&gt;
      &lt;/goals&gt;
      &lt;configuration&gt;
        &lt;outputDirectory&gt;target/features&lt;/outputDirectory&gt;
        &lt;resources&gt;
          &lt;resource&gt;
            &lt;directory&gt;src/main/features&lt;/directory&gt;
            &lt;filtering&gt;true&lt;/filtering&gt;
          &lt;/resource&gt;
        &lt;/resources&gt;
      &lt;/configuration&gt;
    &lt;/execution&gt;
    &lt;execution&gt;
      &lt;id&gt;copy-bnd&lt;/id&gt;
      &lt;phase&gt;generate-resources&lt;/phase&gt;
      &lt;goals&gt;
        &lt;goal&gt;copy-resources&lt;/goal&gt;
      &lt;/goals&gt;
      &lt;configuration&gt;
        &lt;outputDirectory&gt;target/bnd&lt;/outputDirectory&gt;
        &lt;resources&gt;
          &lt;resource&gt;
            &lt;directory&gt;src/main/bnd&lt;/directory&gt;
            &lt;filtering&gt;true&lt;/filtering&gt;
          &lt;/resource&gt;
        &lt;/resources&gt;
      &lt;/configuration&gt;
    &lt;/execution&gt;
  &lt;/executions&gt;
&lt;/plugin&gt;
</pre></p>
<p>The above configuration, coupled with other configuration in the project POM will deploy the needed artifacts to the Maven repository.  You can look at the deployed artifacts that were created by the above configuration by browsing to <a href="https://davidvaleri.googlecode.com/svn/repo/valeri/blog/examples/karaf-wrap/1.0/" target="_self">https://davidvaleri.googlecode.com/svn/repo/valeri/blog/examples/karaf-wrap/1.0/</a>.</p>
<p>To see the complete example configuration and source files, you can browse the example tag in SVN at <a href="https://davidvaleri.googlecode.com/svn/projects/examples/karaf-wrap/tags/karaf-wrap-1.0" target="_blank">https://davidvaleri.googlecode.com/svn/projects/examples/karaf-wrap/tags/karaf-wrap-1.0</a>.  You can also use this URL to checkout the example code and build it yourself.  To build from the source, you will need Maven 2.2.1, Java 1.5/1.6, and access to the Internet to retrieve the needed dependencies from the Maven repositories.</p>
<h2>Putting it All Together and Deploying The Feature</h2>
<p>Once the artifacts are deployed to a Maven repository, either your local repository or a repository on the network, you can provision them into OSGi using Karaf Features.  The easiest way to work with Karaf Features and the other OSGi tools used above is to get an OSGi container that already comes with the needed tools installed.  Apache ServiceMix provides these tools out of the box.  These instructions will use the supported FUSE distribution available at <a href="http://fusesource.com" target="_blank">http://fusesource.com</a>.  If you don&#8217;t use ServiceMix, you will need to install and configure Karaf Features, PAX URL, and Spring DM in your OSGi container to execute this example.  Use this <a href="http://repo.fusesource.com/maven2/org/apache/servicemix/apache-servicemix/4.2.0-fuse-02-00/apache-servicemix-4.2.0-fuse-02-00.zip" target="_blank">link</a> to download the Zip installer.  Simply extract the Zip file and execute the servicemix script in the bin directory.  The extracted location of the Zip file will be referred to as $SERVICEMIX_HOME in these instructions.  After you execute the script, you will be presented with a shell environment used in the following instructions.</p>
<ol>
<li>Add the example Maven repository to the PAX URL configuration by opening <span style="font-size:11pt;line-height:120%;font-family:Courier;">$SERVICEMIX_HOME/etc/org.ops4j.pax.url.mvn.cfg</span> in a text editor.
<ol>
<li>Edit the <!--[if gte mso 9]&gt;  Normal 0     false false false  EN-US X-NONE X-NONE              MicrosoftInternetExplorer4              &lt;![endif]--><!--[if gte mso 9]&gt;                                                                                                                                            &lt;![endif]--><!--  /* Font Definitions */  @font-face 	{font-family:Courier; 	panose-1:2 7 4 9 2 2 5 2 4 4; 	mso-font-alt:"Courier New"; 	mso-font-charset:0; 	mso-generic-font-family:modern; 	mso-font-format:other; 	mso-font-pitch:fixed; 	mso-font-signature:3 0 0 0 1 0;} @font-face 	{font-family:"Cambria Math"; 	panose-1:2 4 5 3 5 4 6 3 2 4; 	mso-font-charset:0; 	mso-generic-font-family:roman; 	mso-font-pitch:variable; 	mso-font-signature:-1610611985 1107304683 0 0 159 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-unhide:no; 	mso-style-qformat:yes; 	mso-style-parent:""; 	margin-top:6.0pt; 	margin-right:0in; 	margin-bottom:6.0pt; 	margin-left:0in; 	line-height:120%; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	mso-bidi-font-size:10.0pt; 	font-family:"Arial","sans-serif"; 	mso-fareast-font-family:"Times New Roman"; 	mso-bidi-font-family:"Times New Roman";} .MsoChpDefault 	{mso-style-type:export-only; 	mso-default-props:yes; 	font-size:10.0pt; 	mso-ansi-font-size:10.0pt; 	mso-bidi-font-size:10.0pt;} @page WordSection1 	{size:8.5in 11.0in; 	margin:1.0in 1.0in 1.0in 1.0in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.WordSection1 	{page:WordSection1;} --><!--[if gte mso 10]&gt; &lt;!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:&quot;Table Normal&quot;; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-priority:99; 	mso-style-qformat:yes; 	mso-style-parent:&quot;&quot;; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:&quot;Times New Roman&quot;; 	mso-fareast-theme-font:minor-fareast; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin; 	mso-bidi-font-family:&quot;Times New Roman&quot;; 	mso-bidi-theme-font:minor-bidi;} --> <!--[endif]--><span style="font-size:11pt;line-height:120%;font-family:Courier;">org.ops4j.pax.url.mvn.repositories </span>property by appending <!--[if gte mso 9]&gt;  Normal 0     false false false  EN-US X-NONE X-NONE              MicrosoftInternetExplorer4              &lt;![endif]--><!--[if gte mso 9]&gt;                                                                                                                                            &lt;![endif]--><!--  /* Font Definitions */  @font-face 	{font-family:Courier; 	panose-1:2 7 4 9 2 2 5 2 4 4; 	mso-font-alt:"Courier New"; 	mso-font-charset:0; 	mso-generic-font-family:modern; 	mso-font-format:other; 	mso-font-pitch:fixed; 	mso-font-signature:3 0 0 0 1 0;} @font-face 	{font-family:"Cambria Math"; 	panose-1:2 4 5 3 5 4 6 3 2 4; 	mso-font-charset:0; 	mso-generic-font-family:roman; 	mso-font-pitch:variable; 	mso-font-signature:-1610611985 1107304683 0 0 159 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-unhide:no; 	mso-style-qformat:yes; 	mso-style-parent:""; 	margin-top:6.0pt; 	margin-right:0in; 	margin-bottom:6.0pt; 	margin-left:0in; 	line-height:120%; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	mso-bidi-font-size:10.0pt; 	font-family:"Arial","sans-serif"; 	mso-fareast-font-family:"Times New Roman"; 	mso-bidi-font-family:"Times New Roman";} .MsoChpDefault 	{mso-style-type:export-only; 	mso-default-props:yes; 	font-size:10.0pt; 	mso-ansi-font-size:10.0pt; 	mso-bidi-font-size:10.0pt;} @page WordSection1 	{size:8.5in 11.0in; 	margin:1.0in 1.0in 1.0in 1.0in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.WordSection1 	{page:WordSection1;} --><!--[if gte mso 10]&gt; &lt;!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:&quot;Table Normal&quot;; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-priority:99; 	mso-style-qformat:yes; 	mso-style-parent:&quot;&quot;; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:&quot;Times New Roman&quot;; 	mso-fareast-theme-font:minor-fareast; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin; 	mso-bidi-font-family:&quot;Times New Roman&quot;; 	mso-bidi-theme-font:minor-bidi;} --> <!--[endif]--><span style="font-size:11pt;line-height:120%;font-family:Courier;">, http://davidvaleri.googlecode.com/svn/repo/</span> to the last line of the property value.</li>
<li>Save your changes to this file.</li>
</ol>
</li>
<li>In the shell environment, type <span style="font-size:10pt;line-height:120%;font-family:Courier;">features:addUrl mvn:valeri.blog.examples/karaf-wrap/1.0/xml/features</span> and press <strong>enter</strong> to add the feature to the list of known features.  Karaf Features is now aware of the feature.</li>
<li>In the shell environment, type <!--[if gte mso 9]&gt;  Normal 0     false false false  EN-US X-NONE X-NONE              MicrosoftInternetExplorer4              &lt;![endif]--><!--[if gte mso 9]&gt;                                                                                                                                            &lt;![endif]--> <span style="font-size:10pt;line-height:120%;font-family:Courier;">features:list | grep myFeature</span> and press <strong>enter</strong>.  The information for the newly added feature will display.</li>
<li>In the shell environment, type <!--[if gte mso 9]&gt;  Normal 0     false false false  EN-US X-NONE X-NONE              MicrosoftInternetExplorer4              &lt;![endif]--><!--[if gte mso 9]&gt;                                                                                                                                            &lt;![endif]--> <span style="font-size:10pt;line-height:120%;font-family:Courier;">features:install myFeature</span> and press <strong>enter</strong>.</li>
<li>In the shell environment, type osgi<span style="font-size:10pt;line-height:120%;font-family:Courier;">:list </span>and press <strong>enter</strong>.  A list of installed OSGi bundles displays.  The last three entries in the list are the bundles installed by the new feature.  Your output should look like the text below.
<pre>[ 207] [Active     ] [            ] [Started] [   60] David Valeri's...
[ 208] [Active     ] [            ] [       ] [   60] Commons Codec (1.4)
[ 209] [Active     ] [            ] [       ] [   60] Commons BeanUtils...</pre>
</li>
<li>Open <span style="font-size:11pt;line-height:120%;font-family:Courier;">$SERVICEMIX_HOME/data/log/servicemix.log </span>and observe the log output generated by the installed feature.  The log should contain output that resembles the following.
<pre>--------------------------------------------
23:08:14,937 | INFO  | raf_wrap.Example | Example | og.examples.karaf_...
--------------------------------------------
Protocol: http
Host: davidvaleri.wordpress.com
Path:
--------------------------------------------</pre>
</li>
</ol>
<h2>Conclusion</h2>
<p>While this is a fairly trivial example using only a single JAR, this approach can help you to migrate legacy JARs to OSGi without needing to maintain binaries for each converted JAR or build each converted JAR from source.  Avoiding the need to pass these converted JARs out to my clients in the Zip means that the Zip need only contain my application binaries which are not available in a public repository.</p>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:705px;width:1px;height:1px;overflow:hidden;">
<pre>&lt;bundle&gt;mvn:valeri.example/karaf-wrap/1.0&lt;/bundle&gt;</pre>
</div>
<br /> Tagged: <a href='http://davidvaleri.wordpress.com/tag/karaf/'>karaf</a>, <a href='http://davidvaleri.wordpress.com/tag/maven/'>maven</a>, <a href='http://davidvaleri.wordpress.com/tag/osgi/'>osgi</a>, <a href='http://davidvaleri.wordpress.com/tag/servicemix/'>servicemix</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvaleri.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvaleri.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvaleri.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvaleri.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvaleri.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvaleri.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvaleri.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvaleri.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvaleri.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvaleri.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvaleri.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvaleri.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvaleri.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvaleri.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvaleri.wordpress.com&amp;blog=15062177&amp;post=7&amp;subd=davidvaleri&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvaleri.wordpress.com/2010/08/13/combining-karaf-features-pax-url-and-maven-to-deploy-a-plain-jar-as-an-osgi-bundle/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bcc5eab278c97ad0d3adb502001031bf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dvaleri</media:title>
		</media:content>
	</item>
	</channel>
</rss>
