【问题标题】:Forwarding Client Certifcate from Apache to Tomcat将客户端证书从 Apache 转发到 Tomcat
【发布时间】:2013-01-20 22:47:31
【问题描述】:

我正在尝试将 x509 客户端证书(我的浏览器上安装了一个测试证书)从 Apache Web 服务器 (SSL) 传递到 Tomcat 应用程序。我现在配置它的方式,应用程序的弹簧安全没有找到(因此没有转发)证书。

DEBUG: [http-8080-1]  org.springframework.security.web.authentication.preauth.x509.X509AuthenticationFilter - No client certificate found in request.

Apache服务器ssl.conf文件是这样配置的(不相关的部分我省略了):

LoadModule ssl_module modules/mod_ssl.so

Listen 443

AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl    .crl

NameVirtualHost *:443

<VirtualHost *:443>

    ...

    SSLVerifyClient require
    SSLVerifyDepth 2

    ...

    # initialize the SSL headers to a blank value to avoid http header forgeries
    RequestHeader set SSL_CLIENT_CERT ""
    RequestHeader set SSL_CLIENT_VERIFY ""

    # add whatever SSL_* variables needed to pass to web application
    RequestHeader set SSL_CLIENT_CERT "%{SSL_CLIENT_CERT}s"
    RequestHeader set SSL_CLIENT_VERIFY "%{SSL_CLIENT_VERIFY}s"

    RequestHeader add X-Forwarded-Scheme https

    ProxyPass /testcert http://127.0.0.1:8080/testcert
    ProxyPassReverse /testcert http://127.0.0.1:8080/testcert

</VirtualHost>

有没有办法在 Apache 中配置这个,整个证书被转发到 Tomcat 服务器?我知道我可以使用ajp,但我试图在没有这种方法的情况下完成它。

【问题讨论】:

  • 你是说你所拥有的东西不起作用 - 你在 tomcat 中看不到 SSL_CLIENT_CERT 标头吗?
  • @Luke 我看到了标题,根据documentationSSL_CLIENT_CERT 是“PEM 编码的客户端证书”,但它没有在 Tomcat 服务器上通过。 Spring security 说它没有收到证书。

标签: apache tomcat spring-security x509


【解决方案1】:

如果您将证书作为标头传递,tomcat 不会自动意识到它,因为连接只是 HTTP 而不是 HTTPS。您不必将证书作为请求属性获取,而是必须从标头中提取并自行解析。

您可以覆盖getPreAuthenticationCredentials method in X509AuthenticationFilter。有一些代码here 显示了如何解码证书。

Bean 配置

您删除了 &lt;x509 /&gt; 命名空间元素并将其替换为等效的 bean。参考手册中有一个附录,它解释了 XML 元素创建的 bean。您的配置应如下所示:

<http entry-point-ref="http403">
    <custom-filter position="PRE_AUTH_FILTER" ref="x509Filter" />
</http>

<bean id="http403" class="org.springframework.security.web.authentication.Http403ForbiddenEntryPoint" />

<bean id="x509Filter" class="YourExtendedX509AuthenticaitonFilter" />

【讨论】:

  • 这似乎可以完成工作。我已经重写了该方法,但是由于对 spring 的熟练程度不如您,我不确定在哪里注入包含该类的 bean 以及应该如何调用它。声明 bean 并让 spring security 识别它的存在就足够了吗?此外,我是否仍应在 &lt;http&gt; 部分保留 &lt;x509 ... /&gt; 声明,因为这是预授权?
  • 已更新以包含配置示例。
猜你喜欢
  • 2018-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-04
  • 2013-05-25
  • 2012-07-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多