<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>simplericity - tomcat tag</title>
  <link>http://simplericity.com/tags/tomcat/</link>
  <description>Reducing software entropy</description>
  <language>en</language>
  <copyright>Eirik Bjørsnøs</copyright>
  <lastBuildDate>Fri, 02 Jan 2009 11:02:56 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  
  <item>
    <title>Yes, cross-platform Single Sign-On for Java Webapps is possible.</title>
    <link>http://simplericity.com/2008/07/24/1216920300000.html</link>
    
      
        <description>
          A customer participating in the &lt;a href=&#034;http://svnsearch.org&#034;&gt;SVNSearch&lt;/a&gt; beta round asked me about Single Sign-On solutions for SVNSearch. SSO has become something of holy grail in the Enterprise. Everyone wants it but few seem to really achieve it. The Wikipedia article for &lt;a href=&#034;javascript:void(0);/*1216920824305*/&#034;&gt;Single Single-On&lt;/a&gt; even cites a Gartner report stating that &amp;quot;no one can achieve it without a homogeneous IT infrastructure&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
What could be a better motivation than Gartner saying it&#039;s impossible? I decided I&#039;d prove them wrong and took on the task to create a cross platform, Single Sign-On solution for SVNSearch.&lt;br /&gt;
&lt;br /&gt;
&lt;img alt=&#034;&#034; src=&#034;http://simplericity.com/images/sso/looking.jpg&#034; /&gt;&lt;br /&gt;
&lt;h2&gt;The NTLM headache&lt;/h2&gt;
As it turns out, there are only a couple of options available for Web SSO . The Java CIFS Client Library (&lt;a href=&#034;javascript:void(0);/*1216920861940*/&#034;&gt;JCIFS&lt;/a&gt;) implements Microsoft&#039;s NTLM technology. NTLM is a challenge-response authentication mechanism, and being a product of Microsoft it&#039;s not much of a surprise that it has a history of security weaknesses.&lt;br /&gt;
&lt;br /&gt;
NTLM has caused me lots of headache on a past project because it doesn&#039;t play nice with the basic rules of HTTP. NTLM is a connection-oriented protocol, so both the server and the client needs to keep the same TCP connection open for at least the three request it takes to do the authentication. This is just fine when Internet Explorer is talking to Microsoft&#039;s IIS server, but when you introduce a web server like Tomcat, weird things start happening.&amp;nbsp; In our case Tomcat would start sending Connection: close headers under heavy load. This is a perfectly sensible thing to do &amp;ndash; if you&#039;re running low on available threads, turing off keep-alive is&amp;nbsp; better than refusing requests. But in the NTLM case it made Internet Explorer fail with a non-decipherable error page. &lt;br /&gt;
&lt;br /&gt;
Finally, NTLM isn&#039;t really cross platform. Both Firefox and Safari have adopted NTLM, but they&#039;ll pop up a username/password dialog on non Windows platforms. &lt;br /&gt;
&lt;h2&gt;Enter Kerberos&lt;/h2&gt;
So you might not be surprised to hear I wanted something better than NTLM. I&#039;d been reading about Kerberos for years, but my impression was that it required an army of sysadmins to set up and a Ph.D in cryptography to create software for it.&amp;nbsp; Then I realized Microsoft actually use Kerberos for their domain controllers so I already had the infrastructure set up. I started looking for open source projects implementing Kerberos authentication, but I couldn&#039;t really find anything. There were a lot of pointers to a an &lt;a href=&#034;javascript:void(0);/*1216920959962*/&#034;&gt;old patch&lt;/a&gt; providing Kerberos support for JCIFS, but it doesn&#039;t seem like it ever got applied.&lt;br /&gt;
&lt;br /&gt;
So it seemed like I had no option but to roll my own. In doing so, I had to spend some time trying to understand how Kerberos works. And it&#039;s not really that hard. Every time you log on to your Windows Domain Controller, Windows acquires a Kerberos token from the Domain Controller. This token can be used to fetch another type of token that lets you log into network services like my Java based web server. The service also has to authenticate itself and that is taken care of by issuing KeyTab files containing secret keys for the service.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;The implementation&lt;/h2&gt;
Kerberos is implemented in Java through the GSS API. GSS is a just a wrapper API around token based security mechanisms like Kerberos and doesn&#039;t provide any security itself. The authentication of the service is done through a JAAS LoginModule, the &lt;a href=&#034;javascript:void(0);/*1216921004740*/&#034;&gt;Krb5LoginModule&lt;/a&gt;.&amp;nbsp; The module needs to be configured to use a KeyTab file and to store the credentials in the Subject. This way the credentials can be used in the next step when authenticating users. You only need to do the service login once, after that you can keep the Subject around as long as the service is running.&lt;br /&gt;
&lt;br /&gt;
It&#039;s important to name the service principal correctly. The principal name needs to match the host name of the service&amp;nbsp; and the host name needs to have a DNS A record who&#039;s IP address resolves back to the host name. User authentication is done through the GSSAPI. I&#039;m using the GSSManager to create a &lt;a href=&#034;javascript:void(0);/*1216921049497*/&#034;&gt;GSSContext&lt;/a&gt;. This context is then fed the Kerberos token in the acceptSecContext() method and&amp;nbsp; if isEstablished() returns true we can fetch the identity of the authenticated user with getSrcName().&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Web-based Kerberos&lt;/h2&gt;
Kerberos was invented before the web and doesn&#039;t specify how tokens should be transported in a web context. Microsoft implemented SPNEGO in Internet Explorer 5.01 as an HTTP authentication mechanism. When the server requires user authentication it sends a HTTP 401 status back to the user with a &amp;laquo;WWW-Authenticate: Negotiate&amp;raquo; header. The browser then resubmits the request, now with a &amp;laquo;Authorization&amp;raquo; header containing a security token. This ping-pong game continues until the underlying security mechanism is negotiated and the user is authenticated. SPNEGO is a pseudo mechanism used to negotiate the use of a real mechanism in the case that the server and client don&#039;t agree on a mechanism upfront. SPNEGO is implemented in Java 1.6 as a part of the Java GSS API. However, the SPNEGO token is DER encoded so it&#039;s pretty straight forward to extract the real&amp;nbsp; Kerberos token from a SPNEGO token if you&#039;re running on Java 5 or 1.4.&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&#034;http://simplericity.com/images/sso/tind.jpg&#034; alt=&#034;&#034; /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Cross-platform support&lt;/h2&gt;
OS X supports Kerberos. You can set up OS X to acquire Kerberos tickets when logging in or you can use kinit command line tool or the graphical utility Kerberos.app for&amp;nbsp; ticket administration. Most Linux distributions also have Kerberos support. Kerberos is supported in&amp;nbsp; both Safari and Firefox, although Firefox doesn&#039;t send SPNEGO tokens but pure Kerberos tokens instead. So my code needed to take that into account. &lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;The result&lt;/h2&gt;
Although it did require a fair amount of research and development I must say I&#039;m very happy with the end result. I now have a 100% pure Java Single Sing-On toolkit. Having complete control of the authentication process also gives some nice extras. I can present the user with a fallback login page if automatic login fails. I can also let the administrator test the Kerberos configuration and provide some useful feedback if something doesn&#039;t work. &lt;br /&gt;
&lt;br /&gt;
If there&#039;s any interest in this&amp;nbsp; code please let me know. I might consider making a small open source project out of it or contribute it to an&amp;nbsp; existing project. And to the Gartner dudes: I now have Kerberos based SSO solution that works great in a cross-platform environment,&amp;nbsp; so go eat your socks!&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&#034;http://simplericity.com/images/sso/kerbconf.jpg&#034; alt=&#034;&#034; /&gt;
        </description>
      
      
    
    
    
    <category>Java</category>
    
    <comments>http://simplericity.com/2008/07/24/1216920300000.html#comments</comments>
    <guid isPermaLink="true">http://simplericity.com/2008/07/24/1216920300000.html</guid>
    <pubDate>Thu, 24 Jul 2008 17:25:00 GMT</pubDate>
  </item>
  
  <item>
    <title>The extra dot in dot-com</title>
    <link>http://simplericity.com/2007/10/29/1193665479084.html</link>
    
      
        <description>
          &lt;p&gt;Sun no longer claims they &amp;quot;put the dot in dot-com&amp;quot;, but did you know there&#039;s actually more than one dot in dot-com?&lt;/p&gt;
&lt;p&gt;According to &lt;a href=&#034;http://www.ietf.org/rfc/rfc1034.txt&#034;&gt;RFC1034&lt;/a&gt; &amp;quot;www.example.com&amp;quot; is a &lt;em&gt;relative&lt;/em&gt; domain name. The complete domain name (also called &lt;em&gt;absolute&lt;/em&gt;) is &amp;quot;www.example.com.&amp;quot; (Notice the trailing &amp;quot;.&amp;quot;)&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Reading this RFC one should think that adding a trailing dot to a domain name should have no effect. All you&#039;re doing is to be explicit by using the absolute representation of the domain right?&lt;/p&gt;
&lt;p&gt;Not quite so. It doesn&#039;t seem like web server vendors and administrators have read this RFC and neither have web browser vendors. This becomes a problem if you&#039;re using name based virtual hosting on your web server. When the server gets a request for &amp;quot;www.example.com.&amp;quot; it won&#039;t have a clue that the user is actually looking for the content at &amp;quot;www.example.com&amp;quot;.&lt;/p&gt;
&lt;p&gt;So I did a little survey on the web servers I use. The &lt;a href=&#034;http://httpd.apache.org&#034;&gt;Apache HTTP Server&lt;/a&gt; handles the trailing dot perfectly. &lt;a href=&#034;http://tomcat.apache.org&#034;&gt;Tomcat&lt;/a&gt; doesn&#039;t understand it and serves content from the default host instead. You can mediate this by always adding an &lt;alias&gt;alias with the trailing dot, but that&#039;s a hack and it&#039;s something the server should handle by itself.&lt;/alias&gt;&lt;/p&gt;
&lt;p&gt;I was a little disappointed to find that &lt;a href=&#034;http://jetty.mortbay.org&#034;&gt;Jetty&lt;/a&gt; (my favorite web server) failed the trailing dot test. But then I remembered how nice the Jetty developers are so a couple of weeks ago I decided to fix the problem and&amp;nbsp; &lt;a href=&#034;http://jira.codehaus.org/browse/JETTY-438&#034;&gt;submit a patch&lt;/a&gt; for it. Today Greg applied it. From the next release onwards, Jetty will normalize host names before comparing them. Try reporting something like that to IBM or BEA and you&#039;ll find out why Jetty rocks!&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Now, just for the fun of it, let&#039;s take a look at how some big sites handle requests with trailing dots:&lt;/p&gt;
&lt;h2&gt;Microsoft: Bad request&lt;/h2&gt;
&lt;p&gt;Microsoft solves the problem the easy way. Just blame it on the user:&lt;/p&gt;
&lt;img alt=&#034;&#034; src=&#034;http://simplericity.com/images/trailingdot/microsoft.png&#034; /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;MSN: Page not found&lt;/h2&gt;
&lt;p&gt;MSN is a little more polite, they even say they&#039;re sorry:&lt;/p&gt;
&lt;img alt=&#034;&#034; src=&#034;http://simplericity.com/images/trailingdot/msn.png&#034; /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Myspace: Redirect to google&lt;/h2&gt;
&lt;p&gt;I knew Myspace and Google made an advertising deal, but this is just weird:&lt;/p&gt;
&lt;img alt=&#034;&#034; src=&#034;http://simplericity.com/images/trailingdot/myspace.png&#034; /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Facebook: Redirect to www.facebook.facebook.com&lt;/h2&gt;
&lt;p&gt;Facebook is getting so big they seem to have started a facebook inside the facebook, but there&#039;s no response there:&lt;/p&gt;
&amp;nbsp;&lt;img alt=&#034;&#034; src=&#034;http://simplericity.com/images/trailingdot/facebook.png&#034; /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;NSA: Trust no one, say nothing&lt;/h2&gt;
&lt;p&gt;One can say a lot about the NSA, but don&#039;t give them a trailing dot because they will refuse to talk to you. Period.  &lt;/p&gt;
&lt;img src=&#034;http://simplericity.com/images/trailingdot/nsa.png&#034; alt=&#034;&#034; /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Sun: Page not found&lt;/h2&gt;
&lt;p&gt;Sun may once have &amp;quot;put the dot in dot-com&amp;quot;, but that&#039;s no longer the case. They&#039;re more sorry than MSN though. Sorry with an exclamation point. And what makes them think I own documents at sun.com?&lt;br /&gt;
&lt;/p&gt;
&lt;img src=&#034;http://simplericity.com/images/trailingdot/sun.png&#034; alt=&#034;&#034; /&gt;
        </description>
      
      
    
    
    
    <category>Java</category>
    
    <comments>http://simplericity.com/2007/10/29/1193665479084.html#comments</comments>
    <guid isPermaLink="true">http://simplericity.com/2007/10/29/1193665479084.html</guid>
    <pubDate>Mon, 29 Oct 2007 13:44:39 GMT</pubDate>
  </item>
  
  </channel>
</rss>
