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());
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations