Search in sources :

Example 1 with EndpointPolicy

use of org.apache.cxf.ws.policy.EndpointPolicy in project cxf by apache.

the class PolicyAnnotationTest method testAnnotationImplNoInterface.

@org.junit.Test
public void testAnnotationImplNoInterface() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestImplNoInterface());
    factory.setStart(false);
    List<String> tp = Arrays.asList("http://schemas.xmlsoap.org/soap/http", "http://schemas.xmlsoap.org/wsdl/http/", "http://schemas.xmlsoap.org/wsdl/soap/http", "http://www.w3.org/2003/05/soap/bindings/HTTP/", "http://cxf.apache.org/transports/http/configuration", "http://cxf.apache.org/bindings/xformat");
    LocalTransportFactory f = new LocalTransportFactory();
    f.getUriPrefixes().add("http");
    f.setTransportIds(tp);
    Server s = factory.create();
    try {
        ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, s.getEndpoint().getService().getServiceInfos());
        Definition def = builder.build();
        WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter();
        def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
        Element wsdl = wsdlWriter.getDocument(def).getDocumentElement();
        Map<String, String> ns = new HashMap<>();
        ns.put("wsdl", WSDLConstants.NS_WSDL11);
        ns.put("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
        ns.put("wsp", Constants.URI_POLICY_13_NS);
        XPathUtils xpu = new XPathUtils(ns);
        // org.apache.cxf.helpers.XMLUtils.printDOM(wsdl);
        assertEquals(1, xpu.getValueList("/wsdl:definitions/wsdl:binding/" + "wsp:PolicyReference[@URI='#TestImplNoInterfaceServiceSoapBindingBindingPolicy']", wsdl).getLength());
        final EndpointPolicy policy = bus.getExtension(PolicyEngine.class).getServerEndpointPolicy(s.getEndpoint().getEndpointInfo(), null, null);
        assertNotNull(policy);
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) Server(org.apache.cxf.endpoint.Server) HashMap(java.util.HashMap) LocalTransportFactory(org.apache.cxf.transport.local.LocalTransportFactory) Element(org.w3c.dom.Element) Definition(javax.wsdl.Definition) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) WSDLWriter(javax.wsdl.xml.WSDLWriter) ServiceWSDLBuilder(org.apache.cxf.wsdl11.ServiceWSDLBuilder) EndpointPolicy(org.apache.cxf.ws.policy.EndpointPolicy) XPathUtils(org.apache.cxf.helpers.XPathUtils) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean)

Example 2 with EndpointPolicy

use of org.apache.cxf.ws.policy.EndpointPolicy in project cxf by apache.

the class RMEndpoint method setPolicies.

void setPolicies(Message message) {
    // use same WS-policies as for application endpoint
    PolicyEngine engine = manager.getBus().getExtension(PolicyEngine.class);
    if (null == engine || !engine.isEnabled()) {
        return;
    }
    for (Endpoint endpoint : endpoints.values()) {
        EndpointInfo ei = endpoint.getEndpointInfo();
        EndpointPolicy epi = null == conduit ? engine.getServerEndpointPolicy(applicationEndpoint.getEndpointInfo(), null, message) : engine.getClientEndpointPolicy(applicationEndpoint.getEndpointInfo(), conduit, message);
        if (conduit != null) {
            engine.setClientEndpointPolicy(ei, epi);
        } else {
            engine.setServerEndpointPolicy(ei, epi);
        }
        EffectivePolicyImpl effectiveOutbound = new EffectivePolicyImpl();
        effectiveOutbound.initialise(epi, engine, false, false, message);
        EffectivePolicyImpl effectiveInbound = new EffectivePolicyImpl();
        effectiveInbound.initialise(epi, engine, true, false, message);
        BindingInfo bi = ei.getBinding();
        Collection<BindingOperationInfo> bois = bi.getOperations();
        for (BindingOperationInfo boi : bois) {
            engine.setEffectiveServerRequestPolicy(ei, boi, effectiveInbound);
            engine.setEffectiveServerResponsePolicy(ei, boi, effectiveOutbound);
            engine.setEffectiveClientRequestPolicy(ei, boi, effectiveOutbound);
            engine.setEffectiveClientResponsePolicy(ei, boi, effectiveInbound);
        }
    }
// TODO: FaultPolicy (SequenceFault)
}
Also used : EndpointPolicy(org.apache.cxf.ws.policy.EndpointPolicy) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) EffectivePolicyImpl(org.apache.cxf.ws.policy.EffectivePolicyImpl)

Example 3 with EndpointPolicy

use of org.apache.cxf.ws.policy.EndpointPolicy in project cxf by apache.

the class NegotiationUtils method recalcEffectivePolicy.

static void recalcEffectivePolicy(SoapMessage message, String namespace, Policy policy, Invoker invoker, boolean secConv) {
    Exchange ex = message.getExchange();
    Bus bus = ex.getBus();
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    if (null == pe) {
        return;
    }
    Destination destination = ex.getDestination();
    try {
        Endpoint endpoint = message.getExchange().getEndpoint();
        TokenStore store = TokenStoreUtils.getTokenStore(message);
        if (secConv) {
            endpoint = STSUtils.createSCEndpoint(bus, namespace, endpoint.getEndpointInfo().getTransportId(), destination.getAddress().getAddress().getValue(), message.getVersion().getBindingId(), policy);
        } else {
            endpoint = STSUtils.createSTSEndpoint(bus, namespace, endpoint.getEndpointInfo().getTransportId(), destination.getAddress().getAddress().getValue(), message.getVersion().getBindingId(), policy, null);
        }
        endpoint.getEndpointInfo().setProperty(TokenStore.class.getName(), store);
        message.getExchange().put(TokenStore.class.getName(), store);
        EndpointPolicy ep = pe.getServerEndpointPolicy(endpoint.getEndpointInfo(), destination, message);
        List<Interceptor<? extends Message>> interceptors = ep.getInterceptors(message);
        message.getInterceptorChain().add(interceptors);
        Collection<Assertion> assertions = ep.getVocabulary(message);
        if (null != assertions) {
            message.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
        }
        endpoint.getService().setInvoker(invoker);
        ex.put(Endpoint.class, endpoint);
        ex.put(Service.class, endpoint.getService());
        ex.put(org.apache.cxf.binding.Binding.class, endpoint.getBinding());
        ex.remove(BindingOperationInfo.class);
        message.put(MAPAggregator.ACTION_VERIFIED, Boolean.TRUE);
    } catch (Exception exc) {
        throw new Fault(exc);
    }
}
Also used : Bus(org.apache.cxf.Bus) Destination(org.apache.cxf.transport.Destination) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) Fault(org.apache.cxf.interceptor.Fault) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) TokenStoreException(org.apache.cxf.ws.security.tokenstore.TokenStoreException) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap) Exchange(org.apache.cxf.message.Exchange) EndpointPolicy(org.apache.cxf.ws.policy.EndpointPolicy) Endpoint(org.apache.cxf.endpoint.Endpoint) TokenStore(org.apache.cxf.ws.security.tokenstore.TokenStore) Interceptor(org.apache.cxf.interceptor.Interceptor)

Example 4 with EndpointPolicy

use of org.apache.cxf.ws.policy.EndpointPolicy in project cxf by apache.

the class PolicyAnnotationTest method testAnnotations.

@org.junit.Test
public void testAnnotations() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestImpl());
    factory.setStart(false);
    List<String> tp = Arrays.asList("http://schemas.xmlsoap.org/soap/http", "http://schemas.xmlsoap.org/wsdl/http/", "http://schemas.xmlsoap.org/wsdl/soap/http", "http://www.w3.org/2003/05/soap/bindings/HTTP/", "http://cxf.apache.org/transports/http/configuration", "http://cxf.apache.org/bindings/xformat");
    LocalTransportFactory f = new LocalTransportFactory();
    f.getUriPrefixes().add("http");
    f.setTransportIds(tp);
    Server s = factory.create();
    try {
        ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, s.getEndpoint().getService().getServiceInfos());
        Definition def = builder.build();
        WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter();
        def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
        Element wsdl = wsdlWriter.getDocument(def).getDocumentElement();
        Map<String, String> ns = new HashMap<>();
        ns.put("wsdl", WSDLConstants.NS_WSDL11);
        ns.put("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
        ns.put("wsp", Constants.URI_POLICY_13_NS);
        XPathUtils xpu = new XPathUtils(ns);
        // org.apache.cxf.helpers.XMLUtils.printDOM(wsdl);
        check(xpu, wsdl, "/wsdl:definitions/wsdl:service/wsdl:port", "TestImplPortPortPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/", "TestInterfacePortTypePolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/", "echoIntPortTypeOpPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/wsdl:input", "echoIntPortTypeOpInputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/wsdl:output", "echoIntPortTypeOpOutputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/", "TestImplServiceSoapBindingBindingPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/", "echoIntBindingOpPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:input", "echoIntBindingOpInputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:output", "echoIntBindingOpOutputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:service/", "TestImplServiceServicePolicy");
        assertEquals(1, xpu.getValueList("/wsdl:definitions/wsdl:binding/wsdl:operation/" + "wsp:PolicyReference[@URI='#echoIntBindingOpPolicy']", wsdl).getLength());
        EndpointPolicy policy = bus.getExtension(PolicyEngine.class).getServerEndpointPolicy(s.getEndpoint().getEndpointInfo(), null, null);
        assertNotNull(policy);
        assertEquals(1, policy.getChosenAlternative().size());
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) Server(org.apache.cxf.endpoint.Server) HashMap(java.util.HashMap) LocalTransportFactory(org.apache.cxf.transport.local.LocalTransportFactory) Element(org.w3c.dom.Element) Definition(javax.wsdl.Definition) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) WSDLWriter(javax.wsdl.xml.WSDLWriter) ServiceWSDLBuilder(org.apache.cxf.wsdl11.ServiceWSDLBuilder) EndpointPolicy(org.apache.cxf.ws.policy.EndpointPolicy) XPathUtils(org.apache.cxf.helpers.XPathUtils) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean)

Example 5 with EndpointPolicy

use of org.apache.cxf.ws.policy.EndpointPolicy in project cxf by apache.

the class PolicyAnnotationTest method testAnnotationImplNoInterfacePolicies.

@org.junit.Test
public void testAnnotationImplNoInterfacePolicies() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestImplWithPoliciesNoInterface());
    factory.setStart(false);
    List<String> tp = Arrays.asList("http://schemas.xmlsoap.org/soap/http", "http://schemas.xmlsoap.org/wsdl/http/", "http://schemas.xmlsoap.org/wsdl/soap/http", "http://www.w3.org/2003/05/soap/bindings/HTTP/", "http://cxf.apache.org/transports/http/configuration", "http://cxf.apache.org/bindings/xformat");
    LocalTransportFactory f = new LocalTransportFactory();
    f.getUriPrefixes().add("http");
    f.setTransportIds(tp);
    Server s = factory.create();
    try {
        ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, s.getEndpoint().getService().getServiceInfos());
        Definition def = builder.build();
        WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter();
        def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
        Element wsdl = wsdlWriter.getDocument(def).getDocumentElement();
        Map<String, String> ns = new HashMap<>();
        ns.put("wsdl", WSDLConstants.NS_WSDL11);
        ns.put("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
        ns.put("wsp", Constants.URI_POLICY_13_NS);
        XPathUtils xpu = new XPathUtils(ns);
        // org.apache.cxf.helpers.XMLUtils.printDOM(wsdl);
        assertEquals(1, xpu.getValueList("/wsdl:definitions/wsdl:binding/" + "wsp:PolicyReference[@URI='#TestImplWithPoliciesNoInterfaceServiceSoapBindingBindingPolicy']", wsdl).getLength());
        final EndpointPolicy policy = bus.getExtension(PolicyEngine.class).getServerEndpointPolicy(s.getEndpoint().getEndpointInfo(), null, null);
        assertNotNull(policy);
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) Server(org.apache.cxf.endpoint.Server) HashMap(java.util.HashMap) LocalTransportFactory(org.apache.cxf.transport.local.LocalTransportFactory) Element(org.w3c.dom.Element) Definition(javax.wsdl.Definition) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) WSDLWriter(javax.wsdl.xml.WSDLWriter) ServiceWSDLBuilder(org.apache.cxf.wsdl11.ServiceWSDLBuilder) EndpointPolicy(org.apache.cxf.ws.policy.EndpointPolicy) XPathUtils(org.apache.cxf.helpers.XPathUtils) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean)

Aggregations

EndpointPolicy (org.apache.cxf.ws.policy.EndpointPolicy)6 PolicyEngine (org.apache.cxf.ws.policy.PolicyEngine)6 Bus (org.apache.cxf.Bus)4 HashMap (java.util.HashMap)3 Definition (javax.wsdl.Definition)3 WSDLWriter (javax.wsdl.xml.WSDLWriter)3 Server (org.apache.cxf.endpoint.Server)3 XPathUtils (org.apache.cxf.helpers.XPathUtils)3 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)3 LocalTransportFactory (org.apache.cxf.transport.local.LocalTransportFactory)3 ServiceWSDLBuilder (org.apache.cxf.wsdl11.ServiceWSDLBuilder)3 Element (org.w3c.dom.Element)3 Endpoint (org.apache.cxf.endpoint.Endpoint)2 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)2 Destination (org.apache.cxf.transport.Destination)2 Assertion (org.apache.neethi.Assertion)2 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)1 SoapBindingInfo (org.apache.cxf.binding.soap.model.SoapBindingInfo)1 Fault (org.apache.cxf.interceptor.Fault)1 Interceptor (org.apache.cxf.interceptor.Interceptor)1