Search in sources :

Example 16 with PolicyException

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

the class AbstractPolicySecurityTest method runInInterceptorAndValidate.

protected void runInInterceptorAndValidate(Document document, Policy policy, List<QName> assertedInAssertions, List<QName> notAssertedInAssertions, List<CoverageType> types) throws Exception {
    final AssertionInfoMap aim = new AssertionInfoMap(policy);
    this.runInInterceptorAndValidateWss(document, aim, types);
    try {
        aim.checkEffectivePolicy(policy);
    } catch (PolicyException e) {
    // Expected but not relevant
    } finally {
        if (assertedInAssertions != null) {
            for (QName assertionType : assertedInAssertions) {
                Collection<AssertionInfo> ais = aim.get(assertionType);
                assertNotNull(ais);
                for (AssertionInfo ai : ais) {
                    checkAssertion(aim, assertionType, ai, true);
                }
            }
        }
        if (notAssertedInAssertions != null) {
            for (QName assertionType : notAssertedInAssertions) {
                Collection<AssertionInfo> ais = aim.get(assertionType);
                assertNotNull(ais);
                for (AssertionInfo ai : ais) {
                    checkAssertion(aim, assertionType, ai, false);
                }
            }
        }
    }
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) PolicyException(org.apache.cxf.ws.policy.PolicyException) QName(javax.xml.namespace.QName) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 17 with PolicyException

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

the class DomainExpressionBuilderRegistry method build.

public DomainExpression build(Element element) {
    loadDynamic();
    DomainExpressionBuilder builder;
    QName qname = new QName(element.getNamespaceURI(), element.getLocalName());
    builder = get(qname);
    if (null == builder) {
        throw new PolicyException(new Message("NO_DOMAINEXPRESSIONBUILDER_EXC", BUNDLE, qname.toString()));
    }
    return builder.build(element);
}
Also used : Message(org.apache.cxf.common.i18n.Message) PolicyException(org.apache.cxf.ws.policy.PolicyException) QName(javax.xml.namespace.QName)

Example 18 with PolicyException

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

the class EndpointReferenceDomainExpressionBuilder method build.

public DomainExpression build(Element e) {
    Object obj = null;
    try {
        obj = JAXBUtils.unmarshall(createJAXBContext(), e);
    } catch (JAXBException ex) {
        throw new PolicyException(new Message("EPR_DOMAIN_EXPRESSION_BUILD_EXC", BUNDLE, (Object[]) null), ex);
    }
    if (obj instanceof JAXBElement<?>) {
        JAXBElement<?> el = (JAXBElement<?>) obj;
        obj = el.getValue();
    }
    EndpointReferenceDomainExpression eprde = new EndpointReferenceDomainExpression();
    eprde.setEndpointReference((EndpointReferenceType) obj);
    return eprde;
}
Also used : Message(org.apache.cxf.common.i18n.Message) PolicyException(org.apache.cxf.ws.policy.PolicyException) JAXBException(javax.xml.bind.JAXBException) JAXBElement(javax.xml.bind.JAXBElement)

Example 19 with PolicyException

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

the class EndpointReferenceDomainExpressionBuilder method createJAXBContext.

protected synchronized JAXBContext createJAXBContext() {
    if (context == null) {
        try {
            Class<?> clz = EndpointReferenceType.class;
            String pkg = PackageUtils.getPackageName(clz);
            context = JAXBContext.newInstance(pkg, clz.getClassLoader());
        } catch (JAXBException ex) {
            throw new PolicyException(new Message("EPR_DOMAIN_EXPRESSION_BUILDER_INIT_EXC", BUNDLE, (Object[]) null), ex);
        }
    }
    return context;
}
Also used : EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) Message(org.apache.cxf.common.i18n.Message) PolicyException(org.apache.cxf.ws.policy.PolicyException) JAXBException(javax.xml.bind.JAXBException)

Example 20 with PolicyException

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

the class RemoteReferenceResolver method resolveReference.

public Policy resolveReference(String uri) {
    int pos = uri.indexOf('#');
    String documentURI = pos == -1 ? uri : uri.substring(0, pos);
    ExtendedURIResolver resolver = new ExtendedURIResolver();
    InputSource is = resolver.resolve(documentURI, baseURI);
    if (null == is) {
        return null;
    }
    Document doc = null;
    try {
        doc = StaxUtils.read(is.getByteStream());
    } catch (Exception ex) {
        throw new PolicyException(ex);
    } finally {
        resolver.close();
    }
    if (pos == -1) {
        return builder.getPolicy(doc.getDocumentElement());
    }
    String id = uri.substring(pos + 1);
    for (Element elem : PolicyConstants.findAllPolicyElementsOfLocalName(doc, Constants.ELEM_POLICY)) {
        if (id.equals(elem.getAttributeNS(PolicyConstants.WSU_NAMESPACE_URI, PolicyConstants.WSU_ID_ATTR_NAME))) {
            return builder.getPolicy(elem);
        }
    }
    return null;
}
Also used : InputSource(org.xml.sax.InputSource) PolicyException(org.apache.cxf.ws.policy.PolicyException) ExtendedURIResolver(org.apache.cxf.resource.ExtendedURIResolver) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) PolicyException(org.apache.cxf.ws.policy.PolicyException)

Aggregations

PolicyException (org.apache.cxf.ws.policy.PolicyException)21 AssertionInfo (org.apache.cxf.ws.policy.AssertionInfo)8 Test (org.junit.Test)8 AssertionInfoMap (org.apache.cxf.ws.policy.AssertionInfoMap)7 Message (org.apache.cxf.common.i18n.Message)6 Policy (org.apache.neethi.Policy)6 QName (javax.xml.namespace.QName)5 Element (org.w3c.dom.Element)4 URL (java.net.URL)3 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)3 Document (org.w3c.dom.Document)3 FileNotFoundException (java.io.FileNotFoundException)2 JAXBException (javax.xml.bind.JAXBException)2 UrlResource (org.springframework.core.io.UrlResource)2 Closeable (java.io.Closeable)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 JAXBElement (javax.xml.bind.JAXBElement)1 SOAPMessage (javax.xml.soap.SOAPMessage)1