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;
}
}
}