Spring Security domain ACL error: type xxx is already defined
I am using Eclipse, Grails 2.4.5 and Spring Security ACL plugin . I have created domain classes that manage ACL data using the command:
s2-create-acl-domains
After these domains are created, Eclipse reports that the classes are already defined.
The error log shows:
In mine BuildConfig.groovy
I have:
compile ":spring-security-core:2.0-RC5"
runtime ':spring-security-acl:2.0-RC2'
Is there a way to fix this that Eclipse is not showing errors? Apart from this error, the code works fine.
Edit: Here are the classes that are generated grails s2-create-acl-domains
. I haven't changed anything except in the AclObjectIdentity
objectId type from Long to String.
Here are the classes that were generated:
AclClass
:
package grails.plugin.springsecurity.acl
class AclClass {
String className
@Override
String toString() {
"AclClass id $id, className $className"
}
static mapping = {
className column: 'class'
version false
}
static constraints = {
className unique: true, blank: false
}
}
AclObjectIdentity
:
package grails.plugin.springsecurity.acl
class AclObjectIdentity extends AbstractAclObjectIdentity {
String objectId
@Override
String toString() {
"AclObjectIdentity id $id, aclClass $aclClass.className, " +
"objectId $objectId, entriesInheriting $entriesInheriting"
}
static mapping = {
version false
aclClass column: 'object_id_class'
owner column: 'owner_sid'
parent column: 'parent_object'
objectId column: 'object_id_identity'
}
static constraints = {
objectId unique: 'aclClass'
}
}
AclSid
:
package grails.plugin.springsecurity.acl
class AclSid {
String sid
boolean principal
@Override
String toString() {
"AclSid id $id, sid $sid, principal $principal"
}
static mapping = {
version false
}
static constraints = {
principal unique: 'sid'
sid blank: false, size: 1..255
}
}
AclEntry
:
package grails.plugin.springsecurity.acl
class AclEntry {
AclObjectIdentity aclObjectIdentity
int aceOrder
AclSid sid
int mask
boolean granting
boolean auditSuccess
boolean auditFailure
@Override
String toString() {
"AclEntry id $id, aceOrder $aceOrder, mask $mask, granting $granting, " +
"aclObjectIdentity $aclObjectIdentity"
}
static mapping = {
version false
sid column: 'sid'
aclObjectIdentity column: 'acl_object_identity'
}
static constraints = {
aceOrder unique: 'aclObjectIdentity'
}
}
Edit: I still don't have a SOLUTION for this problem !!!
source to share
Groovy has two ways to handle the .groovy file:
- as a script . In this case, you cannot have a class with the same name as the file. You can recognize a script file if there is any code in the file outside of the class statement (other than import), it is script
- as a class definition file : of course, just like in Java, you will have a class definition as the same name as your file.
What happens in the case of a script is that if there is any code in the file, then Groovy needs a class that contains that code. Groovy will implicitly create a class containing the filename.
So, if you have a file called AclEntry.groovy that has code that is not inside the class definition, Groovy will create an implicit class called AclEntry. This means that the script file AclEntry.groovy cannot contain a class called AclEntry, because it would be a duplicate class definition, thus an error.
If, on the other hand, everything you do in the AclEntry.groovy file defines the AclEntry class (and any number of other classes), then Groovy will treat that file as just a collection of class definitions, it won't contain an implicit containing class, and no problems with the AclEntry class inside the AclEntry.groovy class definition file.
you can check if it is valid in your Groovy files.
source to share
I am working so that you have installed the Grails Spring Security Core plugin and configured it correctly.
First, a little background. Java cannot have classes referenced by names of the same name. Eclipse through the groovy plugin complains that named classes are AclClass, AclEntry, AclObjectIndentity, AclSid
already defined. The frustration comes when you don't define these classes! One thing to remember with groovy, groovy implicitly defines classes based on script names. (See this quick post from Steve Claridge for more information.)
Since you mention that the code is working, I expect that as this user on the groovy mailing list, Eclipse clings to the link class no longer exists. The solution that worked with it was:
Moving the class into a separate groovy class file made the error move with the class; eclipse has now complained that the class in groovy classfile is already defined.
However, I solved the problem as follows:
Remove the class from the class file and save this file.
Save the script file (without class), then open it to copy the class definition again and save the file again.
- Eric Tiffany
Seems to reset the saved references that Eclipse has in memory.
EDIT
Here's another tutorial on using Spring security with grails. The script will create some samples for you to start filling out the application with. Try following these directions and see if the error occurs.
source to share
You may need to refresh the dependencies using the grails refresh-dependencies command .
source to share