我正在使用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" />
我在这里缺少什么?
答案 0 :(得分:1)
找出问题......
首先:您需要将策略xml文件放入资源文件夹而不是WEB-INF。
第二:您需要将placement = Policy.Placement.BINDING
添加到@Policy注释...
@Policy(uri = "company-username-token-policy.xml", placement = Policy.Placement.BINDING)
答案 1 :(得分:-1)
警告,在输出设置中,@ Policy在某些绑定中会被忽略,例如Placement.SERVICE起作用了,BINDING也起作用了。但是任何_INCOMING绑定都不会在运行时应用策略;导致服务使用请求,而无需处理/验证WS sec标头部分