0
votes

I require to add Spring Security core to Grails. I have added the spring core security plugin to a grails 2.3.8 app, using: BuildConfig.groovy plugins { ... compile ":spring-security-core:2.0-RC4" ...

then s2-quickstart sim GUser GRole

The file GUserGRole.groovy contains the following errors:

Groovy:unexpected token: validator @ line 82, column 9. Multiple markers at this line - Groovy:expecting EOF, found 'if' @ line 83, column 4. - Groovy:unexpected token: if @ line 83, column 4.

which corresponds to the following code:

static constraints = {
    GRole validator: { GRole r, GUserGRole ur ->
        if (ur.GUser == null) return
        boolean existing = false
        GUserGRole.withNewSession {
            existing = GUserGRole.exists(ur.GUser.id, r.id)
        }
        if (existing) {
            return 'userRole.exists'
        }
    }
}

How can this be resolved? How can I cleanly add Spring Security core to Grails??

3
This code doesn't make a whole lot of sense to me. What exactly are you trying to accomplish with this?rmlan
The code shown is created automatically when I run quickstart after installing the security plugin.Helen Reeves
Same issue with Grails 2.4.4 and spring-security-core:2.0-RC3/RC4 with IDEA 14.bel

3 Answers

1
votes

s2quick-start uses GrailsNameUtils.getPropertyNameRepresentation to generate the instance fields for your domain classes. Use a name that will generate a suitable field name otherwise the field name and the class name are the same.

 //This is fine - generates 'user'
 GrailsNameUtils.getPropertyNameRepresentation("User") 

 //This is fine - generates 'myUser'
 GrailsNameUtils.getPropertyNameRepresentation("MyUser")

 //Not fine. Generates 'GRole' which is same as your class name
 GrailsNameUtils.getPropertyNameRepresentation("GRole")
0
votes

One issue is the GRole validator. The thing before validator there should be the name of the property that is being constrained, not the type. If the property is called gRole then the code should be gRole validator. Is the property really called GRole? That might be problematic if it is.

0
votes

Please check the discussion here Groovy: Unexpected token ":"?

Since the code is auto generated you should manually correct the names of your class variables and change it as "GRole GRole" to "GRole gRole".