4
我的应用程序在身份验证过程中调用Web服务(如下面的代码所示)。Spring MVC 3.1如何在自定义身份验证提供程序(实现AuthenticationProvider)中访问HttpSession
在这个过程中,我如何在HttpSession中保存一些信息? 用户登录后,客户账号等信息将在应用程序的各个地方使用。 是否可以将HttpSession参数传递给MyServiceManager的静态登录方法?
public class MyAuthenticationManager implements AuthenticationProvider {
@Override
public boolean supports(Class<? extends Object> authentication) {
return authentication.equals(UsernamePasswordAuthenticationToken.class);
}
@Override
public Authentication authenticate(Authentication authentication) {
//MyServiceManager.login - makes a call to web service
if(MyServiceManager.login(authentication.getName(), authentication.getCredentials().toString(), XXX_HTTP_SESSION_XXX))
{
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority> ();
authorities.add(new GrantedAuthorityImpl("ROLE_USER"));
authorities.add(new GrantedAuthorityImpl("ROLE_SUPERVISOR"));
return new UsernamePasswordAuthenticationToken(authentication.getName(), authentication.getCredentials(),authorities);
}
else
{
return null;
}
}
}