zoukankan      html  css  js  c++  java
  • 模仿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(),"");
        }
    }


  • 相关阅读:
    初遇黑客
    第四周学习总结
    第三周学习总结
    关于base64编码的原理及如何在python中实现
    在python中如何将十进制小数转换成二进制
    《信息安全专业导论》第二周学习总结
    计算机科学概论速读问题
    刘谨铭的自我介绍
    师生关系
    20201318快速浏览教材提问
  • 原文地址:https://www.cnblogs.com/kisstear/p/5593821.html
Copyright © 2011-2022 走看看