}
@Override
public boolean assertEvent(SecurityEvent securityEvent) throws WSSPolicyException {
SignedPartSecurityEvent signedPartSecurityEvent = (SignedPartSecurityEvent) securityEvent;
SignedParts signedParts = (SignedParts) getAssertion();
if (signedParts.getAttachments() != null) {
signedAttachmentRequired = true;
if (signedPartSecurityEvent.isAttachment()) {
signedAttachmentCount++;
setAsserted(true);
policyAsserter.assertPolicy(getAssertion());
return true;
}
}
if (signedParts.isBody()
&& WSSUtils.pathMatches(WSSConstants.SOAP_11_BODY_PATH, signedPartSecurityEvent.getElementPath(), true, false)) {
if (signedPartSecurityEvent.isSigned()) {
setAsserted(true);
policyAsserter.assertPolicy(getAssertion());
return true;
} else {
setAsserted(false);
setErrorMessage("Element " + WSSUtils.pathAsString(signedPartSecurityEvent.getElementPath()) + " must be signed");
policyAsserter.unassertPolicy(getAssertion(), getErrorMessage());
return false;
}
}
//body processed above. so this must be a header element
if (signedParts.isSignAllHeaders()) {
if (signedPartSecurityEvent.isSigned()) {
setAsserted(true);
policyAsserter.assertPolicy(getAssertion());
return true;
} else {
setAsserted(false);
setErrorMessage("Element " + WSSUtils.pathAsString(signedPartSecurityEvent.getElementPath()) + " must be signed");
policyAsserter.unassertPolicy(getAssertion(), getErrorMessage());
return false;
}
} else {
for (int i = 0; i < signedParts.getHeaders().size(); i++) {
Header header = signedParts.getHeaders().get(i);
QName headerQName = new QName(header.getNamespace(), header.getName() == null ? "" : header.getName());
List<QName> header11Path = new LinkedList<QName>();
header11Path.addAll(WSSConstants.SOAP_11_HEADER_PATH);
header11Path.add(headerQName);
if (WSSUtils.pathMatches(header11Path, signedPartSecurityEvent.getElementPath(), true, header.getName() == null)) {
if (signedPartSecurityEvent.isSigned()) {
setAsserted(true);
policyAsserter.assertPolicy(getAssertion());
return true;
} else {
setAsserted(false);
setErrorMessage("Element " + WSSUtils.pathAsString(signedPartSecurityEvent.getElementPath()) + " must be signed");
policyAsserter.unassertPolicy(getAssertion(), getErrorMessage());
return false;
}
}
}