繁体   English   中英

如何保护Apache Camel REST API?

[英]How do I secure my Apache Camel REST API?

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

我正在使用Camel 3.0.0-M1。 对于REST API,我使用的是REST DSL和camel-jetty组件。 从SO和骆驼邮件列表上的其他问题我收集到,我只需要配置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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM