Reputation: 469
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??
Upvotes: 0
Views: 987
Reputation: 459
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".
Upvotes: 0
Reputation: 110
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")
Upvotes: 1
Reputation: 27255
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.
Upvotes: 0