Grails Spring Security(获取当前用户) [英] Grails Spring Security (get current user)

查看:212
本文介绍了Grails Spring Security(获取当前用户)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有这种情况:

  def user = User.get(springSecurityService.principal.id)



  def user = springSecurityService.currentUser 

我所能想到的是防止懒惰或确保数据目前运行的是不是陈旧?

解决方案

实际上,我没有看到这两者之间有太大的区别。我会倾向于使用

  def user = springSecurityService.currentUser 

因为它比其他表单稍短,这就是插件文档推荐的内容,并且可能是插件中用户的一些额外缓存(超出了Hibernate提供的缓存)。

更新



方法 SpringSecurityService .getCurrentUser() 现已被弃用和根据javadoc评论


将在未来的发行版中被删除而不会被替换,但是有关如何添加在应用程序中的功能


个人而言,我认为在不提供使用方法的指导的情况下标记不使用的方法是不合理的d替换为,因此,直到上述文档可用,我会倾向于继续使用它。


Is there ever a case for:

def user = User.get(springSecurityService.principal.id)

over

def user = springSecurityService.currentUser

All I can think of is preventing lazy inits or ensuring data you are currently operating on is not stale?

解决方案

In practical terms, I don't see much difference between these two. I would be inclined to use

def user = springSecurityService.currentUser

Because it's slightly shorter that the other form, it's what the plugin docs recommend, and there might be some additional caching of the user within plugin (beyond the caching already provided by Hibernate).

Update

The method SpringSecurityService.getCurrentUser() is now deprecated and according to the javadoc comment

will be removed in a future release without replacement, but with documentation on how to add this functionality in the application

Personally, I think it's unreasonable to mark a method deprecated without providing guidance about what it's usages should be replaced with, so until the aforementioned documentation is available, I would be inclined to continue using it.

这篇关于Grails Spring Security(获取当前用户)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆