2007-08-02
Re: 学习Acegi-认证(authentication)
关键字: acegi,安全,web acegi
对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]
[code]
Object obj = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (obj instanceof UserDetails) { String username = ((UserDetails)obj).getUsername(); } else { String username = obj.toString(); }
[/code]
发表评论
- 浏览: 65038 次

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
Spring源代码解析(九): ...
当然是研究角色和资源方面的动态扩张!
-- by clz1314521 -
Spring源代码解析(九): ...
ls:你的意思是楼主写这些没用么?我很想知道你在研究Acegi的什么部分
-- by 差沙 -
Spring源代码解析(五): ...
public class ProxyFactoryBean extends Pr ...
-- by x15594 -
Spring源代码解析(九): ...
lz写的这些都是acegi最基本的东西,基本上稍微对acegi有点研究的人自己都 ...
-- by starsea -
Spring源代码解析(九): ...
目前的Acegi在某些部分还做的不够,不知道为什么没有用OR/M实现的代码,在处 ...
-- by timonzhang






评论排行榜