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(),"");
        }
    }


  • 相关阅读:
    如何提高使用Java反射的效率?
    程序猿必知必会Linux命令之awk
    Java日志正确使用姿势
    “==”、“equals()”、“hashcode()”之间的秘密
    Mybatis缓存
    Java高并发至Synchronized
    web.py
    python爬虫模块理解
    通用http状态码
    SpringMVC的理论
  • 原文地址:https://www.cnblogs.com/kisstear/p/5593821.html
Copyright © 2011-2022 走看看