【问题标题】:How to pass NTLM credentials to zuul request header如何将 NTLM 凭据传递给 zuul 请求标头
【发布时间】:2017-06-01 20:49:17
【问题描述】:

我有一个 Windows 服务“A”用于身份验证(不由我们管理),我有一个基于 Spring-boot 的 REST Api 服务“B”(由我们管理),它使用 Zuul 来路由流量。有一个外部服务“C”(不由我们管理)需要通过我们的 REST API 与 Windows 服务通信。由于“A”使用 NTLM 身份验证,我们需要从“C”传递请求正文并在“B”的标头中添加 ntlm 凭据,并使用 zuul 路由流量。

我的问题是,如何将 Java 中的 NTLM 凭据添加到 zuul 标头中的路由流量?

~贾丁

【问题讨论】:

    标签: java rest spring-boot ntlm netflix-zuul


    【解决方案1】:

    你需要自己写ZuulFilter

    类似

    import javax.servlet.http.HttpServletRequest;
    import com.netflix.zuul.context.RequestContext;
    import com.netflix.zuul.ZuulFilter;
    
    public class MyFilter extends ZuulFilter {
    
      @Override
      public String filterType() {
        return "pre";
      }
    
      @Override
      public int filterOrder() {
        return 1;
      }
    
      @Override
      public boolean shouldFilter() {
        return true;
      }
    
      @Override
      public Object run() {
        RequestContext ctx = RequestContext.getCurrentContext();
        HttpServletRequest request = ctx.getRequest();
    
        // now add your headers to the request
    
        return null;
      }
    
    }
    

    只需确保在您的应用中创建过滤器 bean 并将其自动注册:

    @EnableZuulProxy
    @SpringBootApplication
    public class GatewayApplication {
    
      public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class, args);
      }
    
      @Bean
      public MyFilter myFilter() {
        return new MyFilter();
      }
    
    }
    

    查看this guide 了解更多信息。

    【讨论】:

      【解决方案2】:

      Zuul 可以在 Spring Session 中正常工作。有很多关于此的博客。

      http://docs.spring.io/spring-session/docs/current/reference/html5/guides/boot.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-21
        • 2013-09-13
        • 2018-09-21
        • 2013-11-23
        • 2021-08-11
        • 2021-03-21
        • 1970-01-01
        • 2015-06-09
        相关资源
        最近更新 更多