use of org.apache.neethi.PolicyComponent 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.PolicyComponent 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);
}
}
use of org.apache.neethi.PolicyComponent 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();
level++;
printPolicyComponent(nested, buf, level);
level--;
}
} else {
level++;
List<PolicyComponent> children = CastUtils.cast(((PolicyOperator) pc).getPolicyComponents(), PolicyComponent.class);
nl(buf);
for (PolicyComponent child : children) {
printPolicyComponent(child, buf, level);
}
level--;
}
}
use of org.apache.neethi.PolicyComponent in project cxf by apache.
the class PolicyBuilderTest method testGetPolicy.
@Test
public void testGetPolicy() throws Exception {
String name = "/samples/test25.xml";
InputStream is = PolicyBuilderTest.class.getResourceAsStream(name);
Policy p = builder.getPolicy(is);
assertNotNull(p);
List<PolicyComponent> a = CastUtils.cast(p.getAssertions(), PolicyComponent.class);
assertEquals(3, a.size());
for (int i = 0; i < 3; i++) {
assertEquals(Constants.TYPE_ASSERTION, a.get(i).getType());
}
}
use of org.apache.neethi.PolicyComponent in project cxf by apache.
the class JaxbAssertionTest method testEqual.
@Test
public void testEqual() {
JaxbAssertion<FooType> assertion = new JaxbAssertion<FooType>();
FooType data = new FooType();
data.setName("CXF");
data.setNumber(2);
QName qn = new QName("http://cxf.apache.org/test/assertions/foo", "FooType");
assertion.setName(qn);
assertion.setData(data);
PolicyComponent pc = new Policy();
assertTrue(!assertion.equal(pc));
pc = new All();
assertTrue(!assertion.equal(pc));
pc = new ExactlyOne();
assertTrue(!assertion.equal(pc));
IMocksControl ctrl = EasyMock.createNiceControl();
PrimitiveAssertion xpa = ctrl.createMock(PrimitiveAssertion.class);
QName oqn = new QName("http://cxf.apache.org/test/assertions/blah", "OtherType");
EasyMock.expect(xpa.getName()).andReturn(oqn);
EasyMock.expect(xpa.getType()).andReturn(Constants.TYPE_ASSERTION);
ctrl.replay();
assertTrue(!assertion.equal(xpa));
ctrl.verify();
FooType odata = new FooType();
odata.setName(data.getName());
odata.setNumber(data.getNumber());
JaxbAssertion<FooType> oassertion = new JaxbAssertion<FooType>();
oassertion.setData(odata);
oassertion.setName(qn);
assertTrue(!assertion.equal(oassertion));
oassertion.setData(data);
assertTrue(assertion.equal(oassertion));
assertTrue(assertion.equal(assertion));
}
Aggregations