<?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/"
	>

<channel>
	<title>my2cents &#187; Apache</title>
	<atom:link href="http://www.frightanic.com/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.frightanic.com</link>
	<description>&#34;The Earth was made round so that we would not see too far down the road&#34; - Karen Blixen</description>
	<lastBuildDate>Sat, 04 Sep 2010 07:13:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Self-signed SSL certificates with Apache HttpClient</title>
		<link>http://www.frightanic.com/2010/04/05/self-signed-ssl-certificates-with-apache-httpclient/</link>
		<comments>http://www.frightanic.com/2010/04/05/self-signed-ssl-certificates-with-apache-httpclient/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 09:14:24 +0000</pubDate>
		<dc:creator>frightanic</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[certificates]]></category>
		<category><![CDATA[HttpClient]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[SSL handshake]]></category>

		<guid isPermaLink="false">http://www.frightanic.com/?p=513</guid>
		<description><![CDATA[When you need to support self-signed SSL certificates in your Apache HttpClient based application you can use the contributed EasySSLProtocolSocketFactory as described in the HttpClient docs. Instead of using HttpClient&#8217;s HostConfiguration object directly you&#8217;d modify its protocol socket factory in your code like so: ... if (config.isAllowSelfSignedCertificates()) { ProtocolSocketFactory factory = new EasySSLProtocolSocketFactory(); try { [...]]]></description>
			<content:encoded><![CDATA[<p>When you need to support self-signed SSL certificates in your Apache HttpClient based application you can use the contributed <a href="http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/contrib/org/apache/commons/httpclient/contrib/ssl/EasySSLProtocolSocketFactory.java?view=markup" target="_blank">EasySSLProtocolSocketFactory</a> as described in the <a href="http://hc.apache.org/httpclient-3.x/sslguide.html" target="_blank">HttpClient docs</a>.</p>
<p>Instead of using HttpClient&#8217;s HostConfiguration object directly you&#8217;d modify its protocol socket factory in your code like so:</p>
<pre class="brush:java">...
if (config.isAllowSelfSignedCertificates()) {
  ProtocolSocketFactory factory = new EasySSLProtocolSocketFactory();
  try {
    URI uri = new URI(config.getBaseUrl());
    int port = uri.getPort();
    if (port == -1) {
      port = 443;
    }
    Protocol easyHttps = new Protocol(uri.getScheme(), factory, port);
    hostConfiguration.setHost(uri.getHost(), port, easyHttps);
  } catch (URISyntaxException e) {
    throw new IOException("could not parse URI " + config.getBaseUrl(), e);
  }
}
...</pre>
<p>Somewhere you&#8217;d instantiate a HttpClient object. Then you get its host config through HttpClient#getHostConfiguration() &#8211; I stored this in the hostConfiguration variable. The if, the config variable, checking for port, etc. is all my own code and has nothing to do with HttpClient directly.</p>
<p>There is one caveat, though! Never use absolute URIs against the HttpClient 3.x with the EasySSLProtocolSocketFactory in place! If you did you&#8217;d get the dreaded</p>
<pre class="brush:java">javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target</pre>
<p>I found that the HttpClient 3.x has the following code in its executeMethod() method:</p>
<pre class="brush:java">...
if (hostconfig == defaulthostconfig || uri.isAbsoluteURI()) {
  // make a deep copy of the host defaults
  hostconfig = (HostConfiguration) hostconfig.clone();
  if (uri.isAbsoluteURI()) {
      hostconfig.setHost(uri);
  }
}
...</pre>
<p>So, in my case (absolute URI) the modified host config (uses EasySSLProtocolSocketFactory) is cloned.</p>
<p>Problem: since the so called &#8220;deep copy&#8221; isn&#8217;t a proper deep copy the copy&#8217;s protocol&#8217;s socket factory is no longer EasySSLProtocolSocketFactory but the standard SSLProtocolSocketFactory instead!</p>
<h4>Update</h4>
<p>Apparently, this behavior is &#8220;well known and documented&#8221;. Since I couldn&#8217;t find anything in the HttpClient 3.x documentation I tried Google again and made note of the following JIRA issues and one particular mailing list entry:</p>
<ul>
<li><a href="http://issues.apache.org/jira/browse/HTTPCLIENT-634">http://issues.apache.org/jira/browse/HTTPCLIENT-634</a></li>
<li><a href="http://issues.apache.org/jira/browse/HTTPCLIENT-683">http://issues.apache.org/jira/browse/HTTPCLIENT-683</a></li>
<li><a href="http://issues.apache.org/jira/browse/HTTPCLIENT-783">http://issues.apache.org/jira/browse/HTTPCLIENT-783</a></li>
<li><a href="http://www.mail-archive.com/httpclient-user@jakarta.apache.org/msg03530.html">http://www.mail-archive.com/httpclient-user@jakarta.apache.org/msg03530.html</a></li>
</ul>
<p>Please note that HttpClient 4.x does not have this limitation!</p>
<p><a href="https://issues.apache.org/jira/browse/HTTPCLIENT-634"></a></p>
<p><a href="https://issues.apache.org/jira/browse/HTTPCLIENT-683"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frightanic.com/2010/04/05/self-signed-ssl-certificates-with-apache-httpclient/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>No principal in request after Apache basic authentication with mod_jk</title>
		<link>http://www.frightanic.com/2009/09/11/no-principal-in-request-after-apache-basic-authentication-with-mod_jk/</link>
		<comments>http://www.frightanic.com/2009/09/11/no-principal-in-request-after-apache-basic-authentication-with-mod_jk/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 21:08:46 +0000</pubDate>
		<dc:creator>frightanic</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[mod_jk]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://www.frightanic.com/?p=305</guid>
		<description><![CDATA[Yet another software configuration issue that I wasted a few hours at today. Environment Apache 2.2.13 connect to Tomcat 5.5 with mod_jk (ajp13). Apache requires basic-auth for &#8220;/&#8221; i.e. for all URLs it serves. Just to be 100% precise, Tomcat runs as a WTP server &#8220;inside&#8221; Eclipse. However, the fact that it&#8217;s not a standalone [...]]]></description>
			<content:encoded><![CDATA[<p>Yet another software configuration issue that I wasted a few hours at today.</p>
<h3>Environment</h3>
<p>Apache 2.2.13 connect to Tomcat 5.5 with mod_jk (ajp13). Apache requires basic-auth for &#8220;/&#8221; i.e. for all URLs it serves. Just to be 100% precise, Tomcat runs as a WTP server &#8220;inside&#8221; Eclipse. However, the fact that it&#8217;s not a standalone instance has no effect to either the problem or the solution.</p>
<h3>Problem</h3>
<p>I noticed that request.getUserPrincipal() returned null in my Servlet filter although basic-auth in Apache was successful. By raising the mod_jk log level to debug (JkLogLevel debug) and looking at the mod_jk.log I could confirm, however, that mod_jk at least passed the remote user along in the request.</p>
<h3>Solution</h3>
<p>Set tomcatAuthentication=&#8221;false&#8221; for the AJP/1.3 connector in server.xml. The parameter is explained in the <a href="http://tomcat.apache.org/tomcat-5.5-doc/config/ajp.html" target="_blank">Tomcat connector documentation</a>: &#8220;If set to true, the authentication will be done in Tomcat. Otherwise, the authenticated principal will be propagated from the native webserver and used for authorization in Tomcat. The default value is true.&#8221;</p>
<p>A thread from the tomcat-users mailing list archive helped a lot: <a href="http://www.mail-archive.com/users@tomcat.apache.org/msg55080.html" target="_blank">http://www.mail-archive.com/users@tomcat.apache.org/msg55080.html</a>. I didn&#8217;t initially find that through a web search because I kept looking for something like &#8220;principal null Tomcat Apache mod_jk&#8221; instead of &#8220;REMOTE_USER null&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.frightanic.com/2009/09/11/no-principal-in-request-after-apache-basic-authentication-with-mod_jk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
