Java Code Examples for org.apache.neethi.Assertion#isOptional()

The following examples show how to use org.apache.neethi.Assertion#isOptional() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
protected void policyNotAsserted(Assertion assertion, Exception reason) {
    if (assertion == null) {
        return;
    }
    LOG.log(Level.FINE, "Not asserting " + assertion.getName() + ": " + reason);
    Collection<AssertionInfo> ais;
    ais = aim.get(assertion.getName());
    if (ais != null) {
        for (AssertionInfo ai : ais) {
            if (ai.getAssertion() == assertion) {
                ai.setNotAsserted(reason.getMessage());
            }
        }
    }
    if (!assertion.isOptional()) {
        throw new PolicyException(new Message(reason.getMessage(), LOG));
    }
}
 
Example 2
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
protected void policyNotAsserted(Assertion assertion, String reason) {
    if (assertion == null) {
        return;
    }
    LOG.log(Level.FINE, "Not asserting " + assertion.getName() + ": " + reason);
    Collection<AssertionInfo> ais;
    ais = aim.get(assertion.getName());
    if (ais != null) {
        for (AssertionInfo ai : ais) {
            if (ai.getAssertion() == assertion) {
                ai.setNotAsserted(reason);
            }
        }
    }
    if (!assertion.isOptional()) {
        throw new PolicyException(new Message(reason, LOG));
    }
}
 
Example 3
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
protected void policyNotAsserted(Assertion assertion, Exception reason) {
    if (assertion == null) {
        return;
    }
    LOG.log(Level.FINE, "Not asserting " + assertion.getName() + ": " + reason);
    Collection<AssertionInfo> ais;
    ais = aim.get(assertion.getName());
    if (ais != null) {
        for (AssertionInfo ai : ais) {
            if (ai.getAssertion() == assertion) {
                ai.setNotAsserted(reason.getMessage());
            }
        }
    }
    if (!assertion.isOptional()) {
        throw new PolicyException(new Message(reason.getMessage(), LOG));
    }
}
 
Example 4
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
protected void policyNotAsserted(Assertion assertion, String reason) {
    if (assertion == null) {
        return;
    }
    LOG.log(Level.FINE, "Not asserting " + assertion.getName() + ": " + reason);
    Collection<AssertionInfo> ais;
    ais = aim.get(assertion.getName());
    if (ais != null) {
        for (AssertionInfo ai : ais) {
            if (ai.getAssertion() == assertion) {
                ai.setNotAsserted(reason);
            }
        }
    }
    if (!assertion.isOptional()) {
        throw new PolicyException(new Message(reason, LOG));
    }
}
 
Example 5
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
protected void policyNotAsserted(Assertion assertion, Exception reason) {
    if (assertion == null) {
        return;
    }
    LOG.log(Level.FINE, "Not asserting " + assertion.getName() + ": " + reason);
    Collection<AssertionInfo> ais;
    ais = aim.get(assertion.getName());
    if (ais != null) {
        for (AssertionInfo ai : ais) {
            if (ai.getAssertion() == assertion) {
                ai.setNotAsserted(reason.getMessage());
            }
        }
    }
    if (!assertion.isOptional()) {
        throw new PolicyException(new Message(reason.getMessage(), LOG));
    }
}
 
Example 6
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
protected void policyNotAsserted(Assertion assertion, String reason) {
    if (assertion == null) {
        return;
    }
    LOG.log(Level.FINE, "Not asserting " + assertion.getName() + ": " + reason);
    Collection<AssertionInfo> ais;
    ais = aim.get(assertion.getName());
    if (ais != null) {
        for (AssertionInfo ai : ais) {
            if (ai.getAssertion() == assertion) {
                ai.setNotAsserted(reason);
            }
        }
    }
    if (!assertion.isOptional()) {
        throw new PolicyException(new Message(reason, LOG));
    }
}
 
Example 7
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
protected void policyNotAsserted(Assertion assertion, Exception reason) {
    if (assertion == null) {
        return;
    }
    LOG.log(Level.FINE, "Not asserting " + assertion.getName() + ": " + reason);
    Collection<AssertionInfo> ais;
    ais = aim.get(assertion.getName());
    if (ais != null) {
        for (AssertionInfo ai : ais) {
            if (ai.getAssertion() == assertion) {
                ai.setNotAsserted(reason.getMessage());
            }
        }
    }
    if (!assertion.isOptional()) {
        throw new PolicyException(new Message(reason.getMessage(), LOG));
    }
}
 
Example 8
Source File: AbstractBindingBuilder.java    From steady with Apache License 2.0 6 votes vote down vote up
protected void policyNotAsserted(Assertion assertion, String reason) {
    if (assertion == null) {
        return;
    }
    LOG.log(Level.FINE, "Not asserting " + assertion.getName() + ": " + reason);
    Collection<AssertionInfo> ais;
    ais = aim.get(assertion.getName());
    if (ais != null) {
        for (AssertionInfo ai : ais) {
            if (ai.getAssertion() == assertion) {
                ai.setNotAsserted(reason);
            }
        }
    }
    if (!assertion.isOptional()) {
        throw new PolicyException(new Message(reason, LOG));
    }
}
 
Example 9
Source File: AbstractCommonBindingHandler.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void unassertPolicy(Assertion assertion, String reason) {
    if (assertion == null) {
        return;
    }
    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "Not asserting " + assertion.getName() + ": " + reason);
    }
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    Collection<AssertionInfo> ais = aim.get(assertion.getName());
    if (ais != null) {
        for (AssertionInfo ai : ais) {
            if (ai.getAssertion() == assertion) {
                ai.setNotAsserted(reason);
            }
        }
    }
    if (!assertion.isOptional()) {
        throw new PolicyException(new Message(reason, LOG));
    }
}
 
Example 10
Source File: AbstractCommonBindingHandler.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void unassertPolicy(Assertion assertion, Exception reason) {
    if (assertion == null) {
        return;
    }
    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "Not asserting " + assertion.getName() + ": " + reason);
    }
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    Collection<AssertionInfo> ais = aim.get(assertion.getName());
    if (ais != null) {
        for (AssertionInfo ai : ais) {
            if (ai.getAssertion() == assertion) {
                ai.setNotAsserted(reason.getMessage());
            }
        }
    }
    if (!assertion.isOptional()) {
        throw new PolicyException(new Message(reason.getMessage(), LOG), reason);
    }
}
 
Example 11
Source File: PolicyEngineImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
Collection<Assertion> getAssertions(EffectivePolicy pc, boolean includeOptional) {
    if (pc == null || pc.getChosenAlternative() == null) {
        return null;
    }
    Collection<Assertion> assertions = new ArrayList<>();
    for (Assertion assertion : pc.getChosenAlternative()) {
        if (Constants.TYPE_ASSERTION == assertion.getType()) {
            if (includeOptional || !assertion.isOptional()) {
                assertions.add(assertion);
            }
        } else {
            addAssertions(assertion, includeOptional, assertions);
        }
    }
    return assertions;
}
 
Example 12
Source File: PolicyEngineImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 13
Source File: PolicyInterceptorProviderRegistryImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public List<Interceptor<? extends Message>>
getInterceptorsForAlternative(Collection<? extends Assertion> alternative,
                              boolean out, boolean fault) {

    List<Interceptor<? extends Message>> interceptors = new ArrayList<>();
    for (Assertion a : alternative) {
        if (a.isOptional()) {
            continue;
        }
        QName qn = a.getName();
        interceptors.addAll(getInterceptorsForAssertion(qn, out, fault));
    }
    return interceptors;
}
 
Example 14
Source File: PolicyEngineImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Return a collection of all assertions used in the given policy component,
 * optionally including optional assertions.
 * The policy need not be normalised, so any policy references will have to be resolved.
 * @param pc the policy component
 * @param includeOptional flag indicating if optional assertions should be included
 * @return the assertions
 */
Collection<Assertion> getAssertions(PolicyComponent pc, boolean includeOptional) {

    Collection<Assertion> assertions = new ArrayList<>();

    if (Constants.TYPE_ASSERTION == pc.getType()) {
        Assertion a = (Assertion)pc;
        if (includeOptional || !a.isOptional()) {
            assertions.add(a);
        }
    } else {
        addAssertions(pc, includeOptional, assertions);
    }
    return assertions;
}
 
Example 15
Source File: PolicyEngineImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 16
Source File: AssertionInfoMap.java    From cxf with Apache License 2.0 4 votes vote down vote up
public boolean supportsAlternative(PolicyComponent assertion,
                                   List<QName> errors) {
    boolean pass = true;
    if (assertion instanceof PolicyAssertion) {
        PolicyAssertion a = (PolicyAssertion)assertion;
        if (!a.isAsserted(this) && !a.isOptional()) {
            errors.add(a.getName());
            pass = false;
        }
    } else if (assertion instanceof Assertion) {
        Assertion ass = (Assertion)assertion;
        Collection<AssertionInfo> ail = getAssertionInfo(ass.getName());
        boolean found = false;
        for (AssertionInfo ai : ail) {
            if (ai.getAssertion().equal(ass) || ai.getAssertion().equals(ass)) {
                found = true;
                if (!ai.isAsserted() && !ass.isOptional()) {
                    errors.add(ass.getName());
                    pass = false;
                }
            }
        }
        if (!found) {
            errors.add(ass.getName());
            return false;
        }
    }
    if (assertion instanceof PolicyContainingAssertion) {
        Policy p = ((PolicyContainingAssertion)assertion).getPolicy();
        if (p != null) {
            Iterator<List<Assertion>> alternatives = p.getAlternatives();
            while (alternatives.hasNext()) {
                List<Assertion> pc = alternatives.next();
                for (Assertion p2 : pc) {
                    pass &= supportsAlternative(p2, errors);
                }
            }
        }
    }
    return pass;
}