Spring Security ACL域错误:类型xxx已经定义 [英] Spring Security ACL Domains Error: The type xxx is already defined
问题描述
我正在使用Eclipse,Grails 2.4.5和
错误日志显示:
在我的 BuildConfig.groovy
我有: / p>
编译:spring-security-core:2.0-RC5
运行时:spring-security-acl:2.0 -RC2'
有没有办法解决这个Eclipse不会显示错误?除了这个错误,代码运行正常。
编辑:以下是由 grails s2-create-acl生成的类-domains
。我没有改变任何东西,除了 AclObjectIdentity
objectId类型从长到字符串。
生成:
AclClass
:
package grails.plugin.springsecurity.acl
class AclClass {
String className
@Override
String toString(){
AclClass id $ id,className $ className
}
static mapping = {
className列:'class'
版本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列:'object_id_class'
所有者列:'owner_sid'
父列:'parent_object'
objectId列:'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:f alse,size:1..255
}
}
AclEntry
:
package grails.plugin.springsecurity.acl
class AclEntry {
AclObjectIdentity aclObjectIdentity
int aceOrder
AclSid sid
int mask
boolean授予
boolean auditSuccess
boolean auditFailure
@Override
String toString(){
AclEntry id $ id,aceOrder $ aceOrder,mask $ mask,授予$ granting,+
aclObjectIdentity $ aclObjectIdentity
}
static mapping = {
version false
sid列:'sid'
aclObjectIdentity列:'acl_object_identity'
}
static constraints = {
aceOrder unique:'aclObjectIdentity'
}
}
编辑:我仍然没有解决方案这个问题!!!
Groovy有两种方式来处理.groovy文件:
- 脚本:在这种情况下,您不能使用与该文件相同名称的类。您可以识别脚本文件,如果文件中的语句(除了导入之外)中有任何代码,则将脚本
- 作为类定义文件:当然如在Java中,你将类的定义与你的文件相同。
脚本中发生了什么情况是,如果有任何代码要在文件中执行,那么Groovy需要一个包含该代码的类。 Groovy将隐式地创建一个包含文件名的包含类。
所以如果你有一个名为AclEntry.groovy的文件,其中有一些代码不在类定义中,Groovy将创建一个隐含的包含类AclEntry。这意味着脚本文件AclEntry.groovy本身不能包含一个名为AclEntry的类,因为这将是一个重复的类定义,因此是错误。
另一方面,如果AclEntry.groovy中的所有文件都被定义为AclEntry类(和任何其他类),那么Groovy将会对待文件作为简单的类定义的集合,将不会有隐含的包含类,并且在类定义文件AclEntry.groovy中有一个名为AclEntry的类没有问题。
您可能想检查您的groovy文件是否如此。
I am using Eclipse, Grails 2.4.5 and the Spring Security ACL plugin. I created the domain classes that manage ACL data with the command:
s2-create-acl-domains
After these domains have been generated Eclipse reports that the classes have already been defined.
The error log shows:
In my 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 does not show the errors? Beside that error the code is running fine.
Edit: Here are the classes which are generated by grails s2-create-acl-domains
. I did not change anything except in AclObjectIdentity
objectId type from Long to String.
Here are the classes which have been 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 have no SOLUTION for this problem!!!
Groovy has two ways to treat a .groovy file:
- as a script : In this case you can not have a class by the same name as the file. You can recognize script file, if there is any code outside a class statement in the file (other than imports), it is a script
- as a class definition file: of course as in Java you will have the class definition as the same name as your file.
What is happening in the script case is that if there is any code to be executed in the file then Groovy needs a containing class for that code. Groovy will implicitly create a containing class with the name of the file.
So if you have a file called AclEntry.groovy that has some code in it that isn't inside a class definition, Groovy will create an implicit containing class called AclEntry. This means that the script file AclEntry.groovy can not itself contain a class called AclEntry because that would be a duplicate class definition, thus the error.
If, on the other hand, all you do in the file AclEntry.groovy is define the class AclEntry (and any number of other classes), then Groovy will treat that file as simply a collection of class definitions, there will be no implicit containing class, and there is no problem having a class called AclEntry inside the class definition file AclEntry.groovy.
you might want to check if this is the case in your groovy files.
这篇关于Spring Security ACL域错误:类型xxx已经定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!