【问题标题】:Wildfly request.getRemoteUser() returns null when accessed through nginx basic authenticationWildfly request.getRemoteUser() 通过nginx基本认证访问时返回null
【发布时间】:2021-11-17 08:51:57
【问题描述】:

我在 nginx 网络服务器后面有 Wildfly 24,充当具有基本身份验证的反向代理。当我使用 Insomnia 访问我的服务时,我可以发送一个 POST(并且有效),但问题是 request.getRemoteUser() 返回 NULL,而不是来自基本身份验证的经过身份验证的用户,我需要在我的应用程序中使用该值。

这是我的 nginx 配置

  location / {
    auth_basic "Application auth";
    auth_basic_user_file /etc/nginx/htpasswd;

    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_pass http://wildfly/;

    include snippets/services.conf;

    return 404;
  }

其中snippets/services.conf 仅出于遗留原因包含大量重写。

我已经尝试添加proxy_set_header Authorization $http_authorization;proxy_pass_header Authorization;,但到目前为止还没有产生任何结果。有什么我想念的想法吗?

【问题讨论】:

    标签: nginx http-post wildfly reverse-proxy basic-authentication


    【解决方案1】:

    可以将请求记录器添加到 Wildfly,从而将带有标头的请求直接记录到 server.log

    1. 使用 RequestDumpingHandler 为 Undertow 创建自定义过滤器
    2. 将此过滤器添加到默认服务器

    启动 CLI (bin/jboss-cli.sh -c) 并输入以下命令

    /subsystem=undertow/configuration=filter/custom-filter=request-logger:add(module=io.undertow.core, class-name=io.undertow.server.handlers.RequestDumpingHandler)
    /subsystem=undertow/server=default-server/host=default-host/filter-ref=request-logger:add()
    reload
    

    使用以下命令删除记录器:

    /subsystem=undertow/server=default-server/host=default-host/filter-ref=request-logger:remove
    /subsystem=undertow/configuration=filter/custom-filter=request-logger:remove
    reload
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-15
      • 2014-02-25
      • 2016-08-14
      • 1970-01-01
      • 2021-12-23
      • 1970-01-01
      • 1970-01-01
      • 2015-02-02
      相关资源
      最近更新 更多