小编Suy*_*rve的帖子

Spring MVC 3.1 如何在Custom Authentication Provider(实现了AuthenticationProvider)中访问HttpSession

我的应用程序在身份验证过程中调用 Web 服务(如下面的代码所示)。

在这个过程中如何在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;
        }

    }
 }
Run Code Online (Sandbox Code Playgroud)

authentication spring-mvc

6
推荐指数
1
解决办法
6823
查看次数

标签 统计

authentication ×1

spring-mvc ×1