<?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; JForum</title>
	<atom:link href="http://blog.smartkey.co.uk/tag/jforum/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>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>
	</channel>
</rss>
