1

语境

我在 Grails 2.4.4 中有一个使用Spring Security Rest Plugin 1.5.4 for GrailsSpring Security Core 2.0.0的项目,我收到了这个警告

Warning |
The [getAssociatedToEntities] action in [security.UserController] accepts a parameter of type [java.util.List].  Interface types and abstract class types are not supported as command objects.  This parameter will be ignored.

       @Secured("hasAnyRole('READ__USER', 'READ__PROFILE')")
       ^

这是代码...

BuildConfig

//...
compile "org.grails.plugins:spring-security-core:2.0.0"
compile "org.grails.plugins:spring-security-rest:1.5.4"
//...

UserController (警告来自的代码!)

@Secured("hasAnyRole('READ__USER', 'READ__PROFILE')")
def getAssociatedToEntities(List<Long> e, SearchCommand cmd){
    //code omitted
}

问题:

我怎样才能摆脱那个警告?

提前致谢!

4

2 回答 2

2

java.util.List是一个不能用作命令对象的接口,试试这个:

创建一个包含列表的命令对象

import grails.validation.Validateable

@Validateable
class SearchListCommand extends SearchCommand {
  List values
}

并将列表的声明替换为getAssociatedToEntities操作中的命令对象

def getAssociatedToEntities(SearchListCommand listCommand) { 
     //code omitted...
}
于 2017-05-10T19:05:08.960 回答
0

将其包装在列表中:@Secured("hasAnyRole(['READ__USER', 'READ__PROFILE'])")

于 2017-05-10T19:00:04.007 回答