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));
}
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);
}
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();
}
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);
}
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);
}
}
}
}
}
Aggregations