如何在Spring-Security-Acl中创建acl



我刚刚开始使用Grails,在配置spring-security-acl插件时遇到了瓶颈。我一直遵循官方插件教程,但我无法得到过去的引导阶段时,试图运行我的应用程序(使用Position域类,而不是Report类。我的大多数问题都围绕着应用程序的ACL部分。

我无法解决的问题是Bootstrap.groovygrantPermissions()函数。根据教程的说明,by函数是这样开始的:

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
    }
}

看起来问题是无法在通用的acl对象上找到函数deleteAce;我可以通过在

中指定类型MutableAcl来解决这个问题。
MutableAcl acl = aclUtilService.readAcl(position)

所有属性都有一个隐式的nullable:false约束,但是您只设置了title属性。draft没有设置,所以验证失败,所有的Position s都是空的。

这个应该可以工作:

def position = new Position(title: "position$id", draft: false).save()

最新更新