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

用户信息

     默认的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();

你可能感兴趣的:(UI,Security,Acegi)