我对 groovy grails 技术有点陌生,但我在这方面遇到了问题
我看了这个could not initialize proxy - no Session但应用程序不会过时太久
我正在尝试访问位于 config 子文件夹中的 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.user = user //not enough
session.user.accountType = user.accountType
现在我能够从 session 对象中检索用户对象并获取我想要获取的属性
关于grails - 无法初始化代理 - 无 session ,正在访问过滤器类中的 session 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11612134/