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