Search in sources :

Example 26 with Policy

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

the class AbstractPolicyProvider method resolveExternal.

protected Policy resolveExternal(PolicyReference ref, String baseURI) {
    Policy resolved = registry.lookup(ref.getURI());
    if (null != resolved) {
        return resolved;
    }
    ReferenceResolver resolver = new RemoteReferenceResolver(baseURI, builder);
    return resolver.resolveReference(ref.getURI());
}
Also used : Policy(org.apache.neethi.Policy) RemoteReferenceResolver(org.apache.cxf.ws.policy.attachment.reference.RemoteReferenceResolver) ReferenceResolver(org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver) RemoteReferenceResolver(org.apache.cxf.ws.policy.attachment.reference.RemoteReferenceResolver)

Example 27 with Policy

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

the class ExternalAttachmentProvider method readDocument.

void readDocument() {
    if (null != attachments) {
        return;
    }
    // read the document and build the attachments
    attachments = new ArrayList<>();
    Document doc = null;
    try {
        InputStream is = location.getInputStream();
        if (null == is) {
            throw new PolicyException(new org.apache.cxf.common.i18n.Message("COULD_NOT_OPEN_ATTACHMENT_DOC_EXC", BUNDLE, location));
        }
        doc = StaxUtils.read(is);
    } catch (Exception ex) {
        throw new PolicyException(ex);
    }
    for (Element ae : PolicyConstants.findAllPolicyElementsOfLocalName(doc, Constants.ELEM_POLICY_ATTACHMENT)) {
        PolicyAttachment attachment = new PolicyAttachment();
        for (Node nd = ae.getFirstChild(); nd != null; nd = nd.getNextSibling()) {
            if (Node.ELEMENT_NODE != nd.getNodeType()) {
                continue;
            }
            QName qn = new QName(nd.getNamespaceURI(), nd.getLocalName());
            if (Constants.isAppliesToElem(qn)) {
                Collection<DomainExpression> des = readDomainExpressions((Element) nd);
                if (des.isEmpty()) {
                    // forget about this attachment
                    continue;
                }
                attachment.setDomainExpressions(des);
            } else if (Constants.isPolicyElement(qn)) {
                Policy p = builder.getPolicy(nd);
                if (null != attachment.getPolicy()) {
                    p = p.merge(attachment.getPolicy());
                }
                attachment.setPolicy(p);
                // cache the element so it can be used when generating the wsdl
                attachment.setElement((Element) nd);
            } else if (Constants.isPolicyRef(qn)) {
                PolicyReference ref = builder.getPolicyReference(nd);
                if (null != ref) {
                    Policy p = resolveReference(ref, doc);
                    if (null != attachment.getPolicy()) {
                        p = p.merge(attachment.getPolicy());
                    }
                    attachment.setPolicy(p);
                }
            }
        // TODO: wsse:Security child element
        }
        if (null == attachment.getPolicy() || null == attachment.getDomainExpressions()) {
            continue;
        }
        attachments.add(attachment);
    }
}
Also used : Policy(org.apache.neethi.Policy) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) PolicyReference(org.apache.neethi.PolicyReference) PolicyException(org.apache.cxf.ws.policy.PolicyException) PolicyException(org.apache.cxf.ws.policy.PolicyException)

Example 28 with Policy

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

the class ExternalAttachmentProvider method getEffectivePolicy.

public Policy getEffectivePolicy(ServiceInfo si, Message m) {
    readDocument();
    Policy p = null;
    for (PolicyAttachment pa : attachments) {
        if (pa.appliesTo(si)) {
            if (p == null) {
                p = new Policy();
            }
            p = p.merge(pa.getPolicy());
        }
    }
    return p;
}
Also used : Policy(org.apache.neethi.Policy)

Example 29 with Policy

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

the class ExternalAttachmentProvider method resolveLocal.

Policy resolveLocal(PolicyReference ref, Document doc) {
    String relativeURI = ref.getURI().substring(1);
    String absoluteURI = doc.getBaseURI() + ref.getURI();
    Policy resolved = registry.lookup(absoluteURI);
    if (null != resolved) {
        return resolved;
    }
    ReferenceResolver resolver = new LocalDocumentReferenceResolver(doc, builder);
    resolved = resolver.resolveReference(relativeURI);
    if (null != resolved) {
        ref.setURI(absoluteURI);
        registry.register(absoluteURI, resolved);
    }
    return resolved;
}
Also used : Policy(org.apache.neethi.Policy) LocalDocumentReferenceResolver(org.apache.cxf.ws.policy.attachment.reference.LocalDocumentReferenceResolver) ReferenceResolver(org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver) LocalDocumentReferenceResolver(org.apache.cxf.ws.policy.attachment.reference.LocalDocumentReferenceResolver)

Example 30 with Policy

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

the class Wsdl11AttachmentPolicyProvider method getEffectivePolicy.

/**
 * The effective policy for a WSDL endpoint policy subject includes the element policy of the
 * wsdl11:port element that defines the endpoint merged with the element policy of the
 * referenced wsdl11:binding element and the element policy of the referenced wsdl11:portType
 * element that defines the interface of the endpoint.
 *
 * @param ei the EndpointInfo object identifying the endpoint
 * @return the effective policy
 */
public Policy getEffectivePolicy(EndpointInfo ei, Message m) {
    Policy p = getElementPolicy(ei);
    p = mergePolicies(p, getElementPolicy(ei.getBinding()));
    p = mergePolicies(p, getElementPolicy(ei.getInterface(), true));
    return p;
}
Also used : Policy(org.apache.neethi.Policy)

Aggregations

Policy (org.apache.neethi.Policy)122 Test (org.junit.Test)47 Assertion (org.apache.neethi.Assertion)27 QName (javax.xml.namespace.QName)23 ArrayList (java.util.ArrayList)21 All (org.apache.neethi.All)18 ExactlyOne (org.apache.neethi.ExactlyOne)18 Message (org.apache.cxf.message.Message)15 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)14 Element (org.w3c.dom.Element)13 Bus (org.apache.cxf.Bus)12 PrimitiveAssertion (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion)12 List (java.util.List)9 Interceptor (org.apache.cxf.interceptor.Interceptor)9 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)9 HashMap (java.util.HashMap)7 OMElement (org.apache.axiom.om.OMElement)7 MessageImpl (org.apache.cxf.message.MessageImpl)7 ReferenceResolver (org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver)6 InputStream (java.io.InputStream)5