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).

http://burtbeckwith.github.com/grails-spring-security-core/docs/manual/guide/single.html#5.4%20Using%20Expressions%20to%20Create%20Descriptive,%20Fine-Grained%20Rules

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:

http://grails.1312388.n4.nabble.com/spring-security-ui-depending-on-mail-plugin-gt-dependency-resolution-fails-td3238433.html

5. Persistent cookies

To enable persistent cookie support you have to create a specific domain class as explained here

http://burtbeckwith.github.com/grails-spring-security-core/docs/manual/ref/Scripts/s2-create-persistent-token.html

 

That’s all for the moment.  I’ll continue working and updating this post :)

 

Read More

What I’ve learned about GORM

24 March 2011 11:09 PM

I’m starting to learn Grails and I’m working in a project where I have to connect an existing database to Grails by custom mapping. While working on this I’ve had some difficulties and questions, here’s a summary of what I’ve learned about them :)

Problem 1: Is there a tool that generates Groovy classes from existing tables?

Yes. It’s called GRAG and does a pretty decent job.  I still had to tweak somethings by hand,  but GRAG saved me a lot of time :D .

Problem 2: Is the id field mandatory in GORM?  How do I map a table in where the primary key is made of various fields and has no id of its own?

The identification field is mandatory.   Tables with composite keys can be mapped using the  ‘composite’  atributte in this way:

class Person {
  String firstName
  String lastName
  static mapping = {
      id composite:['firstName', 'lastName']
  }
}

http://grails.org/doc/latest/guide/5.%20Object%20Relational%20Mapping%20%28GORM%29.html#5.5.2.5%20Composite%20Primary%20Keys

Problem 3:  I didn’t realize ‘composite’ field’s  parameters were referring to  field names and not column names.

So in my first attempt to create the composite key I did this

class Person {
  String firstName
  String lastName
  static mapping = {
      id composite:['First', 'Last']
  }
}

Assumnig First and last were the names of the columns on the table. (Compare this with the section above)

http://grails.1312388.n4.nabble.com/DataSources-Plugin-with-Read-Only-Database-Unable-to-map-a-composite-key-No-property-found-for-name–td1391729.html

Problem 4:  Domain objects with composite keys must implement serializable

The compiler told me so XD

Problem 5:  ‘properties’  is a reserved word

I couldn’t give the name ‘properties’ to one of my fields.  Apparently it is a reserved word and cannot be used.

I wrote something like this:

class Item {
 
static hasMany = [properties: ItemProperties]
 
}

And the compiler gave me this error:

No such property: id for class: groovy.util.MapEntry

Googling I found this link

http://archive.codehaus.org/lists/org.codehaus.grails.user/msg/84b9b45c0806050258n118a1d66v82b9bdda4e4ed2b1@mail.gmail.com

and rewrote my code to:

class Item {
 
static hasMany = [itemProperties: ItemProperties]
 
}

which runs without problems :)

 

That’s all at the moment.  Hope someone would find this useful.

Read More

World of Warcraft Patch 4.0 Installation Issues

14 October 2010 3:10 AM

I do not play WOW but my brother does. He was getting trouble installing the new patch (4.0).

The symptoms were the following,

1. The Launcher was unable to get the information of the new patch. It showed the normal Lich King display. I checked the log file and it said,

#-----------------------------------------------------------
# System started at 2010-10-13 21:27:03.7500
# system: COMPUTERNAMEHERE
#-----------------------------------------------------------
21:27:03.7656 Launcher version 1.8.0.394
21:27:04.0937 Fetch version information from
us.version.worldofwarcraft.com
(http://206.18.98.54/update/PatchSequenceFile.txt).
21:27:04.5312 Received version information from

http://206.18.98.54/update/PatchSequenceFile.txt.

21:27:04.5312 No update is required.

2. When my brother logged in to his account the game showed him a list of WOW realms all in red (like they were unavailable), after selecting one of those, the game froze with the “Connecting” status.

3. When we tried to run the Repair tool it responded with the following error “Cannot connect to server to download repair information. Please try again later”

So… after looking for a while in the World of Warcraft forums we found the solution in this post.

We only had to download a new Repair tool from here and let it fix it all :D .  Now he’s happily downloading the patch.

I’m pasting the new information found in the log after the fix,  just for reference.

#-----------------------------------------------------------
# System started at 2010-10-13 21:44:10.8883
# system: COMPUTERNAMEHERE
#-----------------------------------------------------------
21:44:11.0156 Launcher version 2.1.1.1462
21:44:11.0156 Found incorrect InstallPath registry key entry for World
of Warcraft ('D:\World of Warcraft\').
21:44:11.0157 Found incorrect GamePath registry key entry for World of
Warcraft ('D:\World of Warcraft\Launcher.exe').
21:44:11.0158 Fixed incorrect InstallPath registry key entry for World
of Warcraft (now 'D:\Copy of World of Warcraft\').
21:44:11.0159 Fixed incorrect GamePath registry key entry for Launcher
(now 'D:\Copy of World of Warcraft\Launcher.exe').
21:44:11.4584 Reverting to old PSF patching system.
21:44:11.6755 Fetch version information from
us.version.worldofwarcraft.com
(http://206.18.98.51/update/PatchSequenceFile.txt).
21:44:12.1748 Fetch version information from
us.version.worldofwarcraft.com
(http://12.129.254.54/update/PatchSequenceFile.txt).
21:44:12.4277 Fetch version information from
us.version.worldofwarcraft.com
(http://12.129.222.52/update/PatchSequenceFile.txt).
21:44:12.6777 Fetch version information from
us.version.worldofwarcraft.com
(http://12.129.254.51/update/PatchSequenceFile.txt).
21:44:12.9155 Received version information from

http://12.129.222.52/update/PatchSequenceFile.txt.

21:44:12.9193 A tools update is required.
21:44:21.7756 Timeout from http://206.18.98.51/update/PatchSequenceFile.txt.
21:44:22.1968 Timeout from http://12.129.254.54/update/PatchSequenceFile.txt.
Read More

RedDwarf Project Configuration (Video)

5 October 2010 1:03 AM

Hello!!

I recently found a compilation of video tutorials  about Project Darkstar here.

The compilation includes a video tutorial of how to setup a project under Netbeans.   This one was very useful to me.  Because the same steps are valid for RedDwarf.

Darkstar: NetBeans Project Configuration from Project Darkstar on Vimeo.

Also there’s a version of how to set up the project under eclipse.

Darkstar Eclipse Project Configuration from Project Darkstar on Vimeo.

Many thanks to “Peter”  who was the person who created the tutorials :D

Tip:  You can watch the videos in HD @ Vimeo

Read More

Some resources for RedDwarf newcomers

20 September 2010 4:42 PM

Hello everyone!  As you may know,  I’m learning how to develop applications for the RedDwarf server.  At the beginning it was very difficult for me because I didn’t know where to start.  But I’m finally understanding :D .

FYI I’m posting some resources that I think are  useful for all the people starting with RedDwarf.

1.  Project Snowman Hands On Lab.   This is a tutorial created by Sun,  specifically designed to teach how to use Project Darkstar.  I think following this tutorial  is one of the best things to do to learn RedDwarf.  By doing it  you can get a pretty good understanding of the basic principles of Darkstar/RedDwarf  and  how everything works.  I found it while searching at the RedWarf forums.

2.  Server Tutorial and Client Tutorial -  Original Version by Sun.  I had some problems when I started reading the tutorials published at RedDwarf’s site because the Server Tutorial referred to a script which I could not find within the downloaded files.  So again, searching in the forums I found this post and the original tutorials.  With those in hand I was able to happily finish what I was doing (that was only trying to run the server XP).

Now whit the help from the information above I can look at the RedDwarf documentation more confidently.  I’m  still learning and I hope to learn more and share with you here. XD.  Meanwhile check out RedDwarf documentation and the forums.  Good Luck!! ;) .

Read More
Page 1 of 212