in shared-libraries/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/security/WSSecurityHandler.java [263:356]
public void onReceive(Context context) throws Exception {
RequestData reqData = new RequestData();
init(context);
try {
reqData.setNoSerialization(true);
reqData.setMsgContext(context);
Vector actions = new Vector();
String action = this.receiveAction;
if (action == null) {
throw new IllegalStateException("WSSecurityHandler: No receiveAction defined");
}
int doAction = WSSecurityUtil.decodeAction(action, actions);
Document doc = context.getInMessage().getDocument();
if (doc == null) {
throw new IllegalStateException("WSSecurityHandler: The soap message has not been parsed using DOM");
}
/*
* Get and check the Signature specific parameters first because
* they may be used for encryption too.
*/
doReceiverAction(doAction, reqData);
List wsResult = null;
try {
wsResult = secEngine.processSecurityHeader(
doc, actor, handler,
reqData.getSigCrypto(),
reqData.getDecCrypto());
} catch (WSSecurityException ex) {
throw new SoapFault(ex);
}
if (wsResult == null) { // no security header found
if (doAction == WSConstants.NO_SECURITY) {
return;
} else {
throw new SoapFault(new WSSecurityException(
"WSSecurityHandler: Request does not contain required Security header"));
}
}
if (reqData.getWssConfig().isEnableSignatureConfirmation()) {
checkSignatureConfirmation(reqData, wsResult);
}
/*
* now check the security actions: do they match, in right order?
*/
if (!checkReceiverResults(wsResult, actions)) {
throw new SoapFault(new WSSecurityException(
"WSSecurityHandler: security processing failed (actions mismatch)"));
}
/*
* All ok up to this point. Now construct and setup the security
* result structure. The service may fetch this and check it.
*/
Vector results = null;
if ((results = (Vector) context.getProperty(WSHandlerConstants.RECV_RESULTS)) == null) {
results = new Vector();
context.setProperty(WSHandlerConstants.RECV_RESULTS, results);
}
WSHandlerResult rResult = new WSHandlerResult(actor, wsResult);
results.add(0, rResult);
// Add principals to the message
for (Iterator iter = results.iterator(); iter.hasNext();) {
WSHandlerResult hr = (WSHandlerResult) iter.next();
for (Iterator it = hr.getResults().iterator(); it.hasNext();) {
WSSecurityEngineResult er = (WSSecurityEngineResult) it.next();
if (er.get(WSSecurityEngineResult.TAG_PRINCIPAL) != null) {
context.getInMessage().addPrincipal((Principal)er.get(WSSecurityEngineResult.TAG_PRINCIPAL));
}
}
}
Subject s = (Subject) currentSubject.get();
if (s != null) {
for (Iterator iterator = s.getPrincipals().iterator(); iterator.hasNext();) {
Principal p = (Principal) iterator.next();
context.getInMessage().addPrincipal(p);
}
}
} finally {
reqData.clear();
currentSubject.set(null);
currentHandler.set(null);
}
}