Search in sources :

Example 16 with Assertion

use of org.apache.neethi.Assertion 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();
            printPolicyComponent(nested, buf, level + 1);
        }
    } else {
        List<PolicyComponent> children = CastUtils.cast(((PolicyOperator) pc).getPolicyComponents(), PolicyComponent.class);
        nl(buf);
        for (PolicyComponent child : children) {
            printPolicyComponent(child, buf, level + 1);
        }
    }
}
Also used : PolicyComponent(org.apache.neethi.PolicyComponent) Assertion(org.apache.neethi.Assertion) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion)

Example 17 with Assertion

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

the class ServerPolicyOutFaultInterceptor method handle.

protected void handle(Message msg) {
    if (MessageUtils.isRequestor(msg)) {
        LOG.fine("Is a requestor.");
        return;
    }
    Exchange exchange = msg.getExchange();
    assert null != exchange;
    BindingOperationInfo boi = exchange.getBindingOperationInfo();
    if (null == boi) {
        LOG.fine("No binding operation info.");
        return;
    }
    Endpoint e = exchange.getEndpoint();
    if (null == e) {
        LOG.fine("No endpoint.");
        return;
    }
    EndpointInfo ei = e.getEndpointInfo();
    Bus bus = exchange.getBus();
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    if (null == pe) {
        return;
    }
    Destination destination = exchange.getDestination();
    Exception ex = exchange.get(Exception.class);
    List<Interceptor<? extends Message>> faultInterceptors = new ArrayList<>();
    Collection<Assertion> assertions = new ArrayList<>();
    // 1. Check overridden policy
    Policy p = (Policy) msg.getContextualProperty(PolicyConstants.POLICY_OVERRIDE);
    if (p != null) {
        EndpointPolicyImpl endpi = new EndpointPolicyImpl(p);
        EffectivePolicyImpl effectivePolicy = new EffectivePolicyImpl();
        effectivePolicy.initialise(endpi, pe, false, true, msg);
        PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy());
        faultInterceptors.addAll(effectivePolicy.getInterceptors());
        assertions.addAll(effectivePolicy.getChosenAlternative());
    } else {
        // 2. Process effective server policy
        BindingFaultInfo bfi = getBindingFaultInfo(msg, ex, boi);
        if (bfi == null && msg.get(FaultMode.class) != FaultMode.UNCHECKED_APPLICATION_FAULT && msg.get(FaultMode.class) != FaultMode.CHECKED_APPLICATION_FAULT) {
            return;
        }
        EffectivePolicy effectivePolicy = pe.getEffectiveServerFaultPolicy(ei, boi, bfi, destination, msg);
        if (effectivePolicy != null) {
            faultInterceptors.addAll(effectivePolicy.getInterceptors());
            assertions.addAll(effectivePolicy.getChosenAlternative());
        }
    }
    // add interceptors into message chain
    for (Interceptor<? extends Message> oi : faultInterceptors) {
        msg.getInterceptorChain().add(oi);
        LOG.log(Level.FINE, "Added interceptor of type {0}", oi.getClass().getSimpleName());
    }
    // insert assertions of the chosen alternative into the message
    if (!assertions.isEmpty()) {
        msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
    }
}
Also used : Policy(org.apache.neethi.Policy) Bus(org.apache.cxf.Bus) Destination(org.apache.cxf.transport.Destination) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) Assertion(org.apache.neethi.Assertion) Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) FaultMode(org.apache.cxf.message.FaultMode) Endpoint(org.apache.cxf.endpoint.Endpoint) Interceptor(org.apache.cxf.interceptor.Interceptor) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 18 with Assertion

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

the class PolicyDataEngineImpl method getClientEndpointPolicy.

public <T> T getClientEndpointPolicy(Message m, EndpointInfo ei, Conduit c, PolicyCalculator<T> policyCalculator) {
    Collection<Assertion> alternative = getPolicyEngine().getClientEndpointPolicy(ei, c, m).getChosenAlternative();
    List<T> filteredPolicies = new ArrayList<>();
    for (Assertion a : alternative) {
        if (policyCalculator.getDataClassName().equals(a.getName())) {
            T p = JaxbAssertion.cast(a, policyCalculator.getDataClass()).getData();
            filteredPolicies.add(p);
        }
    }
    return getPolicy(filteredPolicies, policyCalculator);
}
Also used : JaxbAssertion(org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion) Assertion(org.apache.neethi.Assertion) ArrayList(java.util.ArrayList)

Example 19 with Assertion

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

the class PolicyEngineImpl method supportsAlternative.

/**
 * Check if a given list of assertions can potentially be supported by
 * interceptors or by an already installed assertor (a conduit or transport
 * that implements the Assertor interface).
 *
 * @param alternative the policy alternative
 * @param assertor the assertor
 * @return true iff the alternative can be supported
 */
public boolean supportsAlternative(Collection<? extends PolicyComponent> alternative, Assertor assertor, Message m) {
    PolicyInterceptorProviderRegistry pipr = bus.getExtension(PolicyInterceptorProviderRegistry.class);
    final boolean doLog = LOG.isLoggable(Level.FINE);
    for (PolicyComponent pc : alternative) {
        if (pc instanceof Assertion) {
            Assertion a = (Assertion) pc;
            if (!a.isOptional()) {
                if (null != assertor && assertor.canAssert(a.getName())) {
                    continue;
                }
                Set<PolicyInterceptorProvider> s = pipr.get(a.getName());
                if (s.isEmpty()) {
                    if (doLog) {
                        LOG.fine("Alternative " + a.getName() + " is not supported");
                    }
                    return false;
                }
                for (PolicyInterceptorProvider p : s) {
                    if (!p.configurationPresent(m, a)) {
                        if (doLog) {
                            LOG.fine("Alternative " + a.getName() + " is not supported");
                        }
                        return false;
                    }
                }
            }
        } else {
            return false;
        }
    }
    return true;
}
Also used : PolicyComponent(org.apache.neethi.PolicyComponent) Assertion(org.apache.neethi.Assertion)

Example 20 with Assertion

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

the class PolicyEngineImpl method addAssertions.

void addAssertions(PolicyComponent pc, boolean includeOptional, Collection<Assertion> assertions) {
    if (Constants.TYPE_ASSERTION == pc.getType()) {
        Assertion a = (Assertion) pc;
        if (includeOptional || !a.isOptional()) {
            assertions.add((Assertion) pc);
        }
        return;
    }
    if (Constants.TYPE_POLICY_REF == pc.getType()) {
        PolicyReference pr = (PolicyReference) pc;
        pc = pr.normalize(registry, false);
    }
    PolicyOperator po = (PolicyOperator) pc;
    List<PolicyComponent> pcs = CastUtils.cast(po.getPolicyComponents(), PolicyComponent.class);
    for (PolicyComponent child : pcs) {
        addAssertions(child, includeOptional, assertions);
    }
}
Also used : PolicyComponent(org.apache.neethi.PolicyComponent) PolicyOperator(org.apache.neethi.PolicyOperator) Assertion(org.apache.neethi.Assertion) PolicyReference(org.apache.neethi.PolicyReference)

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