Search in sources :

Example 86 with Policy

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

the class EndpointPolicyImplTest method doTestUpdateWithEmptyPolicy.

private void doTestUpdateWithEmptyPolicy(Policy emptyPolicy) {
    Policy p1 = new Policy();
    QName aqn1 = new QName("http://x.y.z", "a");
    p1.addAssertion(mockAssertion(aqn1, 5, true));
    EndpointPolicyImpl epi = new TestEndpointPolicy();
    control.replay();
    epi.setPolicy(p1.normalize(true));
    Policy ep = epi.updatePolicy(emptyPolicy, createMessage()).getPolicy();
    List<ExactlyOne> pops = CastUtils.cast(ep.getPolicyComponents(), ExactlyOne.class);
    assertEquals("New policy must have 1 top level policy operator", 1, pops.size());
    List<All> alts = CastUtils.cast(pops.get(0).getPolicyComponents(), All.class);
    assertEquals("1 alternatives should be available", 1, alts.size());
    List<PolicyAssertion> assertions1 = CastUtils.cast(alts.get(0).getAssertions(), PolicyAssertion.class);
    assertEquals("1 assertion should be available", 1, assertions1.size());
    QName n1 = assertions1.get(0).getName();
    assertTrue("Policy was not merged", n1.equals(aqn1));
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) QName(javax.xml.namespace.QName) ExactlyOne(org.apache.neethi.ExactlyOne)

Example 87 with Policy

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

the class EndpointPolicyImplTest method testUpdatePolicyWithEmptyAll.

@Test
public void testUpdatePolicyWithEmptyAll() {
    Policy emptyPolicy = new Policy();
    emptyPolicy.addPolicyComponent(new All());
    emptyPolicy.addPolicyComponent(new All());
    doTestUpdateWithEmptyPolicy(emptyPolicy);
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) Test(org.junit.Test)

Example 88 with Policy

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

the class PolicyEngineTest method testGetAggregatedServicePolicy.

@Test
public void testGetAggregatedServicePolicy() {
    engine = new PolicyEngineImpl();
    ServiceInfo si = control.createMock(ServiceInfo.class);
    control.replay();
    Policy p = engine.getAggregatedServicePolicy(si, null);
    assertTrue(p.isEmpty());
    control.verify();
    control.reset();
    PolicyProvider provider1 = control.createMock(PolicyProvider.class);
    engine.getPolicyProviders().add(provider1);
    Policy p1 = control.createMock(Policy.class);
    EasyMock.expect(provider1.getEffectivePolicy(si, null)).andReturn(p1);
    control.replay();
    assertSame(p1, engine.getAggregatedServicePolicy(si, null));
    control.verify();
    control.reset();
    PolicyProvider provider2 = control.createMock(PolicyProvider.class);
    engine.getPolicyProviders().add(provider2);
    Policy p2 = control.createMock(Policy.class);
    Policy p3 = control.createMock(Policy.class);
    EasyMock.expect(provider1.getEffectivePolicy(si, null)).andReturn(p1);
    EasyMock.expect(provider2.getEffectivePolicy(si, null)).andReturn(p2);
    EasyMock.expect(p1.merge(p2)).andReturn(p3);
    control.replay();
    assertSame(p3, engine.getAggregatedServicePolicy(si, null));
    control.verify();
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) Policy(org.apache.neethi.Policy) Test(org.junit.Test)

Example 89 with Policy

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

the class CustomPolicyAlgorithmsTest method testSHA256AsymSigAlgorithm.

@Test
public void testSHA256AsymSigAlgorithm() throws Exception {
    final String rsaSha2SigMethod = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
    String policyName = "signed_elements_policy.xml";
    Policy policy = policyBuilder.getPolicy(this.getResourceAsStream(policyName));
    AssertionInfoMap aim = new AssertionInfoMap(policy);
    AssertionInfo assertInfo = aim.get(SP12Constants.ASYMMETRIC_BINDING).iterator().next();
    AsymmetricBinding binding = (AsymmetricBinding) assertInfo.getAssertion();
    // set Signature Algorithm to RSA SHA-256
    binding.getAlgorithmSuite().setAsymmetricSignature(rsaSha2SigMethod);
    String sigMethod = binding.getAlgorithmSuite().getAsymmetricSignature();
    assertNotNull(sigMethod);
    assertEquals(rsaSha2SigMethod, sigMethod);
}
Also used : Policy(org.apache.neethi.Policy) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) AsymmetricBinding(org.apache.wss4j.policy.model.AsymmetricBinding) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap) Test(org.junit.Test)

Example 90 with Policy

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

the class PluggablePolicyValidatorTest method runInInterceptorAndValidate.

private void runInInterceptorAndValidate(String document, String policyDocument, List<QName> assertedInAssertions, List<QName> notAssertedInAssertions, List<CoverageType> types, Map<QName, SecurityPolicyValidator> validators) throws Exception {
    final Policy policy = this.policyBuilder.getPolicy(this.readDocument(policyDocument).getDocumentElement());
    final Document doc = this.readDocument(document);
    final AssertionInfoMap aim = new AssertionInfoMap(policy);
    this.runInInterceptorAndValidateWss(doc, aim, types, validators);
    try {
        aim.checkEffectivePolicy(policy);
    } catch (PolicyException e) {
    // Expected but not relevant
    } finally {
        if (assertedInAssertions != null) {
            for (QName assertionType : assertedInAssertions) {
                Collection<AssertionInfo> ais = aim.get(assertionType);
                assertNotNull(ais);
                for (AssertionInfo ai : ais) {
                    checkAssertion(aim, assertionType, ai, true);
                }
            }
        }
        if (notAssertedInAssertions != null) {
            for (QName assertionType : notAssertedInAssertions) {
                Collection<AssertionInfo> ais = aim.get(assertionType);
                assertNotNull(ais);
                for (AssertionInfo ai : ais) {
                    checkAssertion(aim, assertionType, ai, false);
                }
            }
        }
    }
}
Also used : Policy(org.apache.neethi.Policy) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) PolicyException(org.apache.cxf.ws.policy.PolicyException) QName(javax.xml.namespace.QName) Document(org.w3c.dom.Document) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Aggregations

Policy (org.apache.neethi.Policy)122 Test (org.junit.Test)47 Assertion (org.apache.neethi.Assertion)27 QName (javax.xml.namespace.QName)23 ArrayList (java.util.ArrayList)21 All (org.apache.neethi.All)18 ExactlyOne (org.apache.neethi.ExactlyOne)18 Message (org.apache.cxf.message.Message)15 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)14 Element (org.w3c.dom.Element)13 Bus (org.apache.cxf.Bus)12 PrimitiveAssertion (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion)12 List (java.util.List)9 Interceptor (org.apache.cxf.interceptor.Interceptor)9 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)9 HashMap (java.util.HashMap)7 OMElement (org.apache.axiom.om.OMElement)7 MessageImpl (org.apache.cxf.message.MessageImpl)7 ReferenceResolver (org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver)6 InputStream (java.io.InputStream)5