zoukankan      html  css  js  c++  java
  • SpringColud TokenFilter

    package com.example.apigeteway.filter;
    
    import com.netflix.zuul.ZuulFilter;
    import com.netflix.zuul.context.RequestContext;
    import org.springframework.stereotype.Component;
    
    import javax.servlet.http.HttpServletRequest;
    
    import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_DECORATION_FILTER_ORDER;
    import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_TYPE;
    
    /**
     * @Title: PreFilter PostFilter
     * @ProjectName api-geteway
     * @Desc 判断token
     * @date 2019/12/1616:34
     */
    @Component
    public class PreTokenFilter extends ZuulFilter {
        @Override
        public String filterType() {
            return PRE_TYPE;
        }
    
        @Override
        public int filterOrder() {
            return PRE_DECORATION_FILTER_ORDER - 1;
        }
    
        /**
         * false 不启用
         * @return
         */
        @Override
        public boolean shouldFilter() {
            return false;
        }
    
        @Override
        public Object run() {
            RequestContext requestContext = RequestContext.getCurrentContext();
            HttpServletRequest request = requestContext.getRequest();
            // 这里是从参数中,也可以从header中 或者 cookie中
            String token = request.getParameter("token");
           /* if (StringUtils.isEmpty(token)) {
                requestContext.setSendZuulResponse(false);
                requestContext.setResponseStatusCode(HttpStatus.UNAUTHORIZED.value());
            }*/
            return null;
        }
    }
    

      

  • 相关阅读:
    大型系统的支撑
    应用系统开发思想的变迁
    面向对象基本特征的来历
    GC使用注意
    系统分层演变
    Oracle位图索引
    剪刀剪纸
    权限设计随笔(有空细化)
    Hibernate基础学习(六)—Hibernate二级缓存
    Hibernate基础学习(五)—对象-关系映射(下)
  • 原文地址:https://www.cnblogs.com/412013cl/p/12053975.html
Copyright © 2011-2022 走看看