我正在使用Acegi / Spring Security插件在Grails中编写Web应用程序,并且无法使其看到对User实例所做的更改。 我一直在使用Groovy / Grails约三周,所以请原谅我,如果这个问题是微不足道的,因为我一直在阅读邮件列表和教程试图找到答案。
每当我需要用户包含更多信息(例如电子邮件确认标记或真实姓名)时,我一直向用户域类添加新属性,因为我找不到任何相反的建议。 一切似乎都适合创建新用户,但是当我编辑用户时,更改显示在用户列表中,但Acegi标记库和关联的函数似乎看不到更改。
以下是UserController.update()的相关代码片段:
def person = User.get(params.id) //...snip error checking... //Update user attributes person.username = params.email person.email = params.email person.userRealName = params.userRealName //Attempt to save changes if (person.save()) { //If successful, redirect back to profile viewing page redirect action: show, id: person.id return } else { //Otherwise, show errors and edit again render view: 'edit', model: buildPersonModel(person) return }运行此代码后,如果我总是通过ID获取用户数据,我可以看到更改,但如果我使用Acegi标记或函数则不会。 例如,这不起作用:
loggedInUserInfo(field:'realName')但是这样做:
User.get(loggedInUserInfo(field:'id').toLong()).realName新的信息有时会在我退出后重新出现,但通常不会出现,即使在三次或更多次重新登录后也不会出现。 另外,我尝试将“flush:true”添加到person.save(),但没有效果。
(外设问题:这样对User类进行这样的操作对我来说不好吗?如果没有,那么向它添加信息的最佳方式是什么?)
更多调查后更新:它看起来像是在普通页面中使用loggedInUserInfo(),它工作正常,但如果我在布局中使用它,它会展现我描述的行为。 难道会有一些奇怪的缓存吗?
I am writing a web app in Grails with the Acegi/Spring Security plug-in, and am having trouble getting it to see changes I make to User instances. I have only been working with Groovy/Grails for about three weeks, so please forgive me if this problem is trivial, since I have been poring over mailing lists and tutorials trying to find the answer.
I have been adding new attributes to the User domain class whenever I need a User to contain more information such as an email confirmation token or real name, since I couldn't find any recommendations to the contrary. Everything seems to be fine for creating new users, but when I edit the user, the changes show up in the user list, but the Acegi tag libraries and associated functions don't seem to see the changes.
Here is the relevant snippet from UserController.update():
def person = User.get(params.id) //...snip error checking... //Update user attributes person.username = params.email person.email = params.email person.userRealName = params.userRealName //Attempt to save changes if (person.save()) { //If successful, redirect back to profile viewing page redirect action: show, id: person.id return } else { //Otherwise, show errors and edit again render view: 'edit', model: buildPersonModel(person) return }After this code runs, I can see the changes if I always get user data by ID, but not if I use the Acegi tags or functions. For example, this does not work:
loggedInUserInfo(field:'realName')But this does:
User.get(loggedInUserInfo(field:'id').toLong()).realNameThe new information sometimes shows up after I log out and in again, but usually it doesn't, often not showing up even after three or more relogs. Also, I tried adding "flush:true" to person.save() with no effect.
(Peripheral question: is it bad for me to be fiddling with the User class like this? If not, what's the best way to add information to it?)
Update after more investigation: It looks like if I use loggedInUserInfo() in a normal page, it works fine, but if I use it inside a layout, it exhibits the behavior I described. Could there be some odd caching thing going on?
最满意答案
我有一个解决这个问题的办法,我也为这个问题创建了一个JIRA条目。
Acegi如何在内部更新它的用户似乎存在一个错误。 我以grails过滤器的形式提供解决方法,每次访问控制器时都会手动更新用户的权限。 不理想,但它的工作原理。
干杯,
I have a workaround for this issue and i've also created a JIRA entry for the problem.
There seems to be a bug in how Acegi updates it's users internally. I provide a workaround in the form of a grails filter which updates the user's authorities manually every time a controller is accessed. Not ideal but it works.
Cheers,
更多推荐
发布评论