gpt4 book ai didi

java - 如何保护我的 Apache Camel REST API?

转载 作者:太空宇宙 更新时间:2023-11-03 14:26:39 24 4
gpt4 key购买 nike

我正在使用 Apache Camel 为另一个 camel 应用程序托管 REST API。我如何保护这个只能通过 HTTPS 访问的 REST API?

我正在使用 Camel 3.0.0-M1。对于 REST API,我使用 REST DSL 和 camel-jetty 组件。从关于 SO 和 camel 邮件列表的其他问题我收集到我只需要配置 jetty 组件以启用 SSL。

这是我想出的:

<bean id="securejetty" class="org.apache.camel.component.jetty9.JettyHttpComponent9">
<property name="sslContextParameters" ref="sslContextParameters" />
</bean>

<camel:sslContextParameters id="sslContextParameters">
<camel:keyManagers keyPassword="Linux01!">
<camel:keyStore resource="/etc/certs/KeyStore.jks" password="Linux01!"/>
</camel:keyManagers>
</camel:sslContextParameters>

<restConfiguration component="securejetty" contextPath="api/v0" port="9091" apiContextPath="api-doc" apiContextListing="false" enableCORS="true" host="0.0.0.0">
<dataFormatProperty key="prettyPrint" value="true"/>
<apiProperty key="base.path" value="/opcua"/>
<apiProperty key="api.version" value="0.0.1"/>
<apiProperty key="api.title" value="Blackbox REST API"/>
<apiProperty key="api.description" value="The REST API for the Blackbox Project"/>
<apiProperty key="api.contact.name" value="Blackbox"/>
<corsHeaders key="Access-Control-Allow-*" value="0.0.0.0"/>
<corsHeaders key="Access-Control-Max-Age" value="300"/>
</restConfiguration>

我预计我的 API 只能通过 https 访问。但实际上它继续通过 http 可用,而根本无法通过 https 访问。我已经部分弄清楚原因:“sslContextParameters”被完全忽略,所以 Camel 不知道 jetty 组件应该做 https。我通过为 keyStore 变量分配一个虚假路径来测试它。这甚至不会引发错误,即使它被声明为资源,这让我相信“sslContextParameters”被完全忽略了。我需要知道如何保护我的 camel-jetty REST API,使其符合我公司的安全标准。

最佳答案

有两个错误阻碍了我的成功:

  1. 我没有将方案指定为 http(归功于@Paizo)
  2. 配置“securejetty”错误,我需要专门配置“jetty”

这是更正后的配置:

<bean id="jetty" class="org.apache.camel.component.jetty9.JettyHttpComponent9">
<property name="sslContextParameters" ref="sslContextParameters" />
</bean>

<camel:sslContextParameters id="sslContextParameters">
<camel:keyManagers keyPassword="Linux01!">
<camel:keyStore resource="/etc/certs/KeyStore.jks" password="Linux01!"/>
</camel:keyManagers>
</camel:sslContextParameters>

<restConfiguration component="jetty" contextPath="api/v0" port="9091" apiContextPath="api-doc" apiContextListing="false" enableCORS="true" host="0.0.0.0">
<dataFormatProperty key="prettyPrint" value="true"/>
<apiProperty key="base.path" value="/opcua"/>
<apiProperty key="api.version" value="0.0.1"/>
<apiProperty key="api.title" value="Blackbox REST API"/>
<apiProperty key="api.description" value="The REST API for the Blackbox Project"/>
<apiProperty key="api.contact.name" value="Blackbox"/>
<corsHeaders key="Access-Control-Allow-*" value="0.0.0.0"/>
<corsHeaders key="Access-Control-Max-Age" value="300"/>
</restConfiguration>

关于java - 如何保护我的 Apache Camel REST API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56445956/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com