Search in sources :

Example 1 with PrimitiveAssertion

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

the class WSSCUnitTest method testIssueUnitTest.

@Test
public void testIssueUnitTest() throws Exception {
    if (test.isStreaming()) {
        return;
    }
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = WSSCUnitTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    STSClient stsClient = new STSClient(bus);
    stsClient.setSecureConv(true);
    stsClient.setLocation("https://localhost:" + PORT + "/" + "DoubleItTransport");
    // Add Addressing policy
    Policy p = new Policy();
    ExactlyOne ea = new ExactlyOne();
    p.addPolicyComponent(ea);
    All all = new All();
    all.addPolicyComponent(new PrimitiveAssertion(MetadataConstants.USING_ADDRESSING_2006_QNAME, false));
    ea.addPolicyComponent(all);
    stsClient.setPolicy(p);
    stsClient.requestSecurityToken("http://localhost:" + PORT + "/" + "DoubleItTransport");
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) Bus(org.apache.cxf.Bus) STSClient(org.apache.cxf.ws.security.trust.STSClient) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) ExactlyOne(org.apache.neethi.ExactlyOne) URL(java.net.URL) Test(org.junit.Test)

Example 2 with PrimitiveAssertion

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

the class SHA512PolicyLoader method getAlgorithmSuite.

public AlgorithmSuite getAlgorithmSuite(Bus bus, SPConstants.SPVersion version, Policy nestedPolicy) {
    AssertionBuilderRegistry reg = bus.getExtension(AssertionBuilderRegistry.class);
    if (reg != null) {
        String ns = "http://cxf.apache.org/custom/security-policy";
        final Map<QName, Assertion> assertions = new HashMap<>();
        QName qName = new QName(ns, "Basic128RsaSha512");
        assertions.put(qName, new PrimitiveAssertion(qName));
        reg.registerBuilder(new PrimitiveAssertionBuilder(assertions.keySet()) {

            public Assertion build(Element element, AssertionBuilderFactory fact) {
                if (XMLPrimitiveAssertionBuilder.isOptional(element) || XMLPrimitiveAssertionBuilder.isIgnorable(element)) {
                    return super.build(element, fact);
                }
                QName q = new QName(element.getNamespaceURI(), element.getLocalName());
                return assertions.get(q);
            }
        });
    }
    return new SHA512AlgorithmSuite(version, nestedPolicy);
}
Also used : AssertionBuilderRegistry(org.apache.cxf.ws.policy.AssertionBuilderRegistry) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Element(org.w3c.dom.Element) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion) AbstractSecurityAssertion(org.apache.wss4j.policy.model.AbstractSecurityAssertion) AssertionBuilderFactory(org.apache.neethi.AssertionBuilderFactory) PrimitiveAssertionBuilder(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertionBuilder) XMLPrimitiveAssertionBuilder(org.apache.neethi.builders.xml.XMLPrimitiveAssertionBuilder)

Example 3 with PrimitiveAssertion

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

the class AddressingAssertionBuilder method build.

public Assertion build(Element elem, AssertionBuilderFactory factory) {
    String localName = elem.getLocalName();
    QName qn = new QName(elem.getNamespaceURI(), localName);
    boolean optional = false;
    Attr attribute = PolicyConstants.findOptionalAttribute(elem);
    if (attribute != null) {
        optional = Boolean.valueOf(attribute.getValue());
    }
    if (MetadataConstants.ADDRESSING_ASSERTION_QNAME.equals(qn) || MetadataConstants.ADDRESSING_ASSERTION_QNAME_0705.equals(qn)) {
        Assertion nap = new XMLPrimitiveAssertionBuilder() {

            public Assertion newPrimitiveAssertion(Element element, Map<QName, String> mp) {
                return new PrimitiveAssertion(MetadataConstants.ADDRESSING_ASSERTION_QNAME, isOptional(element), isIgnorable(element), mp);
            }

            public Assertion newPolicyContainingAssertion(Element element, Map<QName, String> mp, Policy policy) {
                return new PolicyContainingPrimitiveAssertion(MetadataConstants.ADDRESSING_ASSERTION_QNAME, isOptional(element), isIgnorable(element), mp, policy);
            }
        }.build(elem, factory);
        if (!(nap instanceof PolicyContainingPrimitiveAssertion || nap instanceof PrimitiveAssertion)) {
            // this happens when neethi fails to recognize the specified addressing policy element
            LOG.warning("Unable to recognize the addressing policy");
        }
        return nap;
    } else if (MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME.equals(qn) || MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME_0705.equals(qn)) {
        return new PrimitiveAssertion(MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME, optional);
    } else if (MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME.getLocalPart().equals(localName) || MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME_0705.getLocalPart().equals(localName)) {
        return new PrimitiveAssertion(MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME, optional);
    }
    return null;
}
Also used : Policy(org.apache.neethi.Policy) XMLPrimitiveAssertionBuilder(org.apache.neethi.builders.xml.XMLPrimitiveAssertionBuilder) QName(javax.xml.namespace.QName) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Element(org.w3c.dom.Element) 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) Attr(org.w3c.dom.Attr)

Example 4 with PrimitiveAssertion

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

the class ExternalAttachmentProviderTest method setUpAttachment.

void setUpAttachment(Object subject, boolean applies, ExternalAttachmentProvider eap) {
    attachments.clear();
    attachment = control.createMock(PolicyAttachment.class);
    attachments.add(attachment);
    policy = new Policy();
    assertion = new PrimitiveAssertion(TEST_ASSERTION_TYPE);
    policy.addAssertion(assertion);
    eap.setAttachments(attachments);
    if (subject instanceof ServiceInfo) {
        EasyMock.expect(attachment.appliesTo((ServiceInfo) subject)).andReturn(applies);
    } else if (subject instanceof EndpointInfo) {
        EasyMock.expect(attachment.appliesTo((EndpointInfo) subject)).andReturn(applies);
    } else if (subject instanceof BindingOperationInfo) {
        EasyMock.expect(attachment.appliesTo((BindingOperationInfo) subject)).andReturn(applies);
    } else if (subject instanceof BindingMessageInfo) {
        EasyMock.expect(attachment.appliesTo((BindingMessageInfo) subject)).andReturn(applies);
    } else if (subject instanceof BindingFaultInfo) {
        EasyMock.expect(attachment.appliesTo((BindingFaultInfo) subject)).andReturn(applies);
    } else {
        System.err.println("subject class: " + subject.getClass());
    }
    if (applies) {
        EasyMock.expect(attachment.getPolicy()).andReturn(policy);
    }
}
Also used : Policy(org.apache.neethi.Policy) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 5 with PrimitiveAssertion

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

the class AssertionInfoMapTest method testCheckEffectivePolicy.

@Test
public void testCheckEffectivePolicy() {
    Policy p = new Policy();
    QName aqn = new QName("http://x.y.z", "a");
    Assertion a = new PrimitiveAssertion(aqn);
    QName bqn = new QName("http://x.y.z", "b");
    Assertion b = new PrimitiveAssertion(bqn);
    QName cqn = new QName("http://x.y.z", "c");
    Assertion c = new PrimitiveAssertion(cqn);
    All alt1 = new All();
    alt1.addAssertion(a);
    alt1.addAssertion(b);
    All alt2 = new All();
    alt2.addAssertion(c);
    ExactlyOne ea = new ExactlyOne();
    ea.addPolicyComponent(alt1);
    ea.addPolicyComponent(alt2);
    p.addPolicyComponent(ea);
    AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, PolicyAssertion.class));
    AssertionInfo ai = new AssertionInfo(a);
    AssertionInfo bi = new AssertionInfo(b);
    AssertionInfo ci = new AssertionInfo(c);
    aim.put(aqn, Collections.singleton(ai));
    aim.put(bqn, Collections.singleton(bi));
    aim.put(cqn, Collections.singleton(ci));
    try {
        aim.checkEffectivePolicy(p);
        fail("Expected PolicyException not thrown.");
    } catch (PolicyException ex) {
    // expected
    }
    ai.setAsserted(true);
    ci.setAsserted(true);
    aim.checkEffectivePolicy(p);
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) 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) ExactlyOne(org.apache.neethi.ExactlyOne) Test(org.junit.Test)

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