<?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>ChangeLog - Jon Chase&#039;s blog &#187; Grails</title>
	<atom:link href="http://www.juliesoft.com/category/grails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.juliesoft.com</link>
	<description>solve niche problems, make users happy</description>
	<lastBuildDate>Sun, 18 Jul 2010 06:56:43 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ChangeLog #4: Every Single Shot 1.0 is OUT!</title>
		<link>http://www.juliesoft.com/2010/06/changelog-4-every-single-shot-1-0-is-out/</link>
		<comments>http://www.juliesoft.com/2010/06/changelog-4-every-single-shot-1-0-is-out/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 07:57:09 +0000</pubDate>
		<dc:creator>Jon Chase</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[ChangeLog]]></category>
		<category><![CDATA[Every Single Shot]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Grails]]></category>

		<guid isPermaLink="false">http://www.juliesoft.com/?p=394</guid>
		<description><![CDATA[Holla!  I just flipped the switch on Every Single Shot 1.0!  If it&#8217;s on Twitter it must be a fact:

This has been the culmination of a lot of work!  Oh sure, it&#8217;s still a little rough around the edges for now, but isn&#8217;t that part of the charm?  I&#8217;ve got big, [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.juliesoft.com%2F2010%2F06%2Fchangelog-4-every-single-shot-1-0-is-out%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.juliesoft.com%2F2010%2F06%2Fchangelog-4-every-single-shot-1-0-is-out%2F" height="61" width="51" /></a></div><p>Holla!  I just flipped the switch on <a href="http://everysingleshot.com">Every Single Shot 1.0</a>!  If it&#8217;s <a href="http://twitter.com/everysingleshot/status/15161765717">on Twitter</a> it must be a fact:</p>
<p><a href="http://twitter.com/everysingleshot/status/15161765717"><img src="http://www.juliesoft.com/wp-content/uploads/2010/06/ess10tweet.png" alt="ess10tweet" title="ess10tweet" width="586" height="259" class="aligncenter size-full wp-image-395" /></a></p>
<p>This has been the culmination of a <strong>lot</strong> of work!  Oh sure, it&#8217;s still a little rough around the edges for now, but isn&#8217;t that part of the charm?  I&#8217;ve got big, big plans for the future of ESS, and I&#8217;m super excited that I&#8217;ve gotten this far.  I don&#8217;t know how else to say it: it&#8217;s been a lot of work.  Worth it? Definitely!  </p>
<p><a href="http://everysingleshot.com"><img src="http://www.juliesoft.com/wp-content/uploads/2010/06/ess1.0.jpg" alt="ess1.0" title="ess1.0" width="550" height="394" class="aligncenter size-full wp-image-396" /></a></p>
<h3>Technical stuff</h3>
<p>What&#8217;s ESS built on?  What technologies does it use?  What methodologies did I use to build it?  </p>
<h4>The tech</h4>
<h5>Grails</h5>
<p>First and foremost, I used <a href="http://grails.org">Grails</a> for pretty much everything.  I was a Spring MVC veteran for a long time, and let me tell you, I knew my way around that stack inside and out.  There was nothing I couldn&#8217;t accomplish with it, albeit with a bit of elbow grease usually.  I decided to move to Grails for this application b/c it was so similar to Spring MVC in so many ways (it&#8217;s built on top of Spring MVC for one), but different where it really counted (i.e. it made the simple stuff really simple, and the tough stuff, well, less tough).  I have no regrets and I don&#8217;t see myself ever going back.  </p>
<p><strong>Grails report card: A++</strong></p>
<h5>Amazon EC2 and S3</h5>
<p>Can I get another holla!  I love love love working on <a href="http://aws.amazon.com/ec2/">EC2</a> and <a href="https://s3.amazonaws.com/">S3</a>.  Let me put it this way: have you ever used a technology or toolset that just works?  I mean, one that <strong>always</strong> does exactly what it&#8217;s supposed to without fail?  Well, I hadn&#8217;t either until I used EC2 and S3.  They are so damn reliable, so rock solid, so well documented and supported.  <strong>Basically, they&#8217;re awesome.</strong>  I know there are other services out there with more bells and whistles, and I&#8217;ll be honest, I had to build a lot of infrastructure in EC2 myself that I wish I hadn&#8217;t needed to, but AWS&#8217;s stability and predictability more than make up for it.  For 10 cents an hour I get a dedicated (virtual) server with lots of RAM, a huge disk, and some crazy fast connectivity.  Scripting set up and configuration of servers couldn&#8217;t be much easier than with good ol&#8217; <a href="http://alestic.com/2009/08/runurl">runurl</a>.  Management of servers is super easy with the command line tools.  Rawk on.</p>
<p><strong>Amazon AWS report card: A++</strong></p>
<h5>Other tech</h5>
<p>Here are some of the other technologies that various parts of Every Single Shot use in no particular order: <a href="http://en.wikipedia.org/wiki/Advanced_Packaging_Tool">apt</a> (this is one reason that Linux rocks), Apache 2, <a href="http://www.juliesoft.com/2010/05/an-easy-way-to-keep-your-ubuntu-ec2-instances-up-to-date/">apticron</a>, <a href="http://timkay.com/aws/">awstools</a>, <a href="http://alestic.com/2009/09/ec2-consistent-snapshot">ec2-consistent-snapshot</a> (Eric Hammond is the man when it comes to EC2 and Ubuntu), Groovy, <a href="http://www.imagemagick.org">ImageMagick</a>, Java, Jquery, MySQL, <a href="http://www.postfix.org/">postfix</a>, Subversion (I know, I know&#8230;), and Tomcat.  All in all you can see there&#8217;s not a lot of glamour tools in there, just a bunch of stuff that works.  </p>
<h4>Methodologies</h4>
<p>Gosh, I wish I could be more specific, but I pretty much just had a big list of issues, loosely divided into versions, organized in <a href="http://www.atlassian.com/software/jira/">Jira</a> (<a href="http://www.atlassian.com/software/jira/pricing.jsp">I got my Jira license for $10</a>).  That&#8217;s it.  No agile, no scrum, no scragile or whatever.  Just cranked through issues.</p>
<p>Here&#8217;s something interesting:  I used to do a lot of TDD (test driven development).  I&#8217;ve abandoned that lately in favor of writing tests&#8230;never.  Actually, since I&#8217;ve started with Grails I&#8217;ve written a lot fewer tests that I used to with Spring MVC.  Part of this is due to the fact that there&#8217;s a lot less that needs testing in Grails, and part of it is due to the fact that tests in Grails can be a little tough to write (there&#8217;s a lot of meta programming magic happening, and I miss Java autocomplete), and a lot of the tests run kinda slow (the entire container has to start up a lot of the time).  Enough about testing though (let the flame wars begin).  </p>
<h3>I could go on&#8230;</h3>
<p>Believe me, I have lots more to talk about, lots more I want to say about the 1.0 release of Every Single Shot.  But that&#8217;ll have to wait.  I need to get back to work!  2.0 is calling me&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.juliesoft.com/2010/06/changelog-4-every-single-shot-1-0-is-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic http/httpS switching with Grails</title>
		<link>http://www.juliesoft.com/2010/04/automatic-httphttps-switching-with-grails/</link>
		<comments>http://www.juliesoft.com/2010/04/automatic-httphttps-switching-with-grails/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 08:40:56 +0000</pubDate>
		<dc:creator>Jon Chase</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Java & Programming]]></category>
		<category><![CDATA[java groovy grails spring security http https]]></category>

		<guid isPermaLink="false">http://www.juliesoft.com/?p=336</guid>
		<description><![CDATA[
A common requirement in webapps nowadays is to switch users between a secure and insecure connection (called protocol switching).  For example, maybe your user needs to enter a password, credit card number, or some other sensitive information.  Of course, you (and the user) would like that information to be sent securely, which means [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.juliesoft.com%2F2010%2F04%2Fautomatic-httphttps-switching-with-grails%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.juliesoft.com%2F2010%2F04%2Fautomatic-httphttps-switching-with-grails%2F" height="61" width="51" /></a></div><p><img src="http://www.juliesoft.com/wp-content/uploads/2010/04/switch.jpg" alt="switch" title="switch" width="500" height="333" class="aligncenter size-full wp-image-356" /></p>
<p>A common requirement in webapps nowadays is to switch users between a secure and insecure connection (called <strong>protocol switching</strong>).  For example, maybe your user needs to enter a password, credit card number, or some other sensitive information.  Of course, you (and the user) would like that information to be sent securely, which means requiring http<strong>s</strong>.  Assuming you&#8217;ve already got a server set up with an SSL cert and it&#8217;s ready to serve pages over SSL, you&#8217;ll need to <strong>ensure</strong> your webapp serves all secure pages over http<strong>s</strong>.  Unfortunately, this isn&#8217;t always as easy as it seems.  But it&#8217;s not too tough either, thanks to <a href="http://grails.org">Grails</a> and <a href="http://static.springsource.org/spring-security/site/index.html">Spring Security</a>.  </p>
<p>Here are the <strong>requirements for protocol switching</strong>:</p>
<ul>
<li>Serve secure pages using http<strong>s</strong>, regardless of the link used to get to the page (i.e. http links should be redirected to http<strong>s</strong>)</li>
<li>Make protocol switching transparent to the majority of your application (i.e. links starting with <span class="mono">http://</span> will automatically get redirected to <span class="mono">http<strong>s</strong>://</span> and vice versa)</li>
<li>Easy configuration of which resources must be served as secure, insecure, or either (i.e. images, CSS, and JavaScript should be loaded using the same protocol the page uses to avoid nasty browser warnings (see below))</li>
<li>Security and protocol switching should be handled in a way such that browsers aren&#8217;t continuously popping up warning dialogs</li>
<li>Make it work in Grails</li>
</ul>
<h3>Implementation</h3>
<p>There are several ways to go about automatic protocol switching.  One of the most popular would be to use Apache and <a href="http://www.whoopis.com/howtos/apache-rewrite.html">mod_rewrite</a>.  That solution works fine, but it&#8217;s not portable between different types of servers.  </p>
<p>The solution below is pure Java, and is portable between any servlet container.  By the way, this isn&#8217;t a Grails only solution &#8211; this will work with pretty much any Java web stack &#8211; the only thing that will differ is how you wire things up.  In fact I&#8217;ve used this in a regular Spring MVC app with a regular Spring configuration&#8230;but I&#8217;m only going to show the Grails way to do it today.  </p>
<p>Here&#8217;s how to get automatic protocol switching in Grails:</p>
<ul>
<li>Add a filter definition to web.xml that intercepts all requests and handles the protocol switching and redirecting</li>
<li>Configure which URLs require which protocol</li>
<li>Test!</li>
</ul>
<h3>Adding the filter definition</h3>
<p>Spring Security has <a href="http://static.springsource.org/spring-security/site/docs/3.0.x/reference/ns-config.html#ns-requires-channel">protocol switching built in</a>, so why reinvent the wheel?  (Don&#8217;t worry, you don&#8217;t need to use any other parts of Spring Security to get protocol switching.)  Spring Security refers to protocol switching as Channel Security, but don&#8217;t worry, it&#8217;s the same thing.</p>
<p>If your Grails app isn&#8217;t already using Spring Security, add the following dependencies into grails-app/conf/BuildConfig.groovy to have Grails download the required JARs:</p>
<pre class="brush: groovy">
grails.project.dependency.resolution = {

	// ...
	// other settings...
	// ...

	dependencies {

		// ...
		// other dependencies...
		// ...

		runtime &#x27;org.springframework.security:spring-security-core:3.0.2.RELEASE&#x27; // http -&gt; https redirecting
		runtime &#x27;org.springframework.security:spring-security-web:3.0.2.RELEASE&#x27; // http -&gt; https redirecting
	}
}
</pre>
<p>You&#8217;ll need to add a Servlet Filter to web.xml now.  There are a couple of ways to do this in Grails, namely writing a plugin that can <a href="http://grails.org/doc/latest/guide/12.%20Plug-ins.html#12.7 Hooking into Runtime Configuration">modify web.xml dynamically</a>, or <a href="http://grails.org/doc/latest/ref/Command%20Line/install-templates.html">installing the Grails templates</a> into your app and manually editing web.xml.  I had planned on doing the first option (writing a plugin), but it was overkill for this, so I decided against it.  I&#8217;m glad I did.  Installing the Grails templates and modifying web.xml manually is painless.</p>
<p>Run <span class="mono">grails install-templates</span> from the root of your Grails project to install the web.xml template (along with a few others).  Next, edit <span class="mono">src/templates/war/web.xml</span> and add the filter definition and mapping in the appropriate places:</p>
<pre class="brush: xml">
&lt;!-- START: use SSL on secure pages --&gt;
&lt;filter&gt;
	&lt;filter-name&gt;channelProcessingFilter&lt;/filter-name&gt;
	&lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
&lt;/filter&gt;
&lt;!-- END: use SSL on secure pages --&gt;

&lt;!-- ... other filter definitions ... --&gt;

&lt;!-- START: use SSL on secure pages --&gt;
&lt;filter-mapping&gt;
	&lt;filter-name&gt;channelProcessingFilter&lt;/filter-name&gt;
	&lt;url-pattern&gt;/*&lt;/url-pattern&gt;
&lt;/filter-mapping&gt;
&lt;!-- END: use SSL on secure pages --&gt;
</pre>
<p>Make sure that the filter-mapping is the first filter-mapping defined in web.xml (above <span class="mono">charEncodingFilter</span> and <span class="mono">sitemesh</span>).</p>
<p>Now to actually define the filter.  Define it as a Spring managed bean in <span class="mono">grails-app/conf/spring/resources.groovy</span>:</p>
<pre class="brush: groovy">
import org.springframework.security.web.util.AntUrlPathMatcher
import org.springframework.security.web.access.intercept.DefaultFilterInvocationSecurityMetadataSource
import org.springframework.security.web.access.channel.SecureChannelProcessor
import org.springframework.security.web.access.channel.InsecureChannelProcessor
import org.springframework.security.web.access.channel.ChannelProcessingFilter
import org.springframework.security.web.access.channel.ChannelDecisionManagerImpl

beans = {

	// -------------------------------------------------------------------------
	// -------------------------------------------------------------------------
	// SPRING SECURITY (CHANNEL SECURITY)
	channelDecisionManager(ChannelDecisionManagerImpl) {
		channelProcessors = [new SecureChannelProcessor(),
							new InsecureChannelProcessor()]
	}
	securityMetadataSource(DefaultFilterInvocationSecurityMetadataSource,
							new AntUrlPathMatcher(),
							ChannelConfig.getChannelConfig()) {
		stripQueryStringFromUrls = true
	}
	channelProcessingFilter(ChannelProcessingFilter) {
		channelDecisionManager = ref(&quot;channelDecisionManager&quot;)
		securityMetadataSource = ref(&quot;securityMetadataSource&quot;)
	}

}
</pre>
<p><span class="mono"><a href="http://static.springsource.org/spring-security/site/docs/3.0.x/apidocs/org/springframework/security/web/access/channel/ChannelProcessingFilter.html">channelProcessingFilter</a></span> is the filter referenced in web.xml.  It will use the <span class="mono"><a href="http://static.springsource.org/spring-security/site/docs/3.0.x/apidocs/org/springframework/security/web/access/channel/ChannelDecisionManagerImpl.html">channelDecisionManager</a></span> to decide if the current protocol (http or http<strong>s</strong>) needs to be switched to the other.  And how does <span class="mono">channelProcessingFilter</span> know which URLs require which protocol?  <span class="mono"><a href="http://static.springsource.org/spring-security/site/docs/3.0.x/apidocs/org/springframework/security/web/access/intercept/DefaultFilterInvocationSecurityMetadataSource.html">securityMetadataSource</a></span>, of course. By default, ports 80 and 8080 are considered insecure, and 443 and 8443 are considered secure.  This means that the defaults should work for both development (8080 and 8443) and production (80 and 443).  If you&#8217;re curious as to the specifics of what these beans do, check their Javadocs.  </p>
<h3>Configure which URLs require which protocol</h3>
<p>See that call above to <span class="mono">ChannelConfig.getChannelConfig()</span>?  That&#8217;s where the configuration for URLs is stored.  Create <span class="mono">grails-app/conf/ChannelConfig.groovy</span>:</p>
<pre class="brush: groovy">
import org.springframework.security.access.ConfigAttribute
import org.springframework.security.access.SecurityConfig
import org.springframework.security.web.access.intercept.RequestKey

class ChannelConfig {

	private ChannelConfig() {} // prevent instantiation

	static def getChannelConfig() {
		LinkedHashMap&lt;RequestKey,java.util.Collection&lt;ConfigAttribute&gt;&gt; requestMap = new LinkedHashMap&lt;RequestKey, Collection&lt;ConfigAttribute&gt;&gt;()

		// resources that can be served over http or https (typically whatever the containing page is served as)
		requestMap.put new RequestKey(&quot;/images/**&quot;), [new SecurityConfig(&quot;ANY_CHANNEL&quot;)]
		requestMap.put new RequestKey(&quot;/css/**&quot;), [new SecurityConfig(&quot;ANY_CHANNEL&quot;)]
		requestMap.put new RequestKey(&quot;/js/**&quot;), [new SecurityConfig(&quot;ANY_CHANNEL&quot;)]
		requestMap.put new RequestKey(&quot;/favicon.ico&quot;), [new SecurityConfig(&quot;ANY_CHANNEL&quot;)]

		// resources that must be served over https
		requestMap.put new RequestKey(&quot;/signup&quot;), [new SecurityConfig(&quot;REQUIRES_SECURE_CHANNEL&quot;)]
		requestMap.put new RequestKey(&quot;/auth/**&quot;), [new SecurityConfig(&quot;REQUIRES_SECURE_CHANNEL&quot;)]
		requestMap.put new RequestKey(&quot;/admin/**&quot;), [new SecurityConfig(&quot;REQUIRES_SECURE_CHANNEL&quot;)]
		requestMap.put new RequestKey(&quot;/app/account/edituser&quot;), [new SecurityConfig(&quot;REQUIRES_SECURE_CHANNEL&quot;)]

		// resources that must be served over http (basically everything else not already listed above)
		requestMap.put new RequestKey(&quot;/**&quot;), [new SecurityConfig(&quot;REQUIRES_INSECURE_CHANNEL&quot;)] // all other pages should be served over http

		requestMap
	}
}
</pre>
<p>What&#8217;s happening here?  First, there&#8217;s some horrible nastiness with the definition of the <span class="mono">requestMap</span> variable (gotta love generics).  This is how your configuration is stored and the format <span class="mono">securityMetadataSource</span> expects.  Each call to <span class="mono">requestMap.put()</span> specifies a URL or URL pattern (Apache Ant pattern style) and its corresponding channel security (i.e. http or http<strong>s</strong>).  </p>
<p>There are three options for channel security:</p>
<ul>
<li><span class="mono">ANY_CHANNEL</span> &#8211; Serve the resource with either http or http<strong>s</strong> &#8211; it doesn&#8217;t matter.  This is good for images, CSS, and JavaScript, which should be served using the same protocol as the containing page.</li>
<li><span class="mono">REQUIRES_SECURE_CHANNEL</span> &#8211; Serve the resource using http<strong>s</strong>.  This is what will automatically redirect the user to http<strong>s</strong> when needed.</li>
<li><span class="mono">REQUIRES_INSECURE_CHANNEL</span> &#8211; Serve the resource using http.  You don&#8217;t want to serve your entire site over http<strong>s</strong>, right?  </li>
</ul>
<p>In the configuration above, I first specified all the resources that are protocol agnostic &#8211; images, CSS, etc.  Then in the next section I specified all of the resources that must be served securely.  Finally, the <span class="mono">/**</span> specifies that anything else not already listed above will be served over plain http.</p>
<p>Note that <strong>order matters</strong> (hence the use of a LinkedHashMap that retains insertion order).  Rules should be added from most specific to least specific.  For example, if the <span class="mono">/**</span> rule was at the very top, it would match every resource request, which would be very bad.  </p>
<p>If you want to see the debug output from Spring Security as it makes its decisions about whether or not a resource is being served over the right protocol, add the following to your Log4j config in <span class="mono">grails-app/conf/Config.groovy</span>:</p>
<pre class="brush: groovy">
log4j = {

	// ...
	// ... other logging definitions
	// ...
	debug &#x27;org.springframework.security&#x27;

}
</pre>
<h3>Testing</h3>
<p>Since you&#8217;re testing your app with http<strong>s</strong>, make sure to start Grails with the <span class="mono">-http<strong>s</strong></span> option:</p>
<p><code>grails run-app -http<strong>s</strong></code></p>
<p>This will automatically set up a fake SSL certificate for your app and run http<strong>s</strong> on port 8443.  </p>
<p>You should now be able to go to <span class="mono">http://localhost:8080</span> and see that it is indeed served over http.  If you have a sign up page like configured above, navigating to <span class="mono">http://localhost:8080</span> should automatically redirect your browser to <span class="mono">http<strong>s</strong>://localhost:8443</span>.  Clicking on a link to <span class="mono">http<strong>s</strong>://localhost:8443/index</span> should then automatically take you back to <span class="mono">http://localhost:8080/index</span>.  You&#8217;ll also notice that resources like images, CSS, and JavaScript are served using whatever protocol the containing page uses.  </p>
<h3>Caveats</h3>
<p>Did you know that if an HttpSession is created over an http<strong>s</strong> connection that it won&#8217;t be available to the user when they go back to regular old http?  This means that if you have your user log in using http<strong>s</strong>, when they are redirected back to http, their session will be gone.  This won&#8217;t be a problem for you if you plan to have users always use http<strong>s</strong> once they&#8217;ve logged in.  But some sites (flickr, for example) prefer to serve most of their pages using http for performance reasons once the user has logged in securely.  There is a trick to allow http<strong>s</strong> -&gt; http session migration, but that&#8217;s a topic for a later blog post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.juliesoft.com/2010/04/automatic-httphttps-switching-with-grails/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
