Basic Authentication service called By Zuul

后端 未结 6 745
闹比i
闹比i 2021-01-14 23:33

I\'m Zuul as edge server. so all request pass by this edge server. I have a micro-service A. all web services of A are protected by Basic Authentication. How can we call the

6条回答
  •  醉梦人生
    2021-01-15 00:20

    This change is little tricky.

    @Override
    public int filterOrder() {
        return 1; // change the return value to more than 5 the above code will work.
    }
    

    try with the final code below:

    @Component
    public class PreFilter extends ZuulFilter {
        private static final Logger LOG = LoggerFactory.getLogger(PreFilter.class);
    
        @Override
        public String filterType() {
            return "pre";
        }
    
        @Override
        public int filterOrder() {
            return 10;
        }
    
        @Override
        public boolean shouldFilter() {
            return true;
        }
    
        @Override
        public Object run() {
            RequestContext ctx = RequestContext.getCurrentContext();
            HttpServletRequest request = ctx.getRequest();
            ctx.addZuulRequestHeader("Authorization", request.getHeader("Authorization"));
            return null;
        }
    }
    

提交回复
热议问题