Search in sources :

Example 1 with PolicyContainingAssertion

use of org.apache.neethi.PolicyContainingAssertion 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 2 with PolicyContainingAssertion

use of org.apache.neethi.PolicyContainingAssertion 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 3 with PolicyContainingAssertion

use of org.apache.neethi.PolicyContainingAssertion 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 4 with PolicyContainingAssertion

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

the class PolicyUtils method printPolicyComponent.

public static void printPolicyComponent(PolicyComponent pc, StringBuilder buf, int level) {
    indent(buf, level);
    buf.append("type: ");
    buf.append(typeToString(pc.getType()));
    if (Constants.TYPE_ASSERTION == pc.getType()) {
        buf.append(" ");
        buf.append(((Assertion) pc).getName());
        if (((Assertion) pc).isOptional()) {
            buf.append(" (optional)");
        }
        buf.append(" (");
        buf.append(pc);
        buf.append(")");
        nl(buf);
        if (pc instanceof PolicyContainingAssertion) {
            PolicyComponent nested = ((PolicyContainingAssertion) pc).getPolicy();
            level++;
            printPolicyComponent(nested, buf, level);
            level--;
        }
    } else {
        level++;
        List<PolicyComponent> children = CastUtils.cast(((PolicyOperator) pc).getPolicyComponents(), PolicyComponent.class);
        nl(buf);
        for (PolicyComponent child : children) {
            printPolicyComponent(child, buf, level);
        }
        level--;
    }
}
Also used : PolicyComponent(org.apache.neethi.PolicyComponent) Assertion(org.apache.neethi.Assertion) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion)

Example 5 with PolicyContainingAssertion

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

the class EndpointPolicyImpl method initializeInterceptors.

void initializeInterceptors(PolicyInterceptorProviderRegistry reg, Set<Interceptor<? extends Message>> out, Assertion a, boolean fault, Message msg) {
    QName qn = a.getName();
    List<Interceptor<? extends org.apache.cxf.message.Message>> i = fault ? reg.getInFaultInterceptorsForAssertion(qn) : reg.getInInterceptorsForAssertion(qn);
    out.addAll(i);
    if (a instanceof PolicyContainingAssertion) {
        Policy p = ((PolicyContainingAssertion) a).getPolicy();
        if (p != null) {
            for (Assertion a2 : getSupportedAlternatives(p, msg)) {
                initializeInterceptors(reg, out, a2, fault, msg);
            }
        }
    }
}
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)

Aggregations

Assertion (org.apache.neethi.Assertion)5 PolicyContainingAssertion (org.apache.neethi.PolicyContainingAssertion)5 Policy (org.apache.neethi.Policy)4 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 Interceptor (org.apache.cxf.interceptor.Interceptor)2 Message (org.apache.cxf.message.Message)2 Collection (java.util.Collection)1 List (java.util.List)1 PolicyComponent (org.apache.neethi.PolicyComponent)1