*/
@SuppressWarnings("unchecked")
@org.junit.Test
public void testSOAPHeaderSTRTransform() throws Exception {
// Construct issuer and user crypto instances
Crypto issuerCrypto = new Merlin();
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
ClassLoader loader = Loader.getClassLoader(SignedSamlTokenHOKTest.class);
InputStream input = Merlin.loadInputStream(loader, "keys/wss40_server.jks");
keyStore.load(input, "security".toCharArray());
((Merlin)issuerCrypto).setKeyStore(keyStore);
Crypto userCrypto = CryptoFactory.getInstance("wss40.properties");
SAML1CallbackHandler callbackHandler = new SAML1CallbackHandler();
callbackHandler.setStatement(SAML1CallbackHandler.Statement.AUTHN);
callbackHandler.setConfirmationMethod(SAML1Constants.CONF_HOLDER_KEY);
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);