我正在尝试在 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/