`
jiwenke
  • 浏览: 397332 次
  • 性别: Icon_minigender_1
  • 来自: 南京
博客专栏
4ee69929-b8e1-3eb5-bbca-157d075d6192
Spring技术内幕——深...
浏览量:181828
D1c226f7-74e9-3ec4-a15b-18a45ccd88c5
随笔:Spring与云计算...
浏览量:25554
社区版块
存档分类
最新评论

Re: 学习Acegi-认证(authentication)

阅读更多
对acegi不是很熟悉但很感兴趣,请问如果通过了认证以后,相关的应用代码怎样获得当前主体的信息?比如登录的用户名什么的,因为有时候应用代码需要的到这些相关的信息来进行相关的处理。只看到说这些信息会存在ContextHolder里面,但具体怎么取出来使用呢?看了一下手册,是不是这样使用: Inside the SecurityContextHolder we store details of the principal currently interacting with the application. Acegi Security uses an Authentication object to represent this information. Whilst you won't normally need to create an Authentication object yourself, it is fairly common for users to query the Authentication object. You can use the following code block - from anywhere in your application - to do this:
[code]
Object obj = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (obj instanceof UserDetails) { String username = ((UserDetails)obj).getUsername(); } else { String username = obj.toString(); }
[/code]
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics