0

我刚刚开始使用 Grails,并且正在尝试配置 spring-security-acl 插件。我一直在关注官方插件教程,但在尝试运行我的应用程序时无法通过引导阶段(使用Position域类而不是Report类。我的大多数问题都围绕着应用程序的 ACL 部分。

我无法解决的问题grantPermissions()在于Bootstrap.groovy. 根据教程的说明,按功能开始是这样的:

private void grantPermissions() {
    def positions = []
    100.times {
        long id = it + 1
        def position = new Position(title: "position$id").save()
        positions << position
        aclService.createAcl(
                objectIdentityRetrievalStrategy.getObjectIdentity(position))
    }

IntelliJ 在aclService.createAcl“无法推断参数类型。此检查报告类型不兼容的分配”的行上警告我。事实上,如果我仍然尝试运行该应用程序,它会在该行崩溃并出现错误:

| Error 2013-03-09 09:35:24,207 [localhost-startStop-1] ERROR context.GrailsContextLoader  - Error initializing the application: Cannot get property 'id' on null object
Message: Cannot get property 'id' on null object
    Line | Method
->>   68 | doCall                           in BootStrap$_grantPermissions_closure4
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     63 | grantPermissions                 in BootStrap
|     29 | doCall . . . . . . . . . . . . . in BootStrap$_closure1
...

任何帮助将不胜感激!


附录

万一这很重要,我的Position域对象如下所示:

class Position {

    String title
    Boolean draft

    static constraints = {
    }
}

我不认为这个问题是相关的,但它是与教程的 ACL 相关的偏差,所以为了后代......我(我认为)我已经解决的第一个问题是在 PositionService.groovy 中,我在代码块上的 IntelliJ 中遇到错误:

def acl = aclUtilService.readAcl(position)

// Remove all permissions associated with this particular
// recipient (string equality to KISS)
acl.entries.eachWithIndex { entry, i ->
    if (entry.sid.equals(position) &&
            entry.permission.equals(permission)) {
        acl.deleteAce i
    }
}

看起来问题是无法deleteAce在通用acl对象上找到函数;我可以通过指定类型来解决这个MutableAcl问题

MutableAcl acl = aclUtilService.readAcl(position)
4

1 回答 1

2

所有属性都有一个隐式nullable:false约束,但您只是设置title属性。draft未设置,因此验证失败并且您的所有Positions 都为空。

这应该有效:

def position = new Position(title: "position$id", draft: false).save()
于 2013-03-09T15:58:36.077 回答