• 模仿spring authentication-provider 自己写登录人管理


        
    import org.springframework.security.Authentication;
    import org.springframework.security.context.SecurityContextHolder;
    import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
                
    //将code交给spring管理
    String openId="sssss";    
    //将传过来的openId封装成
    Authentication
    Authentication token = new UsernamePasswordAuthenticationToken(openId, ""); 
    //调用AuthenticationManager的实现类,验证后返回
    Authentication authenticate
    = new WechatAuthentication().authenticate(token);
    //将返回结果set到ContextHolder管理
    SecurityContextHolder.getContext().setAuthentication(authenticate);

    //获取方式 Authentication authentication
    = SecurityContextHolder.getContext().getAuthentication();



    import org.springframework.security.Authentication;
    import org.springframework.security.AuthenticationException;
    import org.springframework.security.AuthenticationManager;
    import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
    
    /**
     * AuthenticationManager实现类
     * @author yanglei
     * 2016-6-17
     */
    public class WechatAuthentication implements AuthenticationManager{
        
        @Override
        public Authentication authenticate(Authentication arg0)
                throws AuthenticationException {
            return new UsernamePasswordAuthenticationToken(arg0.getName(),"");
        }
    }


  • 相关阅读:
    一些术语
    Professional Frontend Engineering
    爱上阿森纳,爱上一种信仰
    ThinkPHP 和 UCenter接口的冲突
    这个城市
    来自Google的10条价值观
    如何将Gb2312转为unicode?
    未完成的代码(JS)
    微软也用PHP?!
    博客园对"公告"的Js进行了过滤
  • 原文地址:https://www.cnblogs.com/kisstear/p/5593821.html
Copyright © 2020-2023  润新知