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