@SuppressWarnings("unchecked")
public boolean doReceiver(Map<String, Object> mc, RequestData reqData, boolean isRequest)
throws WSSecurityException {
String action = (String) mc.get(WSHandlerConstants.ACTION);
if (action == null) {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty", "WSS4JHandler: No action defined");
}
List<Integer> actions = WSSecurityUtil.decodeAction(action);
String actor = (String) mc.get(WSHandlerConstants.ACTOR);
Document doc = (Document) mc.get(SECURED_DOCUMENT);
/*
* Check if it's a fault. Don't process faults.
*/
org.apache.wss4j.dom.SOAPConstants soapConstants =
WSSecurityUtil.getSOAPConstants(doc.getDocumentElement());
if (WSSecurityUtil.findElement(
doc.getDocumentElement(), "Fault", soapConstants.getEnvelopeURI()) != null
) {
return false;
}
/*
* To check a UsernameToken or to decrypt an encrypted message we need
* a password.
*/
CallbackHandler cbHandler = getPasswordCallbackHandler(reqData);
reqData.setCallbackHandler(cbHandler);
/*
* Get and check the Signature specific parameters first because they
* may be used for encryption too.
*/
doReceiverAction(actions, reqData);
Element elem = WSSecurityUtil.getSecurityHeader(doc, actor);
List<WSSecurityEngineResult> wsResult = null;
try {
wsResult = secEngine.processSecurityHeader(elem, reqData);
} catch (WSSecurityException ex) {
if (doDebug) {
log.debug(ex.getMessage(), ex);
}
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty",
"WSS4JHandler: security processing failed", ex
);
}
if (wsResult == null || wsResult.size() == 0) {
// no security header found
if (actions.isEmpty()) {
return true;
} else {
throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY, "empty",
"WSS4JHandler: Request does not contain required Security header"
);
}
}
if (reqData.getWssConfig().isEnableSignatureConfirmation() && !isRequest) {
checkSignatureConfirmation(reqData, wsResult);
}
if (doDebug) {
log.debug("Processed received SOAP request");
}
/*
* now check the security actions: do they match, in right order?
*/
if (!checkReceiverResults(wsResult, actions)) {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty",
"WSS4JHandler: security processing failed (actions mismatch)"
);
}
/*