Search in sources :

Example 11 with Assertion

use of org.apache.neethi.Assertion in project cxf by apache.

the class AssertionInfoMap method putAssertionInfo.

private void putAssertionInfo(Assertion a) {
    if (a instanceof PolicyContainingAssertion) {
        Policy p = ((PolicyContainingAssertion) a).getPolicy();
        if (p != null) {
            List<Assertion> pcs = new ArrayList<>();
            getAssertions(p, pcs);
            for (Assertion na : pcs) {
                putAssertionInfo(na);
            }
        }
    }
    AssertionInfo ai = new AssertionInfo(a);
    Collection<AssertionInfo> ail = get(a.getName());
    if (ail == null) {
        ail = new ArrayList<>();
        put(a.getName(), ail);
    }
    for (AssertionInfo ai2 : ail) {
        if (ai2.getAssertion() == a) {
            return;
        }
    }
    ail.add(ai);
}
Also used : Policy(org.apache.neethi.Policy) Assertion(org.apache.neethi.Assertion) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion) ArrayList(java.util.ArrayList) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion)

Example 12 with Assertion

use of org.apache.neethi.Assertion in project cxf by apache.

the class AssertionInfoMap method supportsAlternative.

public boolean supportsAlternative(PolicyComponent assertion, List<QName> errors) {
    boolean pass = true;
    if (assertion instanceof PolicyAssertion) {
        PolicyAssertion a = (PolicyAssertion) assertion;
        if (!a.isAsserted(this) && !a.isOptional()) {
            errors.add(a.getName());
            pass = false;
        }
    } else if (assertion instanceof Assertion) {
        Assertion ass = (Assertion) assertion;
        Collection<AssertionInfo> ail = getAssertionInfo(ass.getName());
        boolean found = false;
        for (AssertionInfo ai : ail) {
            if (ai.getAssertion().equal(ass) || ai.getAssertion().equals(ass)) {
                found = true;
                if (!ai.isAsserted() && !ass.isOptional()) {
                    errors.add(ass.getName());
                    pass = false;
                }
            }
        }
        if (!found) {
            errors.add(ass.getName());
            return false;
        }
    }
    if (assertion instanceof PolicyContainingAssertion) {
        Policy p = ((PolicyContainingAssertion) assertion).getPolicy();
        if (p != null) {
            Iterator<List<Assertion>> alternatives = p.getAlternatives();
            while (alternatives.hasNext()) {
                List<Assertion> pc = alternatives.next();
                for (Assertion p2 : pc) {
                    pass &= supportsAlternative(p2, errors);
                }
            }
        }
    }
    return pass;
}
Also used : Policy(org.apache.neethi.Policy) Assertion(org.apache.neethi.Assertion) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion)

Example 13 with Assertion

use of org.apache.neethi.Assertion in project cxf by apache.

the class EffectivePolicyImpl method initialiseInterceptors.

void initialiseInterceptors(PolicyInterceptorProviderRegistry reg, PolicyEngine engine, Set<Interceptor<? extends org.apache.cxf.message.Message>> out, Assertion a, boolean useIn, boolean fault, Message m) {
    QName qn = a.getName();
    List<Interceptor<? extends org.apache.cxf.message.Message>> i = null;
    if (useIn && !fault) {
        i = reg.getInInterceptorsForAssertion(qn);
    } else if (!useIn && !fault) {
        i = reg.getOutInterceptorsForAssertion(qn);
    } else if (useIn && fault) {
        i = reg.getInFaultInterceptorsForAssertion(qn);
    } else if (!useIn && fault) {
        i = reg.getOutFaultInterceptorsForAssertion(qn);
    }
    out.addAll(i);
    if (a instanceof PolicyContainingAssertion) {
        Policy p = ((PolicyContainingAssertion) a).getPolicy();
        if (p != null) {
            for (Assertion a2 : getSupportedAlternatives(engine, p, m)) {
                initialiseInterceptors(reg, engine, out, a2, useIn, fault, m);
            }
        }
    }
}
Also used : Policy(org.apache.neethi.Policy) Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) Assertion(org.apache.neethi.Assertion) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion) Interceptor(org.apache.cxf.interceptor.Interceptor) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion)

Example 14 with Assertion

use of org.apache.neethi.Assertion in project cxf by apache.

the class EffectivePolicyImpl method initialiseInterceptors.

void initialiseInterceptors(PolicyEngine engine, boolean useIn, boolean fault, Message m) {
    if (((PolicyEngineImpl) engine).getBus() != null) {
        PolicyInterceptorProviderRegistry reg = ((PolicyEngineImpl) engine).getBus().getExtension(PolicyInterceptorProviderRegistry.class);
        Set<Interceptor<? extends org.apache.cxf.message.Message>> out = new LinkedHashSet<>();
        for (Assertion a : getChosenAlternative()) {
            initialiseInterceptors(reg, engine, out, a, useIn, fault, m);
        }
        setInterceptors(new ArrayList<Interceptor<? extends org.apache.cxf.message.Message>>(out));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Message(org.apache.cxf.message.Message) Assertion(org.apache.neethi.Assertion) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion) Interceptor(org.apache.cxf.interceptor.Interceptor)

Example 15 with Assertion

use of org.apache.neethi.Assertion in project cxf by apache.

the class EndpointPolicyImpl method initializeInterceptors.

synchronized void initializeInterceptors(Message m) {
    if (interceptors != null) {
        return;
    }
    if (engine == null || engine.getBus() == null || engine.getBus().getExtension(PolicyInterceptorProviderRegistry.class) == null) {
        return;
    }
    PolicyInterceptorProviderRegistry reg = engine.getBus().getExtension(PolicyInterceptorProviderRegistry.class);
    Set<Interceptor<? extends Message>> out = new LinkedHashSet<>();
    if (getChosenAlternative() != null) {
        for (Assertion a : getChosenAlternative()) {
            initializeInterceptors(reg, out, a, false, m);
        }
    }
    final List<Interceptor<? extends Message>> tmp;
    if (requestor) {
        tmp = new ArrayList<>(out);
        out.clear();
        for (Assertion a : getChosenAlternative()) {
            initializeInterceptors(reg, out, a, true, m);
        }
        faultInterceptors = new ArrayList<>(out);
    } else if (ei != null && ei.getBinding() != null) {
        for (BindingOperationInfo boi : ei.getBinding().getOperations()) {
            EffectivePolicy p = engine.getEffectiveServerRequestPolicy(ei, boi, m);
            if (p == null || p.getPolicy() == null || p.getPolicy().isEmpty()) {
                continue;
            }
            Collection<Assertion> c = engine.getAssertions(p, true);
            if (c != null) {
                for (Assertion a : c) {
                    initializeInterceptors(reg, out, a, false, m);
                    initializeInterceptors(reg, out, a, true, m);
                }
            }
        }
        tmp = new ArrayList<>(out);
    } else {
        tmp = new ArrayList<>(out);
    }
    interceptors = tmp;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.message.Message) Assertion(org.apache.neethi.Assertion) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Interceptor(org.apache.cxf.interceptor.Interceptor)

Aggregations

Assertion (org.apache.neethi.Assertion)64 Policy (org.apache.neethi.Policy)27 Message (org.apache.cxf.message.Message)25 Test (org.junit.Test)25 ArrayList (java.util.ArrayList)23 QName (javax.xml.namespace.QName)21 Interceptor (org.apache.cxf.interceptor.Interceptor)19 PrimitiveAssertion (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion)19 PolicyContainingAssertion (org.apache.neethi.PolicyContainingAssertion)9 Element (org.w3c.dom.Element)9 MessageImpl (org.apache.cxf.message.MessageImpl)7 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)7 All (org.apache.neethi.All)7 ExactlyOne (org.apache.neethi.ExactlyOne)7 Bus (org.apache.cxf.Bus)6 InterceptorChain (org.apache.cxf.interceptor.InterceptorChain)6 PolicyEngine (org.apache.cxf.ws.policy.PolicyEngine)6 PolicyContainingPrimitiveAssertion (org.apache.neethi.builders.PolicyContainingPrimitiveAssertion)6 XMLPrimitiveAssertionBuilder (org.apache.neethi.builders.xml.XMLPrimitiveAssertionBuilder)6 List (java.util.List)5