Search in sources :

Example 1 with PolicyEngine

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

the class MinimalMaximalAlternativeSelectorTest method testChooseMaxAlternative.

@Test
public void testChooseMaxAlternative() {
    Message m = new MessageImpl();
    AlternativeSelector selector = new MaximalAlternativeSelector();
    PolicyEngine engine = control.createMock(PolicyEngine.class);
    Assertor assertor = control.createMock(Assertor.class);
    Policy policy = new Policy();
    ExactlyOne ea = new ExactlyOne();
    All all = new All();
    PolicyAssertion a1 = new TestAssertion();
    all.addAssertion(a1);
    ea.addPolicyComponent(all);
    Collection<PolicyAssertion> maxAlternative = CastUtils.cast(all.getPolicyComponents(), PolicyAssertion.class);
    all = new All();
    ea.addPolicyComponent(all);
    Collection<PolicyAssertion> minAlternative = CastUtils.cast(all.getPolicyComponents(), PolicyAssertion.class);
    policy.addPolicyComponent(ea);
    EasyMock.expect(engine.supportsAlternative(maxAlternative, assertor, m)).andReturn(true);
    EasyMock.expect(engine.supportsAlternative(minAlternative, assertor, m)).andReturn(true);
    control.replay();
    Collection<Assertion> choice = selector.selectAlternative(policy, engine, assertor, null, m);
    assertEquals(1, choice.size());
    assertSame(a1, choice.iterator().next());
    control.verify();
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) PolicyAssertion(org.apache.cxf.ws.policy.PolicyAssertion) Message(org.apache.cxf.message.Message) Assertion(org.apache.neethi.Assertion) TestAssertion(org.apache.cxf.ws.policy.TestAssertion) PolicyAssertion(org.apache.cxf.ws.policy.PolicyAssertion) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) ExactlyOne(org.apache.neethi.ExactlyOne) AlternativeSelector(org.apache.cxf.ws.policy.AlternativeSelector) Assertor(org.apache.cxf.ws.policy.Assertor) TestAssertion(org.apache.cxf.ws.policy.TestAssertion) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 2 with PolicyEngine

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

the class PolicyBeansTest method testParse.

@Test
public void testParse() {
    Bus bus = new SpringBusFactory().createBus("org/apache/cxf/ws/policy/spring/beans.xml");
    try {
        PolicyEngine pe = bus.getExtension(PolicyEngine.class);
        assertTrue("Policy engine is not enabled", pe.isEnabled());
        assertTrue("Unknown assertions are not ignored", pe.isIgnoreUnknownAssertions());
        assertEquals(MaximalAlternativeSelector.class.getName(), pe.getAlternativeSelector().getClass().getName());
        PolicyEngineImpl pei = (PolicyEngineImpl) pe;
        Collection<PolicyProvider> providers = pei.getPolicyProviders();
        assertEquals(4, providers.size());
        int n = 0;
        for (PolicyProvider pp : providers) {
            if (pp instanceof ExternalAttachmentProvider) {
                n++;
            }
        }
        assertEquals("Unexpected number of external providers", 2, n);
    } finally {
        bus.shutdown(true);
    }
}
Also used : PolicyEngineImpl(org.apache.cxf.ws.policy.PolicyEngineImpl) Bus(org.apache.cxf.Bus) MaximalAlternativeSelector(org.apache.cxf.ws.policy.selector.MaximalAlternativeSelector) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) PolicyProvider(org.apache.cxf.ws.policy.PolicyProvider) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) ExternalAttachmentProvider(org.apache.cxf.ws.policy.attachment.external.ExternalAttachmentProvider) Test(org.junit.Test)

Example 3 with PolicyEngine

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

the class AbstractPolicyProvider method setBus.

public final void setBus(Bus b) {
    bus = b;
    if (null != bus) {
        setBuilder(bus.getExtension(PolicyBuilder.class));
        PolicyEngine pe = bus.getExtension(PolicyEngine.class);
        if (pe != null) {
            setRegistry(pe.getRegistry());
            ((PolicyEngineImpl) pe).addPolicyProvider(this);
        }
    }
}
Also used : PolicyEngineImpl(org.apache.cxf.ws.policy.PolicyEngineImpl) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) PolicyBuilder(org.apache.cxf.ws.policy.PolicyBuilder)

Example 4 with PolicyEngine

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

the class AbstractSTSClient method findOperation.

protected BindingOperationInfo findOperation(String suffix) {
    BindingInfo bi = client.getEndpoint().getBinding().getBindingInfo();
    for (BindingOperationInfo boi : bi.getOperations()) {
        SoapOperationInfo soi = boi.getExtensor(SoapOperationInfo.class);
        String soapAction = soi != null ? soi.getAction() : null;
        Object o = boi.getOperationInfo().getInput().getExtensionAttribute(new QName("http://www.w3.org/2007/05/addressing/metadata", "Action"));
        if (o instanceof QName) {
            o = ((QName) o).getLocalPart();
        }
        String wsamAction = o == null ? null : o.toString();
        if ((soapAction != null && soapAction.endsWith(suffix)) || (wsamAction != null && wsamAction.endsWith(suffix))) {
            PolicyEngine pe = bus.getExtension(PolicyEngine.class);
            Conduit conduit = client.getConduit();
            EffectivePolicy effectivePolicy = pe.getEffectiveClientRequestPolicy(client.getEndpoint().getEndpointInfo(), boi, conduit, PhaseInterceptorChain.getCurrentMessage());
            setPolicyInternal(effectivePolicy.getPolicy());
            return boi;
        }
    }
    // we can at least find it by name and then set the action and such manually later.
    for (BindingOperationInfo boi : bi.getOperations()) {
        if (suffix.endsWith(boi.getName().getLocalPart())) {
            return boi;
        }
    }
    // Still didn't find anything useful
    for (BindingOperationInfo boi : bi.getOperations()) {
        if (boi.getInput().getMessageInfo().getMessagePartsNumber() > 0) {
            MessagePartInfo mpi = boi.getInput().getMessageInfo().getFirstMessagePart();
            if ("RequestSecurityToken".equals(mpi.getConcreteName().getLocalPart())) {
                return boi;
            }
        }
    }
    return null;
}
Also used : EffectivePolicy(org.apache.cxf.ws.policy.EffectivePolicy) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) QName(javax.xml.namespace.QName) Conduit(org.apache.cxf.transport.Conduit) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 5 with PolicyEngine

use of org.apache.cxf.ws.policy.PolicyEngine 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)

Aggregations

PolicyEngine (org.apache.cxf.ws.policy.PolicyEngine)9 Message (org.apache.cxf.message.Message)4 Assertion (org.apache.neethi.Assertion)4 Test (org.junit.Test)4 MessageImpl (org.apache.cxf.message.MessageImpl)3 BindingInfo (org.apache.cxf.service.model.BindingInfo)3 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)3 AlternativeSelector (org.apache.cxf.ws.policy.AlternativeSelector)3 Assertor (org.apache.cxf.ws.policy.Assertor)3 PolicyAssertion (org.apache.cxf.ws.policy.PolicyAssertion)3 TestAssertion (org.apache.cxf.ws.policy.TestAssertion)3 All (org.apache.neethi.All)3 ExactlyOne (org.apache.neethi.ExactlyOne)3 Policy (org.apache.neethi.Policy)3 Bus (org.apache.cxf.Bus)2 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)2 Conduit (org.apache.cxf.transport.Conduit)2 EffectivePolicy (org.apache.cxf.ws.policy.EffectivePolicy)2