Search in sources :

Example 1 with PolicyComponent

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;
}
Also used : PolicyComponent(org.apache.neethi.PolicyComponent) Assertion(org.apache.neethi.Assertion)

Example 2 with PolicyComponent

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);
    }
}
Also used : PolicyComponent(org.apache.neethi.PolicyComponent) PolicyOperator(org.apache.neethi.PolicyOperator) Assertion(org.apache.neethi.Assertion) PolicyReference(org.apache.neethi.PolicyReference)

Example 3 with PolicyComponent

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--;
    }
}
Also used : PolicyComponent(org.apache.neethi.PolicyComponent) Assertion(org.apache.neethi.Assertion) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion)

Example 4 with PolicyComponent

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());
    }
}
Also used : Policy(org.apache.neethi.Policy) PolicyComponent(org.apache.neethi.PolicyComponent) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 5 with PolicyComponent

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));
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) IMocksControl(org.easymock.IMocksControl) FooType(org.apache.cxf.test.assertions.foo.FooType) PolicyComponent(org.apache.neethi.PolicyComponent) QName(javax.xml.namespace.QName) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) ExactlyOne(org.apache.neethi.ExactlyOne) Test(org.junit.Test)

Aggregations

PolicyComponent (org.apache.neethi.PolicyComponent)6 Assertion (org.apache.neethi.Assertion)4 Policy (org.apache.neethi.Policy)3 Test (org.junit.Test)3 QName (javax.xml.namespace.QName)2 FooType (org.apache.cxf.test.assertions.foo.FooType)2 PrimitiveAssertion (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion)2 InputStream (java.io.InputStream)1 List (java.util.List)1 All (org.apache.neethi.All)1 ExactlyOne (org.apache.neethi.ExactlyOne)1 PolicyContainingAssertion (org.apache.neethi.PolicyContainingAssertion)1 PolicyOperator (org.apache.neethi.PolicyOperator)1 PolicyReference (org.apache.neethi.PolicyReference)1 IMocksControl (org.easymock.IMocksControl)1