【问题标题】:Write operations are not allowed in read-only mode (FlushMode.MANUAL): with grails hibernate只读模式下不允许写操作(FlushMode.MANUAL):使用 grails hibernate
【发布时间】:2011-07-21 21:34:45
【问题描述】:

我已将 spring 安全插件与我的 grails 应用程序集成,该应用程序具有休眠作为 ORM 工具...

使用 spring 安全插件,我的应用程序一切正常,包括身份验证、授权...

但最近我遇到了一个案例,我遇到了一些问题:

登录为:管理员 管理员角色:ROLE_ADMIN ROLE_ADMIN 权限:ROLE_ADMIN 可以访问每个 url

作为管理员用户,当我尝试更新分配给 ROLE_ADMIN 的权限时,它会引发异常:

2011-03-24 10:20:14,035 [http-8080-2] ERROR errors.GrailsExceptionResolver  - Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
        at ConfigController$_closure45_closure59.doCall(ConfigController:1128)
        at ConfigController$_closure45.doCall(ConfigController:1123)
        at ConfigController$_closure45.doCall(ConfigController)
        at java.lang.Thread.run(Thread.java:619)

可能是因为我正在尝试更新登录用户本身的权限...

无论我在哪里使用休眠保存/更新/删除任何对象,在代码内部,我都证明了flush:false,例如:

user.save flush:false

所以我想知道有没有什么方法可以让登录用户更新也能反映他/她自己的权限..

提前谢谢..

【问题讨论】:

    标签: java hibernate grails spring-security


    【解决方案1】:

    更改用户角色权限后调用springSecurityService.reauthenticate。在链接页面的“重新验证”部分也是一个很好的代码 sn-ps 应该可以回答您的问题。

    【讨论】:

      猜你喜欢
      • 2011-12-01
      • 1970-01-01
      • 2016-12-12
      • 2011-10-12
      • 2015-03-14
      • 2014-04-26
      • 1970-01-01
      • 2014-10-03
      • 2018-01-20
      相关资源
      最近更新 更多