39.7.3. 使用 Request-Reply 通信的基于 SSL/TCP 的 Netty consumer 端点
使用 JSSE 配置实用程序
Netty 组件通过 Camel JSSE 配置实用程序 支持 SSL/TLS 配置。这个工具可大大减少您需要编写的组件特定代码,并在端点和组件级别进行配置。以下示例演示了如何将 实用程序与 Netty 组件一起使用。
组件的编程配置
基于端点的 Spring DSL 配置
在 Jetty 组件中使用基本 SSL/TLS 配置
获取 SSLSession 和客户端证书的访问权限
如果需要获取客户端证书的详细信息,您可以获取 javax.net.ssl.SSLSession
的访问权限。当 ssl=true
后,Netty 组件会将 SSLSession
存储为 Camel 消息上的标头,如下所示:
SSLSession session = exchange.getIn().getHeader(NettyConstants.NETTY_SSL_SESSION, SSLSession.class); // get the first certificate which is client certificate javax.security.cert.X509Certificate cert = session.getPeerCertificateChain()[0]; Principal principal = cert.getSubjectDN();
SSLSession session = exchange.getIn().getHeader(NettyConstants.NETTY_SSL_SESSION, SSLSession.class);
// get the first certificate which is client certificate
javax.security.cert.X509Certificate cert = session.getPeerCertificateChain()[0];
Principal principal = cert.getSubjectDN();
请记住,设置 needClientAuth=true
以验证客户端,否则 SSLSession
无法访问客户端证书的信息,您可能会获得一个例外 javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
。如果客户端证书过期或无效等,您可能还会收到此例外。
选项 sslClientCertHeaders
可以设为 true
,然后使用带有带有客户端证书详细信息的标头来增强 Camel 消息。例如,主题名称在标题 CamelNettySSLClientCertSubjectName
中可用。