use of org.apache.cxf.ws.policy.AssertionInfoMap in project cxf by apache.
the class MAPAggregatorImpl method assertAddressing.
/**
* Asserts all Addressing assertions for the current message, regardless their nested
* Policies.
* @param message the current message
*/
private void assertAddressing(Message message, EndpointReferenceType replyTo, EndpointReferenceType faultTo) {
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
if (null == aim) {
return;
}
if (faultTo == null) {
faultTo = replyTo;
}
boolean anonReply = ContextUtils.isGenericAddress(replyTo);
boolean anonFault = ContextUtils.isGenericAddress(faultTo);
boolean onlyAnonymous = anonReply && anonFault;
boolean hasAnonymous = anonReply || anonFault;
QName[] types = new QName[] { MetadataConstants.ADDRESSING_ASSERTION_QNAME, MetadataConstants.USING_ADDRESSING_2004_QNAME, MetadataConstants.USING_ADDRESSING_2005_QNAME, MetadataConstants.USING_ADDRESSING_2006_QNAME };
for (QName type : types) {
assertAssertion(aim, type);
// ADDRESSING_ASSERTION is normalized, so check only the default namespace
if (type.equals(MetadataConstants.ADDRESSING_ASSERTION_QNAME)) {
if (onlyAnonymous) {
assertAssertion(aim, MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME);
} else if (!hasAnonymous) {
assertAssertion(aim, MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME);
}
}
}
if (!MessageUtils.isRequestor(message) && !MessageUtils.isOutbound(message)) {
// need to throw an appropriate fault for these
Collection<AssertionInfo> aicNonAnon = aim.getAssertionInfo(MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME);
Collection<AssertionInfo> aicNonAnon2 = aim.getAssertionInfo(MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME_0705);
Collection<AssertionInfo> aicAnon = aim.getAssertionInfo(MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME);
Collection<AssertionInfo> aicAnon2 = aim.getAssertionInfo(MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME_0705);
boolean hasAnon = (aicAnon != null && !aicAnon.isEmpty()) || (aicAnon2 != null && !aicAnon2.isEmpty());
boolean hasNonAnon = (aicNonAnon != null && !aicNonAnon.isEmpty()) || (aicNonAnon2 != null && !aicNonAnon2.isEmpty());
if (hasAnonymous && hasNonAnon && !hasAnon) {
message.put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
if (isSOAP12(message)) {
SoapFault soap12Fault = new SoapFault("Found anonymous address but non-anonymous required", Soap12.getInstance().getSender());
soap12Fault.addSubCode(new QName(Names.WSA_NAMESPACE_NAME, "OnlyNonAnonymousAddressSupported"));
throw soap12Fault;
}
throw new SoapFault("Found anonymous address but non-anonymous required", new QName(Names.WSA_NAMESPACE_NAME, "OnlyNonAnonymousAddressSupported"));
} else if (!onlyAnonymous && !hasNonAnon && hasAnon) {
message.put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
if (isSOAP12(message)) {
SoapFault soap12Fault = new SoapFault("Found non-anonymous address but only anonymous supported", Soap12.getInstance().getSender());
soap12Fault.addSubCode(new QName(Names.WSA_NAMESPACE_NAME, "OnlyAnonymousAddressSupported"));
throw soap12Fault;
}
throw new SoapFault("Found non-anonymous address but only anonymous supported", new QName(Names.WSA_NAMESPACE_NAME, "OnlyAnonymousAddressSupported"));
}
}
}
use of org.apache.cxf.ws.policy.AssertionInfoMap in project cxf by apache.
the class MAPAggregatorImpl method handleMessage.
/**
* Invoked for normal processing of inbound and outbound messages.
*
* @param message the current message
*/
public void handleMessage(Message message) {
if (!MessageUtils.getContextualBoolean(message, ADDRESSING_DISABLED, false)) {
mediate(message, ContextUtils.isFault(message));
} else {
// addressing is completely disabled manually, we need to assert the
// assertions as the user is in control of those
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
if (null == aim) {
return;
}
QName[] types = new QName[] { MetadataConstants.ADDRESSING_ASSERTION_QNAME, MetadataConstants.USING_ADDRESSING_2004_QNAME, MetadataConstants.USING_ADDRESSING_2005_QNAME, MetadataConstants.USING_ADDRESSING_2006_QNAME, MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME, MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME, MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME_0705, MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME_0705 };
for (QName type : types) {
assertAssertion(aim, type);
}
}
}
use of org.apache.cxf.ws.policy.AssertionInfoMap 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);
}
}
}
}
}
use of org.apache.cxf.ws.policy.AssertionInfoMap in project cxf by apache.
the class SecurityVerificationOutTest method coachMessage.
private SoapMessage coachMessage(String policyName) throws IOException, ParserConfigurationException, SAXException {
Policy policy = policyBuilder.getPolicy(this.getResourceAsStream(policyName));
AssertionInfoMap aim = new AssertionInfoMap(policy);
SoapMessage message = control.createMock(SoapMessage.class);
EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
return message;
}
use of org.apache.cxf.ws.policy.AssertionInfoMap in project cxf by apache.
the class AbstractPolicySecurityTest method runInInterceptorAndValidate.
protected void runInInterceptorAndValidate(Document document, Policy policy, List<QName> assertedInAssertions, List<QName> notAssertedInAssertions, List<CoverageType> types) throws Exception {
final AssertionInfoMap aim = new AssertionInfoMap(policy);
this.runInInterceptorAndValidateWss(document, aim, types);
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