boolean eventHandled = false;
switch (xmlSecEvent.getEventType()) {
case XMLStreamConstants.START_ELEMENT:
XMLSecStartElement xmlSecStartElement = xmlSecEvent.asStartElement();
final String soapMessageVersion = WSSUtils.getSOAPMessageVersionNamespace(xmlSecStartElement);
int level = xmlSecStartElement.getDocumentLevel();
if (level == 1 && soapMessageVersion == null) {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "notASOAPMessage");
} else if (level == 1) {
//set correct namespace on secure parts
List<SecurePart> encryptionParts = securityProperties.getEncryptionSecureParts();
if (encryptionParts.isEmpty()) {
SecurePart securePart = new SecurePart(
new QName(soapMessageVersion, WSSConstants.TAG_soap_Body_LocalName),
SecurePart.Modifier.Content);
outputProcessorChain.getSecurityContext().putAsMap(
WSSConstants.ENCRYPTION_PARTS,
securePart.getName(), securePart
);
} else {
for (int i = 0; i < encryptionParts.size(); i++) {
SecurePart securePart = encryptionParts.get(i);
// Check to see if the wrong SOAP NS was used
SecurePart convertedPart = convertSecurePart(securePart, soapMessageVersion);
if (securePart != convertedPart) {
securePart = convertedPart;
encryptionParts.set(i, securePart);
}
if (securePart.getIdToSign() == null) {
outputProcessorChain.getSecurityContext().putAsMap(
WSSConstants.ENCRYPTION_PARTS,
securePart.getName(),
securePart
);
} else {
outputProcessorChain.getSecurityContext().putAsMap(
WSSConstants.ENCRYPTION_PARTS,
securePart.getIdToSign(),
securePart
);
}
}
}
List<SecurePart> signatureParts = securityProperties.getSignatureSecureParts();
if (signatureParts.isEmpty()) {
SecurePart securePart = new SecurePart(
new QName(soapMessageVersion, WSSConstants.TAG_soap_Body_LocalName),
SecurePart.Modifier.Element);
outputProcessorChain.getSecurityContext().putAsMap(
WSSConstants.SIGNATURE_PARTS,
securePart.getName(), securePart
);
} else {
for (int i = 0; i < signatureParts.size(); i++) {
SecurePart securePart = signatureParts.get(i);
// Check to see if the wrong SOAP NS was used
SecurePart convertedPart = convertSecurePart(securePart, soapMessageVersion);
if (securePart != convertedPart) {
securePart = convertedPart;
signatureParts.set(i, securePart);
}
if (securePart.getIdToSign() == null) {
outputProcessorChain.getSecurityContext().putAsMap(
WSSConstants.SIGNATURE_PARTS,
securePart.getName(),
securePart
);
} else {
outputProcessorChain.getSecurityContext().putAsMap(
WSSConstants.SIGNATURE_PARTS,
securePart.getIdToSign(),
securePart
);
}
}
}
} else if (WSSUtils.isSecurityHeaderElement(xmlSecEvent, ((WSSSecurityProperties) getSecurityProperties()).getActor())) {
//remove this processor. its no longer needed.
outputProcessorChain.removeProcessor(this);
} else if (level == 2
&& WSSConstants.TAG_soap_Body_LocalName.equals(xmlSecStartElement.getName().getLocalPart())
&& xmlSecStartElement.getName().getNamespaceURI().equals(soapMessageVersion)) {
//hmm it seems we don't have a soap header in the current document
//so output one and add securityHeader
//create subchain and output soap-header and securityHeader
OutputProcessorChain subOutputProcessorChain = outputProcessorChain.createSubChain(this, xmlSecStartElement.getParentXMLSecStartElement());
createStartElementAndOutputAsEvent(subOutputProcessorChain,
new QName(soapMessageVersion, WSSConstants.TAG_soap_Header_LocalName, WSSConstants.PREFIX_SOAPENV), true, null);
boolean mustUnderstand = ((WSSSecurityProperties) getSecurityProperties()).isMustUnderstand();
buildSecurityHeader(soapMessageVersion, subOutputProcessorChain, mustUnderstand);
createEndElementAndOutputAsEvent(subOutputProcessorChain,