Using Spring Security Plugin in Grails
14 June 2011 12:37 AM
During my quest on using the Spring Security Plugin in Grails I’ve faced some difficulties. I’m documenting what I’ve done here to future reference and hoping someone else find it useful.
1. Tutorial
Here’s a good tutorial about how to setup and start with the spring security plugin
http://blog.springsource.com/2010/08/11/simplified-spring-security-with-grails/
And the complete guide about the plugin
http://burtbeckwith.github.com/grails-spring-security-core/docs/manual/guide/single.html
2. Field or property cannot be found on object of type ‘org.springframework.security.web.access.expression.WebSecurityExpressionRoot’ Caused by: Failed to evaluate expression. Is ROLE_ prefix mandatory?
According to what I’ve read Spring Security uses two modes. A traditional mode and a mode based on Spring Expression Language (SpEL).
I’m not sure if its possible to specify which mode the plugin will use, as it’s done in Spring-Security
http://forum.springsource.org/showthread.php?78426-Failed-to-evaluate-expression-sec-intercept-url
But according to this post
http://permalink.gmane.org/gmane.comp.lang.groovy.grails.user/107548
and my experience, if you intend to work using the traditional config, you have to name your authorities with the prefix “ROLE_”. If you don’t do so the plugin will assume you’re working with SpEL and try to parse your authority name as an expression, throwing an exception.
3. UI
I was thinking on how to create the views and controller to support user registration and administration, when I found out there is a Spring-Security-UI plugin that does this for you. Here’s an example on how to do this
http://www.objectpartners.com/2011/05/24/customizing-the-grails-spring-security-ui-plugin/
and the complete documentation
http://burtbeckwith.github.com/grails-spring-security-ui/docs/manual/index.html
4. Installing Spring-Security-UI plugin. Failed to install plugin [mail-1.0-SNAPSHOT]. Plugin has missing JAR dependencies.
The Spring-Security-UI plugin depends on the Mail plugin which I could not install in my first attempt, because it’s dependencies cannot be resolved using the default grails repositories. So I had to uncomment the mavenCentral() repository in BuildConfig.groovy, uninstalled the previous plugin and reinstalled again. I found the answer in this thread:
5. Persistent cookies
To enable persistent cookie support you have to create a specific domain class as explained here
That’s all for the moment. I’ll continue working and updating this post
Read More

Recent Comments