【问题标题】:could not initialize proxy - no Session, accessing the session object in the filters class无法初始化代理 - 没有会话,访问过滤器类中的会话对象
【发布时间】:2012-07-25 00:59:14
【问题描述】:

我对 groovy grails 技术有点陌生,但我遇到了这个问题

我查看了这个could not initialize proxy - no Session,但应用程序不会过时太久

我正在尝试访问位于 config 子文件夹中的 SecurityFilter 上的会话对象。我只是想检查控制器上的每个请求,以验证用户是否有权执行此类操作。

class SecurityFilters {
    def filters = {

    userFilterList(controller:"user", action:"list") {
        before = {
            if (!session.user.accountType.equals("Admin")) {
                redirect(uri: "/")
            }
        }
    }
    userFilterShow(controller:"user", action:"show") {
        before = {
            if (!session.user.accountType.equals("Admin")) {
                redirect(uri: "/")
            }
        }
    }
    userFilterEdit(controller:"user", action:"edit") {
        before = {
            if (!session.user.accountType.equals("Admin")) {
                redirect(uri: "/")
            }
        }
    }

    }
}

但我收到此错误

Message: could not initialize proxy - no Session
Line | Method
->>    6 | doCall    in SecurityFilters$_closure1_closure2_closure5
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    186 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|   1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    603 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    636 | run       in java.lang.Thread

在我到达这一点之前,我在执行登录说明后立即将用户对象放在会话对象上,但我不确定会话对象不可用发生了什么

【问题讨论】:

    标签: grails groovy


    【解决方案1】:

    用户对象的某些属性没有被检索到,所以在登录时,当我将用户对象放入会话中时,我还必须手动传输我需要的属性,以便我可以再次检索以供以后使用

    session.user = user //not enough
    session.user.accountType = user.accountType
    

    现在我能够从会话对象中检索用户对象并获取我想要获取的属性

    【讨论】:

      猜你喜欢
      • 2013-03-03
      • 1970-01-01
      • 1970-01-01
      • 2012-11-09
      • 2018-09-28
      相关资源
      最近更新 更多