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

标签 hibernate grails spring-security grails-orm

使用 grails spring security plugin (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]

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

商店.groovy:
package com.mycompany.myapp

class Store {

    String name

    static constraints = {
    }
}

书店.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 安全服务注入(inject)我的 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 中有效,我需要使用该方法更改大量代码以上,希望快速修复,谢谢。

最佳答案

该修复似乎正在将 GORM 从 6.1.9.RELEASE 升级到 6.1.10.RELEASE。在升级说明中没有看到任何表明这是一个已知错误的内容,因此无法评论 GORM 中的确切问题。

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

关于hibernate - 我的 Grails 3.3.8 应用程序中 SpringSecurityService 中的 MissingPropertyException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52264523/

相关文章:

java - hibernate - 无法找到具有 ID 的实体

hibernate - 如何在 Java EE Spring JSF 应用程序中组织支持 bean 和实体类

grails - grails 3.1异常-org.grails.datastore.mapping.core.ConnectionNotFoundException

grails - 使用rest-client-builder插件发布自定义 header 值的问题

grails - GRAILS:groovy.lang.MissingPropertyException:没有此类属性。

spring-security - 用于生产的 Spring Security kerberos 扩展?

java - 使用 Spring-Security 登录并重定向到所需 URL 时出现问题

Spring Boot Data JPA - 修改更新查询 - 刷新持久性上下文

Javafx、Maven、Hibernate,无法在第 0 行和第 0 列处执行解码

java - 如何在需要引用过滤器bean的grails中注册spring bean