【问题标题】:Apache CXF specify which operations to encrypt / signApache CXF 指定要加密/签名的操作
【发布时间】:2021-11-14 07:24:45
【问题描述】:

我正在使用 Apache CXF 来实现一个 SOAP 服务器。它必须符合一个标准。该标准规定必须对某些 SOAP 操作进行加密和签名。其他的未加密且未签名。

我正在使用拦截器方法(例如 WSS4JStaxInInterceptor / WSS4JStaxOutInterceptor)。

如何指定哪些操作不加密,响应加密,哪些不加密?

【问题讨论】:

  • 您为什么使用WSS4JStaxInInterceptor?你可以使用 WSS4JOutInterceptor 吗?
  • 另一条评论 - 请阅读并关注how to ask guide,这可能是一个相当复杂的话题。有关于 CXF Security 的神文档和一些 tutorials。有什么不清楚的地方?
  • 感谢 cmets。我必须使用 Stax,因为每个请求有数百 MB,而且内存使用量太大而无法处理。我做了一些研究,但找不到我的问题的答案。真正的问题是如何处理某些 SOAP 操作受 WS-Security(加密和签名)保护而有些不受保护(普通)的情况。如果你有一个基于 DOM 的拦截器的 anwser 可能也会有所帮助,也许我可以调整它。
  • The standard specfies that some SOAP operations must be encrypted and signed. Others are unencrypted and not signed 这不是任何标准,这是一个没有任何合理化的任意要求。

标签: java cxf


【解决方案1】:

如何指定哪些操作不加密,响应加密,哪些不加密?

为整个端点或客户端分配 WSSJ 拦截器。因此,如果您有一些操作需要安全功能而另一些不需要,您最好将它们拆分为单独的服务/端点。

我必须使用 Stax,因为每个请求有数百 MB,而且内存使用量太大而无法处理

我个人尽量不鼓励将纯肥皂用于非常大的有效载荷,您仍然可以使用attachments along the WSSJ

通过确保签名和加密传递大型内容的另一种选择是使用 MFT(托管文件传输)形式,例如。 G。使用 OFTP2 协议。虽然这个选项增加了一些复杂性。

如果您有基于 DOM 的拦截器的 anwser 可能也会有所帮助,也许我可以调整它。

只需阅读并关注documentation 并在不清楚时创建一个新的具体问题

这是我的项目中签署请求并期待签署响应的示例


    <cxf:cxfEndpoint id="sixxClientService" 
                     address="${cxf.outbound.sixx.address}" 
                     serviceClass="sixx.clientservice.ClientServicePortType" 
                     bindingId="http://schemas.xmlsoap.org/wsdl/soap12/"> 
        <cxf:features>
        </cxf:features>
        <cxf:inInterceptors>
            <bean class="org.apache.cxf.transport.common.gzip.GZIPInInterceptor" />
            <ref bean="loggingInInterceptor"/> 
            <ref bean="WSSecuritySixxResponseInterceptor"/>
        </cxf:inInterceptors>
        <cxf:outInterceptors>
            <ref bean="WSSecuritySixxRequestInterceptor"/>
            <ref bean="loggingOutInterceptor"/>
        </cxf:outInterceptors>
    </cxf:cxfEndpoint>

    <bean id="WSSecuritySixxRequestInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
        <constructor-arg>
            <map>
                <entry key="action" value="Timestamp Signature"/>
                <entry key="user" value="sixxkey"/>             <!-- server key alias -->
                <entry key="timeToLive" value="60"/>
                <entry key="signaturePropFile" value="sixxKeystore.properties"/>
                <entry key="signatureKeyIdentifier" value="DirectReference"/>
                <entry key="passwordCallbackClass" value="clients.routes.wssecurity.KeystorePasswordCallback"/>
                <entry key="signatureParts"
                       value="{Element}{http://www.w3.org/2003/05/soap-envelope}Body;{Element}{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Timestamp"/>
                <entry key="signatureDigestAlgorithm" value="http://www.w3.org/2001/04/xmlenc#sha256"/>
                <entry key="signatureAlgorithm" value="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
            </map>
        </constructor-arg>
    </bean>
    
    <bean id="WSSecuritySixxResponseInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
        <constructor-arg>
            <map>
                <entry key="action" value="Timestamp Signature"/>
                <entry key="user" value="sixxkey"/>             <!-- server key alias -->
                <entry key="timeToLive" value="60"/>
                <entry key="signaturePropFile" value="sixxKeystore.properties"/>
                <entry key="signatureKeyIdentifier" value="DirectReference"/>
                <entry key="passwordCallbackClass" value="clients.routes.wssecurity.KeystorePasswordCallback"/>
                <entry key="signatureDigestAlgorithm" value="http://www.w3.org/2001/04/xmlenc#sha256"/>
                <entry key="signatureAlgorithm" value="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
            </map>
        </constructor-arg>
    </bean>

sixxKeystore.properties:

org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.file=sixxKeystore.jks
org.apache.ws.security.crypto.merlin.keystore.password=sixxpass
org.apache.ws.security.crypto.merlin.keystore.type=jks


编辑:

如何指定哪些操作不加密,响应加密,哪些不加密?

只是一个想法 - 您仍然可以使用反向代理或 http-route 根据 SOAPAction 或其他标头将请求转发到不同的端点。

【讨论】:

  • 这是很好的建议。不幸的是,我无法更改它,因为它是给定的标准,并且无法将其拆分为两个端点。
  • @beat 那么你需要重新考虑这个要求。我的意思是 - 在识别有效负载是哪个操作之前验证签名并解密有效负载。拦截器配置在整个端点之上。只是一个想法 - 您仍然可以使用反向代理或 http-route 根据 SOAPAction 或其他标头将请求转发到不同的端点
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-24
  • 1970-01-01
  • 1970-01-01
  • 2019-09-10
相关资源
最近更新 更多