encContent = true;
encContentparser = new EncryptedContentHeaderParser(reader, parentNS, context);
ed = encContentparser.getEncryptedData();
} else {
throw new XWSSecurityException("Wrong Encrypted SOAP Header");
}
if (ed != null) {
context.setEdIdforEh(ed.getId());
}
//for policy verification
if (!encContent) {
if (ek != null) {
if (ek.getPolicy() != null) {
ek.getPolicy().setKeyBinding(ek.getInferredKB());
}
decryptedData = ed.getDecryptedData(ek.getKey(ed.getEncryptionAlgorithm()));
} else if (rlh != null) {
rlh.getPolicy().setKeyBinding(ed.getInferredKB());
decryptedData = ed.getDecryptedData();
} else {
throw new XWSSecurityException("Internal Error: Both EncryptedKey and ReferenceList set to null");
}
//
if (decryptedData.getEventType() == XMLStreamReader.START_DOCUMENT) {
decryptedData.next();
}
if (decryptedData.getEventType() != XMLStreamReader.START_ELEMENT) {
StreamUtil.moveToNextElement(decryptedData);
}
} else {
if (ek != null) {
if (ek.getPolicy() != null) {
ek.getPolicy().setKeyBinding(ek.getInferredKB());
}
decryptedIS = ed.getCipherInputStream(ek.getKey(ed.getEncryptionAlgorithm()));
} else if (rlh != null) {
rlh.getPolicy().setKeyBinding(ed.getInferredKB());
decryptedIS = ed.getCipherInputStream();
}
}
GenericSecuredHeader gsh = null;
if (!encContent) {
Map<String, String> headerBlockNamespaces = parentNS;
// Collect namespaces on SOAP header block
if (decryptedData.getNamespaceCount() > 0) {
headerBlockNamespaces = new HashMap<String, String>(parentNS);
for (int k = 0; k < decryptedData.getNamespaceCount(); k++) {
headerBlockNamespaces.put(decryptedData.getNamespacePrefix(k), decryptedData.getNamespaceURI(k));
}
}
// Mark
//XMLStreamBuffer mark = new XMLStreamBufferMark(headerBlockNamespaces, creator);
gsh = new GenericSecuredHeader(decryptedData, soapVersion, creator, (HashMap) headerBlockNamespaces, staxIF, context.getEncHeaderContent());
} else {
XMLStreamReader decryptedHeader = encContentparser.getDecryptedElement(decryptedIS);
if (decryptedHeader.getEventType() == XMLStreamReader.START_DOCUMENT) {
decryptedHeader.next();
}
if (decryptedHeader.getEventType() != XMLStreamReader.START_ELEMENT) {
StreamUtil.moveToNextElement(decryptedHeader);
}
Map<String, String> headerBlockNamespaces = parentNS;
// Collect namespaces on SOAP header block
if (decryptedHeader.getNamespaceCount() > 0) {
headerBlockNamespaces = new HashMap<String, String>(parentNS);
for (int k = 0; k < decryptedHeader.getNamespaceCount(); k++) {
String prefix = decryptedHeader.getNamespacePrefix(k);
if (prefix == null) {
prefix = "";
}
headerBlockNamespaces.put(prefix, decryptedHeader.getNamespaceURI(k));
}
}
gsh = new GenericSecuredHeader(decryptedHeader, soapVersion, creator, (HashMap) headerBlockNamespaces, staxIF, context.getEncHeaderContent());
}
QName gshQName = new QName(gsh.getNamespaceURI(), gsh.getLocalPart());
if (eh != null) {
encQNames.put(eh.getId(), gshQName);
edAlgos.put(eh.getId(), ed.getEncryptionAlgorithm());
} else {
encQNames.put(ed.getId(), gshQName);
edAlgos.put(ed.getId(), ed.getEncryptionAlgorithm());
}
return gsh;
} catch (XMLStreamException ex) {
logger.log(Level.SEVERE, LogStringsMessages.WSS_1615_ERROR_DECRYPTING_ENCRYPTED_DATA(), ex);
throw new XWSSecurityException("Error occurred while decrypting EncryptedData ", ex);
} catch (XMLStreamBufferException ex) {
logger.log(Level.SEVERE, LogStringsMessages.WSS_1615_ERROR_DECRYPTING_ENCRYPTED_DATA(), ex);
throw new XWSSecurityException("Error occurred while decrypting EncryptedData", ex);
}
}