Search in sources :

Example 6 with PrimitiveAssertion

use of org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion in project cxf by apache.

the class AssertionInfoMapTest method testCheck.

@Test
public void testCheck() throws PolicyException {
    QName aqn = new QName("http://x.y.z", "a");
    Assertion a = new PrimitiveAssertion(aqn);
    Collection<Assertion> assertions = new ArrayList<>();
    assertions.add(a);
    AssertionInfoMap aim = new AssertionInfoMap(assertions);
    try {
        aim.check();
        fail("Expected PolicyException not thrown.");
    } catch (PolicyException ex) {
        assertEquals("NOT_ASSERTED_EXC", ex.getCode());
    }
    aim.get(aqn).iterator().next().setAsserted(true);
    aim.check();
}
Also used : QName(javax.xml.namespace.QName) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with PrimitiveAssertion

use of org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion in project cxf by apache.

the class AssertionInfoMapTest method testAllAssertionsIn.

@Test
public void testAllAssertionsIn() {
    Policy nested = new Policy();
    Assertion nb = new PrimitiveAssertion(new QName("http://x.y.z", "b"));
    nested.addAssertion(nb);
    Policy p = new Policy();
    Assertion a1 = new PrimitiveAssertion(new QName("http://x.y.z", "a"));
    Assertion a2 = new PrimitiveAssertion(new QName("http://x.y.z", "a"));
    Assertion b = new PrimitiveAssertion(new QName("http://x.y.z", "b"));
    Assertion c = new PolicyContainingPrimitiveAssertion(new QName("http://x.y.z", "c"), false, false, nested);
    All alt1 = new All();
    alt1.addAssertion(a1);
    alt1.addAssertion(b);
    All alt2 = new All();
    alt1.addAssertion(a2);
    alt2.addAssertion(c);
    ExactlyOne ea = new ExactlyOne();
    ea.addPolicyComponent(alt1);
    ea.addPolicyComponent(alt2);
    p.addPolicyComponent(ea);
    AssertionInfoMap aim = new AssertionInfoMap(p);
    Collection<AssertionInfo> listA = aim.getAssertionInfo(new QName("http://x.y.z", "a"));
    assertEquals("2 A assertions should've been added", 2, listA.size());
    AssertionInfo[] ais = listA.toArray(new AssertionInfo[] {});
    assertTrue("Two different A instances should be added", ais[0].getAssertion() == a1 && ais[1].getAssertion() == a2 || ais[0].getAssertion() == a2 && ais[1].getAssertion() == a1);
    Collection<AssertionInfo> listB = aim.getAssertionInfo(new QName("http://x.y.z", "b"));
    assertEquals("2 B assertions should've been added", 2, listB.size());
    ais = listB.toArray(new AssertionInfo[] {});
    assertTrue("Two different B instances should be added", ais[0].getAssertion() == nb && ais[1].getAssertion() == b || ais[0].getAssertion() == b && ais[1].getAssertion() == nb);
    Collection<AssertionInfo> listC = aim.getAssertionInfo(new QName("http://x.y.z", "c"));
    assertEquals("1 C assertion should've been added", 1, listC.size());
    ais = listC.toArray(new AssertionInfo[] {});
    assertSame("One C instances should be added", ais[0].getAssertion(), c);
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) QName(javax.xml.namespace.QName) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion) ExactlyOne(org.apache.neethi.ExactlyOne) Test(org.junit.Test)

Example 8 with PrimitiveAssertion

use of org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion in project cxf by apache.

the class IgnorablePolicyInterceptorProviderTest method createTestAssertions.

private AssertionInfoMap createTestAssertions() {
    AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, PolicyAssertion.class));
    Assertion a = new PrimitiveAssertion(ONEWAY_QNAME);
    Assertion b = new PrimitiveAssertion(DUPLEX_QNAME);
    AssertionInfo ai = new AssertionInfo(a);
    AssertionInfo bi = new AssertionInfo(b);
    aim.put(ONEWAY_QNAME, Collections.singleton(ai));
    aim.put(DUPLEX_QNAME, Collections.singleton(bi));
    return aim;
}
Also used : PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion)

Example 9 with PrimitiveAssertion

use of org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion in project cxf by apache.

the class PolicyEngineTest method testAddAssertions.

@Test
public void testAddAssertions() {
    engine = new PolicyEngineImpl();
    Collection<Assertion> assertions = new ArrayList<>();
    Assertion a = control.createMock(Assertion.class);
    EasyMock.expect(a.getType()).andReturn(Constants.TYPE_ASSERTION);
    EasyMock.expect(a.isOptional()).andReturn(true);
    control.replay();
    engine.addAssertions(a, false, assertions);
    assertTrue(assertions.isEmpty());
    control.verify();
    control.reset();
    EasyMock.expect(a.getType()).andReturn(Constants.TYPE_ASSERTION);
    control.replay();
    engine.addAssertions(a, true, assertions);
    assertEquals(1, assertions.size());
    assertSame(a, assertions.iterator().next());
    control.verify();
    assertions.clear();
    Policy p = new Policy();
    a = new PrimitiveAssertion(new QName("http://x.y.z", "a"));
    p.addAssertion(a);
    // id has no #
    engine.getRegistry().register("ab", p);
    // local reference is an id + #
    PolicyReference pr = new PolicyReference();
    pr.setURI("#ab");
    engine.addAssertions(pr, false, assertions);
    assertEquals(1, assertions.size());
    assertSame(a, assertions.iterator().next());
}
Also used : Policy(org.apache.neethi.Policy) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) QName(javax.xml.namespace.QName) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion) ArrayList(java.util.ArrayList) PolicyReference(org.apache.neethi.PolicyReference) Test(org.junit.Test)

Example 10 with PrimitiveAssertion

use of org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion in project cxf by apache.

the class MC11AssertionBuilder method build.

/**
 * @see org.apache.neethi.builders.AssertionBuilder#build(org.w3c.dom.Element,
 *  org.apache.neethi.AssertionBuilderFactory)
 */
public Assertion build(Element elem, AssertionBuilderFactory factory) throws IllegalArgumentException {
    Assertion assertion = null;
    if (WSMC_NAMESPACE.equals(elem.getNamespaceURI()) && MCSUPPORTED_NAME.equals(elem.getLocalName())) {
        boolean optional = XMLPrimitiveAssertionBuilder.isOptional(elem);
        assertion = new PrimitiveAssertion(MCSUPPORTED_QNAME, optional);
    }
    return assertion;
}
Also used : PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion)

Aggregations

PrimitiveAssertion (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion)22 QName (javax.xml.namespace.QName)15 Assertion (org.apache.neethi.Assertion)15 Policy (org.apache.neethi.Policy)10 All (org.apache.neethi.All)6 ExactlyOne (org.apache.neethi.ExactlyOne)6 XMLPrimitiveAssertionBuilder (org.apache.neethi.builders.xml.XMLPrimitiveAssertionBuilder)6 Element (org.w3c.dom.Element)6 PolicyContainingPrimitiveAssertion (org.apache.neethi.builders.PolicyContainingPrimitiveAssertion)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 AssertionBuilderRegistry (org.apache.cxf.ws.policy.AssertionBuilderRegistry)4 PrimitiveAssertionBuilder (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertionBuilder)4 AssertionBuilderFactory (org.apache.neethi.AssertionBuilderFactory)4 ArrayList (java.util.ArrayList)3 AbstractSecurityAssertion (org.apache.wss4j.policy.model.AbstractSecurityAssertion)3 DefaultSymmetricBinding (org.apache.cxf.ws.security.trust.DefaultSymmetricBinding)2 ProtectionToken (org.apache.wss4j.policy.model.ProtectionToken)2 SignedParts (org.apache.wss4j.policy.model.SignedParts)2 URL (java.net.URL)1