我的Grails 3.3.8应用程序中SpringSecurityService中的MissingPropertyException

问题描述 投票:1回答:1

使用grails spring安全插件(3.2.3)我有一个应用程序,其中包含使用本指南创建的标准域类:

https://grails-plugins.github.io/grails-spring-security-core/3.2.x/index.html#tutorials

它具有本教程中指定的以下类:

Role.groovy,UserRole.groovy和User.groovy。

User.groovy还添加了以下代码:

static belongsTo = [store: Store]

我还添加了两个额外的域类:

Store.groovy:

package com.mycompany.myapp

class Store {

    String name

    static constraints = {
    }
}

BookShop.groovy:

package com.mycompany.myapp

class BookShop extends Store {

    Boolean isOpen

    static constraints = {
    }
}

我在Bootstrap.groovy中创建了一个用户:

def init = {

    def adminRole = new Role(authority: 'ROLE_ADMIN').save()

    def testBookShop = new BookShop(name: "BookShop", isOpen: true).save()

    def testUser = new User(username: 'me', password: 'password', store: testBookShop).save()

    UserRole.create testUser, adminRole

    UserRole.withSession {
        it.flush()
        it.clear()
    }

    assert User.count() == 1
    assert Role.count() == 1
    assert UserRole.count() == 1
}

我将我的spring安全服务注入我的SecureController.groovy并尝试呈现以下内容:

package com.mycompany.myapp

import grails.plugin.springsecurity.annotation.Secured

class SecureController {

    def springSecurityService

    @Secured('ROLE_ADMIN')
    def index() {
        def currentUser = springSecurityService.currentUser
        render 'Store: ' + currentUser.store.name + ' is open = ' + currentUser.store.isOpen
    }
}

我收到以下错误:

2018-09-10 20:34:26.068 ERROR --- [nio-8080-exec-2] 
o.g.web.errors.GrailsExceptionResolver   : MissingPropertyException 
occurred when processing request: [GET] /secure/index
No such property: isOpen for class: com.mycompany.myapp.BookShop

如果我专门打开商店,我可以让它工作:

render 'Store: ' + currentUser.store.name + ' is open = ' +
            GrailsHibernateUtil.unwrapIfProxy(currentUser.store).isOpen

只是想知道有没有更好的解决方案来排序这个,我正在更新一个大的应用程序从grails 2.5.5到3.3.8,这工作在2.5.5我需要使用该方法更改大量的代码以上所以希望快速解决,谢谢。

hibernate grails spring-security gorm
1个回答
0
投票

修复程序似乎是将GORM从6.1.9.RELEASE升级到6.1.10.RELEASE。在升级说明中没有看到任何暗示这是一个已知错误,所以无法评论GORM中的确切问题。

编辑:此处记录的问题 - https://github.com/grails/grails-data-mapping/issues/1072

© www.soinside.com 2019 - 2024. All rights reserved.