Search in sources :

Example 36 with Assertion

use of org.apache.neethi.Assertion 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 37 with Assertion

use of org.apache.neethi.Assertion in project tesb-rt-se by Talend.

the class SingleBusLocatorRegistrar method isSecuredByPolicy.

/**
 * Is the transport secured by a policy
 */
private boolean isSecuredByPolicy(Server server) {
    boolean isSecured = false;
    EndpointInfo ei = server.getEndpoint().getEndpointInfo();
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    if (null == pe) {
        LOG.finest("No Policy engine found");
        return isSecured;
    }
    Destination destination = server.getDestination();
    EndpointPolicy ep = pe.getServerEndpointPolicy(ei, destination, null);
    Collection<Assertion> assertions = ep.getChosenAlternative();
    for (Assertion a : assertions) {
        if (a instanceof TransportBinding) {
            TransportBinding tb = (TransportBinding) a;
            TransportToken tt = tb.getTransportToken();
            AbstractToken t = tt.getToken();
            if (t instanceof HttpsToken) {
                isSecured = true;
                break;
            }
        }
    }
    Policy policy = ep.getPolicy();
    List<PolicyComponent> pcList = policy.getPolicyComponents();
    for (PolicyComponent a : pcList) {
        if (a instanceof TransportBinding) {
            TransportBinding tb = (TransportBinding) a;
            TransportToken tt = tb.getTransportToken();
            AbstractToken t = tt.getToken();
            if (t instanceof HttpsToken) {
                isSecured = true;
                break;
            }
        }
    }
    return isSecured;
}
Also used : TransportToken(org.apache.wss4j.policy.model.TransportToken) EndpointPolicy(org.apache.cxf.ws.policy.EndpointPolicy) Policy(org.apache.neethi.Policy) Destination(org.apache.cxf.transport.Destination) PolicyComponent(org.apache.neethi.PolicyComponent) Assertion(org.apache.neethi.Assertion) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) EndpointPolicy(org.apache.cxf.ws.policy.EndpointPolicy) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) HttpsToken(org.apache.wss4j.policy.model.HttpsToken) AbstractToken(org.apache.wss4j.policy.model.AbstractToken) TransportBinding(org.apache.wss4j.policy.model.TransportBinding)

Example 38 with Assertion

use of org.apache.neethi.Assertion in project cxf by apache.

the class MGF256AlgorithmSuiteLoader 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, "Basic256GCMMGFSHA256");
        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 GCMAlgorithmSuite(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 39 with Assertion

use of org.apache.neethi.Assertion in project cxf by apache.

the class HTTPServerAssertionBuilderTest method testBuildAssertion.

@Test
public void testBuildAssertion() throws Exception {
    HTTPServerAssertionBuilder ab = new HTTPServerAssertionBuilder();
    Assertion a = ab.buildAssertion();
    assertTrue(a instanceof JaxbAssertion);
    assertTrue(a instanceof HTTPServerAssertionBuilder.HTTPServerPolicyAssertion);
    assertEquals(new ServerPolicyCalculator().getDataClassName(), a.getName());
    assertFalse(a.isOptional());
}
Also used : JaxbAssertion(org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion) Assertion(org.apache.neethi.Assertion) JaxbAssertion(org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion) ServerPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator) Test(org.junit.Test)

Example 40 with Assertion

use of org.apache.neethi.Assertion in project cxf by apache.

the class AssertionInfoMap method checkEffectivePolicy.

public List<List<Assertion>> checkEffectivePolicy(Policy policy) {
    List<List<Assertion>> validated = new ArrayList<>(4);
    List<QName> errors = new ArrayList<>();
    Iterator<List<Assertion>> alternatives = policy.getAlternatives();
    while (alternatives.hasNext()) {
        List<Assertion> pc = alternatives.next();
        if (supportsAlternative(pc, errors)) {
            validated.add(pc);
        }
    }
    if (!validated.isEmpty()) {
        return validated;
    }
    Set<String> msgs = new LinkedHashSet<>();
    for (QName name : errors) {
        Collection<AssertionInfo> ais = getAssertionInfo(name);
        boolean found = false;
        for (AssertionInfo ai : ais) {
            if (!ai.isAsserted()) {
                String s = name.toString();
                if (ai.getErrorMessage() != null) {
                    s += ": " + ai.getErrorMessage();
                }
                msgs.add(s);
                found = true;
            }
        }
        if (!found) {
            msgs.add(name.toString());
        }
    }
    StringBuilder error = new StringBuilder();
    for (String msg : msgs) {
        error.append('\n').append(msg);
    }
    throw new PolicyException(new Message("NO_ALTERNATIVE_EXC", BUNDLE, error.toString()));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Message(org.apache.cxf.common.i18n.Message) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Assertion(org.apache.neethi.Assertion) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Assertion (org.apache.neethi.Assertion)64 Policy (org.apache.neethi.Policy)27 Message (org.apache.cxf.message.Message)25 Test (org.junit.Test)25 ArrayList (java.util.ArrayList)23 QName (javax.xml.namespace.QName)21 Interceptor (org.apache.cxf.interceptor.Interceptor)19 PrimitiveAssertion (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion)19 PolicyContainingAssertion (org.apache.neethi.PolicyContainingAssertion)9 Element (org.w3c.dom.Element)9 MessageImpl (org.apache.cxf.message.MessageImpl)7 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)7 All (org.apache.neethi.All)7 ExactlyOne (org.apache.neethi.ExactlyOne)7 Bus (org.apache.cxf.Bus)6 InterceptorChain (org.apache.cxf.interceptor.InterceptorChain)6 PolicyEngine (org.apache.cxf.ws.policy.PolicyEngine)6 PolicyContainingPrimitiveAssertion (org.apache.neethi.builders.PolicyContainingPrimitiveAssertion)6 XMLPrimitiveAssertionBuilder (org.apache.neethi.builders.xml.XMLPrimitiveAssertionBuilder)6 List (java.util.List)5