gpt4 book ai didi

grails - 无法初始化代理-没有 session ,正在访问过滤器类中的 session 对象

转载 作者:行者123 更新时间:2023-12-02 14:03:27 25 4
gpt4 key购买 nike

我在groovy grails技术上有些新知识,对此有疑问

我看着这个could not initialize proxy - no Session,但是应用程序不会过时

我正在尝试访问位于配置子文件夹上的SecurityFilter上的 session 对象。我只是想检查 Controller 上的每个请求,以验证用户是否有权执行此类操作。

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

在执行此操作之前,我先将用户对象放在 session 对象上,然后再将其放置在 session 对象上,但是我不确定 session 对象变得不可用会发生什么情况

最佳答案

未检索到用户对象的某些属性,因此在登录中将用户对象放在 session 中时,我还必须手动传输所需的属性,以便再次检索以供以后使用

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

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

关于grails - 无法初始化代理-没有 session ,正在访问过滤器类中的 session 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11612134/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com