<?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>Jayway Team Blog &#187; grails</title>
	<atom:link href="http://blog.jayway.com/tag/grails/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jayway.com</link>
	<description>Sharing Experience</description>
	<lastBuildDate>Sat, 11 Feb 2012 10:33:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Spring Security For Real with Grails</title>
		<link>http://blog.jayway.com/2009/11/23/spring-security-for-real-with-grails/</link>
		<comments>http://blog.jayway.com/2009/11/23/spring-security-for-real-with-grails/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 18:41:34 +0000</pubDate>
		<dc:creator>Mattias Hellborg Arthursson</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[spring security]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=2248</guid>
		<description><![CDATA[Spring Security is one of the basic building blocks I use pretty much every time I'm constructing a web application. It's a very mature and incredibly powerful security framework, one of its main benefits being its versatility. There are hooks and plugs everywhere, allowing you to extend and combine basically any way you want. Now, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://static.springsource.org/spring-security/site/">Spring Security</a> is one of the basic building blocks I use pretty much every time I'm constructing a web application. It's a very mature and incredibly powerful security framework, one of its main benefits being its versatility. There are hooks and plugs everywhere, allowing you to extend and combine basically any way you want.</p>
<p>Now, if you want to apply security in a Grails application you are typically pointed in the direction of the <a href="http://grails.org/plugin/acegi">Grails Acegi Plugin</a>, which does a rather decent job at applying basic security to your Grails application. It quickly falls short however when you need to start doing something more than the bare basics (which you pretty much always need to do); even though the plugin is based on Spring Security, far from everything in the original framework is supported in the plugin, and hooking in custom components is pretty much out of the question. In addition to this, the Acegi Plugin is haunted by a couple of pretty annoying bugs.</p>
<p>Bottom line: for any real-world scenario you will most likely want to fall back to the original, i.e. use the original Spring Security framework in your Grails application. Since Grails is Spring-based it shouldn't be all that much work to set that up, right? Well basically yes, but as I set out do to it I ran into a number of problems before I got it right, so I thought I might as well line out the steps and pitfalls.</p>
<h4>1. Download and Install the Spring Security jars</h4>
<p>Typically, for the basic setup you should need only the <code>spring-security-core.jar</code> and <code>spring-security-core-tiger.jar</code>, but depending on your requirements you might need to include more of the Spring Security binaries. Place the jars in your <code>lib</code> directory of your Grails application.</p>
<h4>2. Install Templates</h4>
<p>Spring Security is based on an HTTP filter chain, which needs to be declared in the <code>WEB-INF/web.xml</code> file of the web application. This file is normally automatically generated for you by Grails, but for the event that you need more control (such as this occasion) you can have the default file generated for you to edit. The command for this is <code>grails install-templates</code>. This will generate a number of files, and the <code>web.xml</code> will be ready for editing under <code>src/templates/war</code>.</p>
<h4>3. Add the Spring Security Filter Chain</h4>
<p>There will be a number of filters defined in the <code>web.xml</code> file already. Add the Spring Security filter after the other filter definitions, but before the filter-mapping entries (all the filter definitions need to be placed before the filter-mapping ones, or else evil things will happen with any additional filters generated by Grails and we'll get in trouble when we deploy in tomcat).</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;filter<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;filter-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>springSecurityFilterChain<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/filter-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;filter-class<span style="font-weight: bold; color: black;">&gt;</span></span></span>org.springframework.web.filter.DelegatingFilterProxy<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/filter-class<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/filter<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Now, after the other filter-mapping entries, add the filter-mapping for the Spring Security filter:</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;filter-mapping<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;filter-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>springSecurityFilterChain<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/filter-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;url-pattern<span style="font-weight: bold; color: black;">&gt;</span></span></span>/*<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/url-pattern<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/filter-mapping<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<h4>4. Spring Security Configuration </h4>
<p>Now we're ready to add the Spring Security configuration XML. Note that this configuration <b>needs</b> to be placed in <code>grails-app/conf/spring/resources.xml</code>. I initially tried to put it in <code>WEB-APP/WEB-INF/applicationContext.xml</code> but due to the Grails ApplicationContext loading magic that attempt failed spectacularly. We'll start out with a minimal Spring Security configuration just to get things going; for more information the configuration topic I'll refer to the <a href="http://static.springsource.org/spring-security/site/docs/2.0.x/reference/springsecurity.html">reference documentation</a>.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;beans</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span>
        <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
        <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.4.xsd&quot;</span>
        <span style="color: #000066;">xmlns:sec</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/security&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;sec:http<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;sec:intercept-url</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;/**&quot;</span> <span style="color: #000066;">access</span>=<span style="color: #ff0000;">&quot;ROLE_USER&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;sec:http-basic</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/sec:http<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;sec:authentication-provider<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;sec:user-service<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;sec:user</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;mattias&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;12345&quot;</span> <span style="color: #000066;">authorities</span>=<span style="color: #ff0000;">&quot;ROLE_USER&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/sec:user-service<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/sec:authentication-provider<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/beans<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p><b>Another note of caution here:</b> If there is anything incorrect in your <code>resources.xml</code> Grails will <b>happily and silently ignore this</b> and go ahead and start anyway. Therefore, whenever you start doing stuff with your own custom Spring configuration in a Grails app it is imperative to make sure to configure your logging so that Spring warning and error messages are logged properly or you'll be completely in the dark trying to figure out what went wrong.</p>
<h4>All done</h4>
<p>As it turns out this wasn't as bad as expected. You're now all set to unleash the full power of Spring Security on your Grails application.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2009/11/23/spring-security-for-real-with-grails/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Setting Up Grails Projects in IntelliJ Idea</title>
		<link>http://blog.jayway.com/2009/09/06/setting-up-grails-projects-in-intellij-idea/</link>
		<comments>http://blog.jayway.com/2009/09/06/setting-up-grails-projects-in-intellij-idea/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 17:24:01 +0000</pubDate>
		<dc:creator>Mattias Hellborg Arthursson</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[buildconfig]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[idea]]></category>
		<category><![CDATA[intellij]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[setup]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=1927</guid>
		<description><![CDATA[Since I've started doing some stuff in Grails lately I've virtually been forced to start looking for an alternative IDE. I've been an Eclipse guy for the last five years or so; ever since I got out of the JBuilder swamp. Unfortunately, the only IDE with decent support for Grails seems to be Idea (yes [...]]]></description>
			<content:encoded><![CDATA[<p>Since I've started doing some stuff in Grails lately I've virtually been forced to start looking for an alternative IDE. I've been an Eclipse guy for the last five years or so; ever since I got out of the JBuilder swamp. Unfortunately, the only IDE with decent support for Grails seems to be Idea (yes I tried NetBeans, but it was so dreadfully slow it wasn't even funny). Now, even though it is possible to get it to work, it was very far from painless before it was all set up. Since I had problems, and since I had a really hard time finding information about this I figured I might as well share what I had to do to make it work.</p>
<p>Part of the problem was (I guess) that the projects were created outside of Idea, so they had to be imported. Another thing that turned out to be a big problem was that there are a number of inter-dependencies between the projects (set up as plugin dependencies in <code>BuildConfig.groovy</code>). Now, here are the steps I had to go through to make a multi-sub-project Grails project working in IntelliJ Idea:</p>
<ul>
<li>First of all, create an empty top-level project (actively uncheck the 'Create Module' checkbox).</li>
<li>Then, for each of the sub projects, create a new module. The tricky part here is that it turned out that you need to select 'Create from scratch..' option and select the root directory of each Grails app as module directory (and name). Then, just select 'Grails module', and you're done (for now)</li>
<li>Now we need to set up the build paths manually. For each of the modules that have local libraries included in the <code>lib</code> directory, that directory needs to be added manually as a jar directory dependency of that module. Make sure you check the 'export' checkbox as well, so that the binaries are included when you build and when if this module is referenced from another module (see below).</li>
<li>Next step is to manually remove and re-add each of the required plugins in each module. Be sure to re-add them one at a time; it didn't work to add multiple plugins at once</li>
<li>Now if you have inter-dependencies between your modules (e.g. one app uses a plugin you made yourself, set up in <code>BuildConfig.groovy</code>), these need to be set up as module dependencies.</li>
<li>Finally we're done. Now, double check the build path in the module settings window and make sure nothing is marked red. Try to build the project and you should be all set.</li>
</ul>
<p>Obviously, the bad thing here is that it's an incredible amount of work involved in getting everything up and working. The good thing however is that once you have it all set up it works really well. Code navigation and even debugging a remote Grails application works as a charm. That said, I'm still not comfortable with how Idea works. It just feels awkward somehow. I can't wait for when the SpringSource guys get this working in Spring IDE so that I can get back to my IDE of choice.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2009/09/06/setting-up-grails-projects-in-intellij-idea/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

