SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
samlCallback.setIssuer("www.example.com");
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
samlAssertion.signAssertion("wss40_server", "security", issuerCrypto, false);
WSSecSignatureSAML wsSign = new WSSecSignatureSAML();
wsSign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
wsSign.setUserInfo("wss40", "security");
Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
WSSecHeader secHeader = new WSSecHeader();
secHeader.insertSecurityHeader(doc);
List<WSEncryptionPart> parts = new ArrayList<WSEncryptionPart>();
WSEncryptionPart encP =
new WSEncryptionPart("STRTransform", "", "Element");
parts.add(encP);
wsSign.setParts(parts);
//
// set up for keyHolder
//
Document signedDoc = wsSign.build(doc, userCrypto, samlAssertion, null, null, null, secHeader);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed SAML message (key holder):");
String outputString =
XMLUtils.PrettyDocumentToString(signedDoc);
LOG.debug(outputString);
}
// Construct trust crypto instance
Crypto trustCrypto = new Merlin();
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
input = Merlin.loadInputStream(loader, "keys/wss40CA.jks");
trustStore.load(input, "security".toCharArray());
((Merlin)trustCrypto).setTrustStore(trustStore);
List<WSSecurityEngineResult> results =
secEngine.processSecurityHeader(doc, null, null, trustCrypto);
WSSecurityEngineResult stUnsignedActionResult =
WSSecurityUtil.fetchActionResult(results, WSConstants.ST_SIGNED);
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) stUnsignedActionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertTrue(receivedSamlAssertion.isSigned());
WSSecurityEngineResult signActionResult =
WSSecurityUtil.fetchActionResult(results, WSConstants.SIGN);
assertTrue(signActionResult != null);
assertFalse(signActionResult.isEmpty());