<?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>Smartkey - Java Software Consultancy &#187; Grails</title>
	<atom:link href="http://blog.smartkey.co.uk/tag/grails/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.smartkey.co.uk</link>
	<description></description>
	<lastBuildDate>Thu, 02 Sep 2010 15:25:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Formatting the Grails RichUI AutoComplete component</title>
		<link>http://blog.smartkey.co.uk/2009/10/formatting-the-grails-richui-autocomplete-component/</link>
		<comments>http://blog.smartkey.co.uk/2009/10/formatting-the-grails-richui-autocomplete-component/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 20:04:20 +0000</pubDate>
		<dc:creator>Steve Neal</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Grails programming]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[AutoComplete]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[RichUI]]></category>

		<guid isPermaLink="false">http://blog.smartkey.co.uk/?p=321</guid>
		<description><![CDATA[The RichUI component plug-in for Grails is great! It provides a really simple means of accessing rich Ajax functionality in a Grails application. I used this plug-in recently to implement an AutoComplete text field but needed to apply some formatting to the results. This post explains how I did this.]]></description>
			<content:encoded><![CDATA[<p>The RichUI component plug-in for Grails is great! It provides a really simple means of accessing rich Ajax functionality in a Grails application. I used this plug-in recently to implement an AutoComplete text field but needed to apply some formatting to the results. This post explains how I did this.</p>
<p>I&#8217;m not going to explain anything that&#8217;s <a href="http://grails.org/RichUI+Plugin#AutoComplete" target="_blank">already documented</a> for RichUI&#8217;s AutoComplete component. Basic formatting customisation is already documented, so if you&#8217;re looking to change the colours used or the width of the output then take a look there.</p>
<p>The code I was working on searched a multi-lingual database for words, the initial output being displayed looked like this:</p>
<p><img class="aligncenter size-full wp-image-331" title="plain autocomplete" src="http://blog.smartkey.co.uk/wp-content/uploads/2009/10/Picture-5.png" alt="plain autocomplete" width="212" height="249" /></p>
<p>in addition to this, I wanted to display locale flags for the languages alongside the results:</p>
<p><img class="aligncenter size-full wp-image-332" title="Picture 4" src="http://blog.smartkey.co.uk/wp-content/uploads/2009/10/Picture-4.png" alt="Picture 4" width="211" height="251" /></p>
<p>This change would involve modifying, not just the styles, but the actual HTML  that was being used to render the results by the AutoComplete component.</p>
<p>The RichUI plug-in is based on the <a href="http://developer.yahoo.com/yui/2/" target="_blank">Yahoo User Interface Library</a> or YUI for short. The AutoComplete component in RichUI, is just a Grails tag that creates a YUI AutoComplete component; the documentation for which explains how the HTML for the results list <a href="http://developer.yahoo.com/yui/autocomplete/#formatting">can be customised</a>.</p>
<p>In short, to customise the HTML, there is a method named &#8216;<strong>formatResult</strong>&#8216; on the AutoComplete JavaScript object that gets called to render each of the results. By default, this method just returns the plain text of the result. However, it can be overridden to provide custom mark-up.</p>
<p>The documentation for the RichUI AutoComplete tag explains how a JavaScript function can be registered to handle an &#8216;onItemSelect&#8217; event, but there is no explanation of how to override any other methods. After a little investigation of the RichUI plug-in code I found that the renderer that produces the HTML for the tag does in fact and associate any attributes declared on the tag as properties/methods on the YUI component. Note that this is not a documented feature, but one I would hope would not be changed in future versions of this plug-in.</p>
<p>So by declaring the RichUI tag like this:</p>
<pre class="brush: xml">
&lt;richui:autoComplete
    name=&quot;keywords&quot;
    action=&quot;${createLinkTo(&#039;dir&#039;: &#039;word/findAjax&#039;)}&quot;
    maxResultsDisplayed=&quot;20&quot;
    formatResult=&quot;myFormatResult&quot;/&gt;
</pre>
<p>the renderer will generate JavaScript like this; setting not only the formatResult event handler, but the maxResultsDisplayed property too:</p>
<pre class="brush: html">
autoComplete = new YAHOO.widget.AutoComplete(&#039;keywords&#039;,&#039;...&#039;, dataSource);
autoComplete.maxResultsDisplayed = 20;
autoComplete.formatResult = myFormatResult;
</pre>
<p>it&#8217;s then just a matter of implementing a JavaScript function that generates the HTML for each of the items:</p>
<pre class="brush: javascript">
function formatResult(oResultData, sQuery, sResultMatch) {
  var sMarkup;
  var locale = oResultData[1];
  var imageUri = &quot;${createLinkTo(dir:&#039;/images/flags&#039;)}/&quot; + locale + &quot;.png&quot;;
  if (sResultMatch) {
    sMarkup = &quot;&lt;img src=&quot; + imageUri + &quot;/&gt; &quot; + sResultMatch
  } else {
    sMarkup = &quot;&quot;
  }
  return sMarkup;
}
</pre>
<p>Finally, it&#8217;s worth noting here that the data returned from the search controller is available in the &#8216;oResultData&#8217; array that gets passed in to this function. In this example, you can see that the locale for the word is being accessed and used to generate the image URI.</p>
<p>To achieve this, the response is being generated in the search controller like this:</p>
<pre class="brush: javascript">
render(contentType: &quot;text/xml&quot;) {
  results() {
    words.each { w -&gt;
      result() {
        name(w.stem)
        id(w.locale)
      }
    }
  }
}
</pre>
<p>the name and id elements that are being produced in the XML are those specified in the schema that RichUI uses. The name element is the value that is usually displayed by the component, the ID is a supplemental value that is available to the RichUI &#8216;onItemSelect&#8217; JavaScript event handler. it should be possible to extend this but I&#8217;ll leave that challenge for another day&#8230;</p>
<p>If you&#8217;d like to see this code in action take a look at the <a href="http://www.languagespider.com" target="_blank">Language Spider</a> project web-site.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartkey.co.uk/2009/10/formatting-the-grails-richui-autocomplete-component/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using the JForum SSO plug-in from Grails</title>
		<link>http://blog.smartkey.co.uk/2009/10/using-the-jforum-sso-plug-in-from-grails/</link>
		<comments>http://blog.smartkey.co.uk/2009/10/using-the-jforum-sso-plug-in-from-grails/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 16:02:08 +0000</pubDate>
		<dc:creator>Steve Neal</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tool support]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JForum]]></category>
		<category><![CDATA[SSO]]></category>

		<guid isPermaLink="false">http://blog.smartkey.co.uk/?p=279</guid>
		<description><![CDATA[How to apply Single Sign On (SSO) to JForum from within a Grails application.]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://blog.smartkey.co.uk/2009/10/secure-sso-for-jforum/" target="_self">previous post</a> I explained how the JForum SSO plug-in can be used to secure a JForum application.</p>
<p>In this post I&#8217;ll demonstrate how the same principle can be applied in a Grails application.</p>
<p>Basically, just about everything from the previous post is the same, except for how the filtering of requests and the sending of the cookies from the host application is performed.</p>
<p>In Grails it is simple to write web filters. Just create a Groovy class with a name that ends with &#8216;Filters&#8217; in your conf folder and add closures that define the filtering behaviour:</p>
<pre class="brush: java">
class MyFilters {
    def filters = {
        myFirstFilter(controller: &#039;*&#039;, action: &#039;*&#039;) {
            before = {
                  //code here is executed before the controller has been accessed
            }
            after = {
                  //code here is executed after the controller has been accessed
            }
            afterView = {
                  //code here is executed after the view has been rendered
            }
        }
    }
}
</pre>
<p>in this example, there is a single filter called &#8216;myFirstFilter&#8217; that will be applied to all actions on all controllers, which illustrates the three filtering points available in Grails.</p>
<p>So given a Grails application service called &#8216;userService&#8217; that returns us a domain object for the currently logged in user, then we could write a cookie sending filter which uses the SSO plug-in like this:</p>
<pre class="brush: java">
class SecurityFilters {
  def userService;

  def filters = {
    jForumSecureSSOCookie(controller: &#039;*&#039;, action: &#039;*&#039;) {
      after = {
        if (userService.getUser()) {
          def user = userService.getUser();
          def encryptedValues = SecurityTools.getInstance().encryptCookieValues(user.email, user.username);

          Cookie c = new Cookie(SecurityTools.FORUM_COOKIE_NAME, encryptedValues)
          c.maxAge = -1;
          c.path = &quot;/&quot;
          c.comment = &quot;SSO cookie for language spider forum&quot;
          response.addCookie(c)
        } else {
          //user is not logged in so kill the cookie
          //(removing cookies does not work reliably in all browsers)
          Cookie c = new Cookie(SecurityTools.FORUM_COOKIE_NAME, &quot;&quot;)
          c.maxAge = -1;
          c.path = &quot;/&quot;
          c.comment = &quot;SSO cookie for language spider forum&quot;
          response.addCookie(c)
        }
      }
    }
  }
}
</pre>
<p>Because, Grails runs in a Java environment, all other configuration, including the JAR file deployment remain as discussed in the previous post.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartkey.co.uk/2009/10/using-the-jforum-sso-plug-in-from-grails/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Secure single sign on (SSO) for JForum</title>
		<link>http://blog.smartkey.co.uk/2009/10/secure-sso-for-jforum/</link>
		<comments>http://blog.smartkey.co.uk/2009/10/secure-sso-for-jforum/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 14:32:28 +0000</pubDate>
		<dc:creator>Steve Neal</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tool support]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[JForum]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[SSO]]></category>

		<guid isPermaLink="false">http://blog.smartkey.co.uk/?p=225</guid>
		<description><![CDATA[I recently developed a web application that used the excellent open source project JForum for its forum pages. The one thing that was missing from JForum though was a secure SSO module. In this article I&#8217;ll explain why the SSO solution bundled with JForum was not secure enough for our purposes and I&#8217;ll show you how [...]]]></description>
			<content:encoded><![CDATA[<p>I recently developed a web application that used the excellent open source project JForum for its forum pages. The one thing that was missing from JForum though was a secure SSO module. In this article I&#8217;ll explain why the SSO solution bundled with JForum was not secure enough for our purposes and I&#8217;ll show you how I solved this problem.</p>
<p>As the SSO code I wrote didn&#8217;t have any dependency on our applications classes, I decided to package and release it as a JAR file that anyone can use.  If you&#8217;d like to use it, then you can <a href="http://www.smartkey.co.uk/tools.html" target="_blank">download it from the tools page</a> on this website; instructions on how it words and how to configure JForum to use it are detailed below.</p>
<h3>Integrating JForum into an existing application</h3>
<p>JForum is indented to be used as either a stand-alone forum, or as an integrated solution for existing sites. The simplest way to integrate JForum with an existing application is simply to deploy it as a second named application under the same domain. For example, if your application is running on a server at:</p>
<pre>http://www.myapplication.com/</pre>
<p>then just run the JForum application under the same domain as a separate application, for example:</p>
<pre>http://www.myapplication.com/forum</pre>
<p>you can then just link to it from your web pages. Customise the JForum page templates to look like those from your own application and you&#8217;re almost done.</p>
<p>The last thing that you&#8217;ll want to do is automatically log users in to the forum once they&#8217;re logged into your application. If you don&#8217;t do this then your users will have to re-register with JForum just to use the forum pages! Fortunately, JForum ships with a simple SSO module. Unfortunately it&#8217;s not very secure.</p>
<p>If you&#8217;re running JForum on the same domain as the application your are integrating it with, then cookies set by one application will be visible to the other; as far as the browser can tell, its interacting with a single application. The standard SSO solution that ships with JForum exploits this fact and if your application sets a cookie with the user&#8217;s screen name and email address, JForum will automatically log them in to the forum pages for you.</p>
<p>This is a neat and simple solution but it does have a real security hole. If a hacker decides that they want to log into the forum and post messages as another user, then all they need to do is make their browser send a cookie with the name and email details of the users account they want access and JForum will then just log them into it. This is easy to do with something like Firefox&#8217;s firebug plug-in and doesn&#8217;t require any great skill.</p>
<p>JForum does provide an API with hooks for implementing your own SSO integration. In the JForum documentation, the example demonstrates how, in addition to receiving the user&#8217;s credentials (again via a plain text cookie), you could make calls to your database to access further user information. This does not address the security issue outlined above. Further work is required to achieve this.</p>
<h3>A more secure solution</h3>
<p>In the solution I developed, rather than sending a plain text user name to JForum in a cookie, an encrypted value is passed between the applications instead. By using a strong encryption algorithm it is possible to authenticate the user just once in the main application, and then send an encrypted token in the cookie that can be used to authenticate the user in JForum. This approach has the distinct advantage of preventing any hackers from being able to spoof user names by simply sending them in a cookie.</p>
<p>So, for example, if you encrypt your user&#8217;s name and email address before sending them in a cookie, anyone examining the cookie data will see something resembling:</p>
<pre>b259fa5bb42d8c53280c54bbb16d9b814574443d903eb85ba5594ef58b374c8d</pre>
<p>this can be decrypted by JForum and the users name and email address retrieved from it.</p>
<h3>Configuring and using the JForumSecureSSO plug-in</h3>
<p>The steps involved to use this plug-in are:</p>
<ol>
<li>Change the default encryption password used</li>
<li>Install the JAR file in each of the applications</li>
<li>Implement a cookie filter for your application</li>
<li>Configure JForum to use your encrypted cookie</li>
</ol>
<p>Lets look at these in more detail:</p>
<p><em>1. Change the default encryption password used</em></p>
<p>If you take a look in the META-INF folder in the jforum-secure-sso.jar file you&#8217;ll find a properties file that contains a property called security.password. The default value for this property is &#8216;change this&#8217;.</p>
<p>This property value is the password used by the encryption libraries as a seed for the encryption that is carried out on the cookie data. Update the JAR file by changing the password to a value that only you know &#8211; you should make this at least 16 chars long.</p>
<p>Note that you won&#8217;t use this password anywhere else in your application so you could just enter some random characters here.</p>
<p><em>2. Install the JAR file in each of the applications</em></p>
<p>Copy the JAR file with the modified password into the WEB-INF/lib folders of both your application and JForum too. This ensures that the encryption routines in the JAR files will now both be using your secret password when encrypting/decrypting the data.</p>
<p><em>3. Implement a cookie filter for your application</em></p>
<p>In order to ensure that an encrypted cookie is sent for any authenticated users, you&#8217;ll need to add a little functionality to your application.</p>
<p>There are a number of variations on how you might do this depending on the security system that you are using. For this reason, there are no classes in the JAR file that do this for you &#8211; time for you to cut a little code!</p>
<p>Generally, the best way to send the cookie will be from within a Web Filter. These are a standard feature since Servlet 2.3 specification and are are supported by all but the most antique application servers. The filter should be applied to all URLs that your application supports and will need to send an encrypted cookie, something like this:</p>
<pre class="brush: java">
import uk.co.smartkey.jforumsecuresso.SecurityTools;

//get your user&#039;s details from wherever they are available in  your application
User user = session.getAttribute(&#039;user&#039;);

//encrypt them using your secret password
String encryptedData = SecurityTools.getInstance().encryptCookieValues(user.getEmail(), user.getUserName());

//send the cookie using the predefined cookie name
Cookie c = new Cookie(SecurityTools.FORUM_COOKIE_NAME, encryptedData)
c.maxAge = -1;
c.path = &quot;/&quot;
response.addCookie(c)
</pre>
<p><em>4. Configure JForum to use your encrypted cookie</em></p>
<p>In the JForum configuration file, you&#8217;ll need to set the following properties to ensure that your data is loaded and used to log your users in using SSO:</p>
<pre class="brush: xml">
authentication.type=sso
sso.implementation=uk.co.smartkey.jforumsecuresso.JForumSecureSSO
sso.redirect=http://www.myapplication.com/login.jsp
</pre>
<p>More details of these settings are available at the JForum web site.</p>
<h3>Comments</h3>
<p>If you think this could be of use to you, then you can download the distribution files from our <a href="http://www.smartkey.co.uk/tools.html" target="_self">tools page</a>. This project has been tested to work with JForum 2.1.8 running on Tomcat 6 and is built using Maven. The source code is included in the distribution and is released using the same BSD license as JForum. If you&#8217;d like to add any functionality, I&#8217;ll be happy to include it in a future release.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartkey.co.uk/2009/10/secure-sso-for-jforum/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>InteliJ IDEA is now open source!</title>
		<link>http://blog.smartkey.co.uk/2009/10/intelij-idea-is-now-open-source/</link>
		<comments>http://blog.smartkey.co.uk/2009/10/intelij-idea-is-now-open-source/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 20:42:02 +0000</pubDate>
		<dc:creator>Steve Neal</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tool support]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[IDEA]]></category>
		<category><![CDATA[IntelliJ]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://blog.smartkey.co.uk/?p=209</guid>
		<description><![CDATA[IntelliJ have open sourced IDEA. What does this mean to the Java and Groovy/Grails communities?]]></description>
			<content:encoded><![CDATA[<p>IntelliJ <a href="http://www.jetbrains.com/idea/nextversion/free_java_ide.html">announced today</a> that version 9 of their Java IDE &#8220;IDEA&#8221; will be open sourced.</p>
<p>Now I&#8217;ve got to admit to being a big fan of IDEA. I&#8217;ve been using it for years now, and as the IntelliJ people have been saying all along: &#8220;<em>it&#8217;s the best Java IDE that money can buy</em>&#8220;. Well now it looks like it may well be the best free Java IDE too!</p>
<p>If you&#8217;ve not tried it, then now might be the perfect time to download it and give it a go. I can guarantee that after you&#8217;ve invested a little effort in figuring out what it can do for you, your productivity will increase dramatically. And that&#8217;s what&#8217;s always been key for me: if the time I save using the tool costs me less than the license fee, then it&#8217;s a no-brainer: pay up and work more efficiently. It&#8217;s  a simple value-for-money decision.</p>
<p>So what can it do? Well, for example, can your IDE attach to your database, load the schema and then give you code completion in the SQL strings that you write when programming JDBC? Work with Hibernate instead? Then maybe you&#8217;d appreciate the code completion for your HQL queries and also in  your mapping files. Want a UML diagram generated from your source code? No problem. If you&#8217;re a fan of Spring, then you might like the graphical view of the dependencies in a Spring application context? Need to see if your Spring pointcut syntax is right? Then a keyboard shortcut to view the advised methods on your beans will help with that. I could go on and on, but you probably get the idea.</p>
<p>Now this is where things get a little complicated. The JavaEE and framework features I&#8217;ve listed above won&#8217;t be available in the open-source, or &#8220;community&#8221;, edition. The JavaEE support is reserved for those that are still prepared to pay for it. Fair enough you might say; if you want better JavaEE support in Eclipse you&#8217;ll likely choose to use MyEclipse which currently costs over $150 and offers some of the best support available for Web development in that IDE. And I&#8217;d have to agree with  you: you pays your money, you takes your choice.</p>
<p>Regardless of this, the features available in the community edition of IDEA still far exceed those available in most other free Java IDEs and, in my opinion, are more reliable and robust oot. IDEA not only provides Java coding support but also XML, Groovy and regular expression syntax too. Add to this Live Templates (a build in macro language for automating common code generation, like iteration over collections/arrays for example)  and you&#8217;ve got a feature set that will keep most Java developers very happy. For a complete comparison matrix of the features that are available in the community and the ultimate editions, <a href="http://www.jetbrains.com/idea/nextversion/editions_comparison_matrix.html" target="_blank">take a look at this link</a>.</p>
<p>This seems to me to be a very clever marketing decision by IntelliJ. They are clearly aware that their greatest barrier to mass adoption is not the quality of the IDE, but the price of a license, and that by releasing this edition of their application they have completely eliminated this.</p>
<p>Good move I say, and good luck.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.smartkey.co.uk/2009/10/intelij-idea-is-now-open-source/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
