Grails STS and Spring Security Core Plugin

Recently I have been digging into Grails, more specifically Grails 1.3.1, and it has been a rather enjoyable experience.  This post covers an issue I ran into when I tried to implement the Spring Security Core plugin.

I decided on this solution for my application security because it seemed to have all the hooks I needed and it seemed to be the most recent security plugin (for lack of better phrasing).  I tried the jsecurity and Acegi plugins as well, but I kept running into random compiler errors with each of these, so I went with Spring Security Core in hopes to side step the issues.  That approach did not work out and I had some minor class resolution issues.

Setup:

  • IDE – SpringSource Tool Suite – 2.3.2.Release (referred to STS from here on)
  • Grails – 1.3.1
  • Spring-Security-Core Plugin

My problems occurred after installing the plugin via the STS Grails command line feature.  Install for the plugin would run perfectly and then I would build out the code using the quickstart command as follows:

grails s2-quickstart DOMAIN_CLASS_PACKAGE USER_CLASS_NAME ROLE_CLASS_NAME [REQUESTMAP_CLASS_NAME]

This is when the problems started.  The Login and Logout Controllers had import error messages that told me that the following classes could not be resolved:

import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils

import org.springframework.security.authentication.AccountExpiredException
import org.springframework.security.authentication.CredentialsExpiredException
import org.springframework.security.authentication.DisabledException
import org.springframework.security.authentication.LockedException
import org.springframework.security.core.context.SecurityContextHolder as SCH
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter

So I looked around and saw that the Spring Security jars were not in my lib directory and that the plugin source folders were not in my project.  I then did some searching on Google and found a few hints as to what was up but nothing straight on.  So I embarked on trying to hack through the issue.

One Solution:

I downloaded the Spring Security jars and dropped them in to my project lib directory.  Then I changed my build path settings to include these jars (specifically the core and web jars).  That fixed all of the import issues for the Spring classes.  But I still had the Groovy/Grails security import issue.  In Grails 1.3.1 plugins do not install their source files in your project.  This is key.  To get past this I had to add the plugin source directories to my project.  I did this by linking to the src/java and src/groovy directories for the Spring-Security-Core plugin, which is located outside of your actual project.  The end result was no more class resolution issues, and I was off and rolling with security.

Concerns:

I don’t like the solution of linking to the external source files of the plugin as it may cause issues for someone else if they were to use my project artifact.  By using my artifact they would be missing the plugin source files.

The Best Solution:

Burt Beckwith forwarded me a link and this bit of advice -” this works with Grails 1.2 (and maybe 1.1) but it’s broken in 1.3 until STS 2.3.3 is released. But there’s a workaround: http://andrewclement.blogspot.com/2010/05/springsource-tool-suite-and-grails-13.html

This is the ideal solution for the issue

In Closing:

If anyone has ever run into this issue and has some feedback please hit me up on Twitter .  I would love to get feedback and discuss a better solution if there is one.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>