2017-06-22 70 views
0

我正在使用Jboss EAP 7编写一个代码优先的Web服务,并且需要为用户名令牌验证实现WS-Security ...为此,我使用Apache CXF策略,我设法使一切工作在契约优先的角度,现在我需要使其作为代码优先的角度来工作的唯一方法是将策略包含到生成的wsdl中......为此,我使用@org .apache.cxf.annotations.Policy,但该策略的代码片段不会添加到Jboss生成的最终wsdl中。apache CXF @Policy不包括在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 /公司用户名令牌,则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部署,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

想通了这个问题...

首先:你需要把政策的xml文件到资源文件夹而不是WEB-INF。

二:你需要添加placement = Policy.Placement.BINDING到您的@Policy批注......

@Policy(uri = "company-username-token-policy.xml", placement = Policy.Placement.BINDING)