我正在使用 Jboss EAP 7 编写代码优先的 Web 服务,并且需要实现 WS-Security 以进行用户名令牌验证...为此,我使用的是 Apache CXF 策略,我设法让一切都以合同优先的角度工作现在我唯一需要让它作为代码优先的视角工作的是将策略包含在生成的 wsdl 中......为此,我使用的是 @org.apache.cxf.annotations.Policy 但代码策略的片段不会添加到 Jboss 最终生成的 wsdl 中。
这是我的代码:
...
@WebService(serviceName = "ExampleService", portName = "ExampleService",
endpointInterface = "com.company.webservice.ExampleService",
targetNamespace = "https://service.company.com/company-ws/ExampleService")
@EndpointConfig(configFile = "WEB-INF/jaxws-endpoint-config.xml",
configName = "Custom WS-Security Endpoint")
@Policy(uri = "WEB-INF/company-username-token-policy.xml")
public class ExampleServiceImpl implements ExampleService { ...
这是 WEB-INF/company-username-token-policy.xml
<?xml version="1.0" encoding="UTF-8" ?>
<wsp:Policy wsu:Id="UsernameTokenPolicy" xmlns:wsp="http://www.w3.org/ns/ws-policy"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsp:ExactlyOne>
<wsp:All>
<sp:SupportingTokens
xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702">
<wsp:Policy>
<sp:UsernameToken
sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
<wsp:Policy>
<sp:WssUsernameToken11 />
</wsp:Policy>
</sp:UsernameToken>
</wsp:Policy>
</sp:SupportingTokens>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
我的 jboss-deployment-structure.xml 已经有这些条目:
<module name="org.apache.ws.security" export="true" />
<module name="org.apache.cxf" export="true" />
<module name="org.apache.cxf.impl" export="true" />
我在这里想念什么?