论坛首页 Java企业应用论坛

怎样从HttpSession中得到acegi登录的用户名称和密码?

浏览 5127 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-05-21   最后修改:2009-03-03
用户信息

     默认的Acegi登录成功后会在Session中放下面两个内容:

     ACEGI_SECURITY_CONTEXT--------org.acegisecurity.context.SecurityContextImpl@fdd91091: Authentication: org.acegisecurity.providers.UsernamePasswordAuthenticationToken@fdd91091: Username: org.acegisecurity.userdetails.User@fdcb3700: Username: acegi; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: USER; Password: [PROTECTED]; Authenticated: true; Details: org.acegisecurity.ui.WebAuthenticationDetails@fffc7f0c: RemoteIpAddress: 127.0.0.1; SessionId: BBBC69F664334F9E4CD0797BC1209DDB; Granted Authorities: USER

 

ACEGI_SECURITY_LAST_USERNAME--------acegi


通过HttpSesssion可以得到acegi登录的用户的名字和密码
HttpSession session=request.getSession();
// 得到用户名称
String userName=session.getAttribute("ACEGI_SECURITY_LAST_USERNAME");
// 得到用户的密码
SecurityContextImpl securityContext=(SecurityContextImpl)session.getAttribute("ACEGI_SECURITY_CONTEXT");
Authentication authentication=securityContext.getAuthentication();
String password=authentication.getCredentials();
   发表时间:2008-05-21  
可以通过配置一个安全信息传播的Filter,然后使用request.getRemoteUser()得到用户信息——类似于标准的JAAS的做法。
0 请登录后投票
   发表时间:2008-07-08  
   用户信息不是一个实体类吗?
(UserInfo)org.acegisecurity.context.SecurityContextHolder
.getContext().getAuthentication().getPrincipal();
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics