x509certificate - 谁有在Spring Cloud Gateway/Spring WebFlux中实现x509相互认证的简单例子?

标签 x509certificate spring-webflux spring-cloud-gateway mutual-authentication

我正在尝试在 Spring Cloud Gateway 中实现相互身份验证(使用 x509 客户端证书进行身份验证),但在我的整个研究过程中,我一直无法弄清楚从哪里开始。

据我所知,身份验证不是通过 Spring Cloud Gateway 本身处理的,而应该通过 Spring WebFlux 完成——如果这是一个不正确的假设,请纠正我。我找到了通过 Spring Security 实现认证身份验证的示例,但我还没有找到任何使用 WebFlux 的示例。

任何人都可以提供一些提示甚至一些代码示例来帮助我走上正确的轨道吗?

最佳答案

可以在src/main/resources/application.yml中配置,例如

server:
  # for testing or development without SSL certs (HTTP) use an "appropriate"
  # non-secure port, e.g. 8080
  # for HTTPS use an "appropriate" secure port, e.g. 8443
  port: 8443
  ssl:
    # for HTTP set enabled to false, for HTTPS (with required client certs) set to true
    enabled: true
    # this is the spring cloud gateway _server_ cert
    key-store: /etc/pki/tls/private/server.p12
    key-store-password: servercertpassword
    key-store-type: PKCS12
    # this is the "bundle" of CA intermediate/root upon which the client cert has to
    # match
    trust-store: /etc/pki/ca-trust/extracted/java/cacerts
    # this `client-auth` option is where you *require* mutual-TLS, it can alternatively
    # be made optional
    client-auth: need
    trust-store-password: truststorepassword
    trust-store-type: JCEKS
management:
  # management port without SSL to allow monitoring/etc. without client certs
  # e.g. /actuator/health
  server:
    port: 8080
    ssl:
      enabled: false

如果您有一组客户端证书、一个服务器证书和信任库/CA 包,这是一个如何在 Spring Cloud Gateway 中配置它的示例。

X509 PreAuthenticatedAuthenticationToken 将在您的应用程序中可用,以通过双向 TLS 建立成功连接,其中包含客户端证书的主体/详细信息。

关于x509certificate - 谁有在Spring Cloud Gateway/Spring WebFlux中实现x509相互认证的简单例子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58030447/

相关文章:

java - 如何修复 : java method in Anonymous class derived from <class> clashes with java method

azure - X509Certificate2.Verify() 在控制台应用程序中返回 true,在 asp.net Web 应用程序中返回 false

spring - 使用 WebClient 将 Spring Webflux 应用程序中接收到的请求 header 传播到下游服务

java - Spring Cloud Gateway 未找到路由路径(404 错误)

spring-boot - Spring Security Oauth2 客户端是否自动处理来自 Spring 授权服务器的刷新 token ?

ssl-certificate - Windows : How to import when certificate and private key are in separate files?

c# - 无法验证 Windows Server 证书的服务总线

java - 如何使用 R2dbc 将 jsonb 从 Postgresql 提取到 Spring webflux

java - 如何让 Flux 的多个订阅者在不同的执行上下文/线程上运行

spring-boot - 在 spring cloud gateway 中将配置从 Ribbon 更改为 Spring Cloud Load Balancer