You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2016/11/25 12:30:30 UTC
svn commit: r1771305 [1/2] - in /webservices/wss4j/trunk/ws-security-dom/src:
main/java/org/apache/wss4j/dom/message/
test/java/org/apache/wss4j/dom/message/
Author: coheigea
Date: Fri Nov 25 12:30:30 2016
New Revision: 1771305
URL: http://svn.apache.org/viewvc?rev=1771305&view=rev
Log:
More refactoring
Modified:
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecHeader.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SKISignatureTest.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/STRSignatureTest.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureAlgorithmSuiteTest.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureCertTest.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureEncryptionTest.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureIssuerCertConstraintsTest.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignaturePartsTest.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureTest.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/TimestampTest.java
webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/UTDerivedKeyTest.java
Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecHeader.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecHeader.java?rev=1771305&r1=1771304&r2=1771305&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecHeader.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecHeader.java Fri Nov 25 12:30:30 2016
@@ -101,6 +101,10 @@ public class WSSecHeader {
public Element getSecurityHeaderElement() {
return securityHeader;
}
+
+ public void setSecurityHeaderElement(Element securityHeaderElement) {
+ this.securityHeader = securityHeaderElement;
+ }
/**
* Returns whether the security header is empty
Modified: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SKISignatureTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SKISignatureTest.java?rev=1771305&r1=1771304&r2=1771305&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SKISignatureTest.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SKISignatureTest.java Fri Nov 25 12:30:30 2016
@@ -62,18 +62,18 @@ public class SKISignatureTest extends or
*/
@Test
public void testX509SignatureDSA_SKI() throws Exception {
- WSSecSignature builder = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
builder.setUserInfo("wss40DSA", "security");
builder.setKeyIdentifierType(WSConstants.SKI_KEY_IDENTIFIER);
builder.setSignatureAlgorithm(WSConstants.DSA);
LOG.info("Before SigningDSA_SKIDirect....");
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
-
- Document signedDoc = builder.build(doc, crypto, secHeader);
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed message with DSA_SKI key identifier:");
@@ -106,17 +106,17 @@ public class SKISignatureTest extends or
*/
@Test
public void testX509SignatureDSA_Autodetect() throws Exception {
- WSSecSignature builder = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
builder.setUserInfo("wss40DSA", "security");
builder.setKeyIdentifierType(WSConstants.SKI_KEY_IDENTIFIER);
LOG.info("Before SigningDSA_Autodetect....");
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
-
- Document signedDoc = builder.build(doc, crypto, secHeader);
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed message with DSA_Autodetect:");
@@ -140,17 +140,17 @@ public class SKISignatureTest extends or
*/
@Test
public void testX509SignatureRSA_Autodetect() throws Exception {
- WSSecSignature builder = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
builder.setUserInfo("wss40", "security");
builder.setKeyIdentifierType(WSConstants.SKI_KEY_IDENTIFIER);
LOG.info("Before SigningRSA_Autodetect....");
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
-
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed message with RSA Autodetect:");
Modified: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/STRSignatureTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/STRSignatureTest.java?rev=1771305&r1=1771304&r2=1771305&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/STRSignatureTest.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/STRSignatureTest.java Fri Nov 25 12:30:30 2016
@@ -64,10 +64,13 @@ public class STRSignatureTest extends or
*/
@Test
public void testX509SignatureDirectSTR() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setUserInfo("wss40", "security");
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(doc.getDocumentElement());
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setUserInfo("wss40", "security");
//
// Set up to sign body and use STRTransform to sign
@@ -90,10 +93,7 @@ public class STRSignatureTest extends or
LOG.info("Before Signing STR DirectReference....");
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
-
- Document signedDoc = builder.build(doc, crypto, secHeader);
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed message with STR DirectReference key identifier:");
@@ -112,13 +112,13 @@ public class STRSignatureTest extends or
*/
@Test
public void testWSS96() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setUserInfo("wss40", "security");
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(doc.getDocumentElement());
-
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setUserInfo("wss40", "security");
//
// Set up to sign body and use STRTransform to sign
@@ -137,15 +137,15 @@ public class STRSignatureTest extends or
"Content");
builder.getParts().add(encP);
- WSSecTimestamp timestamp = new WSSecTimestamp();
+ WSSecTimestamp timestamp = new WSSecTimestamp(secHeader);
timestamp.setTimeToLive(600);
- timestamp.build(doc, secHeader);
+ timestamp.build(doc);
builder.getParts().add(new WSEncryptionPart(timestamp.getId()));
builder.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
LOG.info("Before Signing STR DirectReference....");
- Document signedDoc = builder.build(doc, crypto, secHeader);
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed message with STR DirectReference key identifier:");
@@ -169,11 +169,13 @@ public class STRSignatureTest extends or
*/
@Test
public void testX509SignatureISSTR() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setUserInfo("wss40", "security");
-
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(doc.getDocumentElement());
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setUserInfo("wss40", "security");
//
// Set up to sign body and use STRTransform to sign
@@ -196,10 +198,7 @@ public class STRSignatureTest extends or
LOG.info("Before Signing STR IS....");
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
-
- Document signedDoc = builder.build(doc, crypto, secHeader);
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed message with STR IssuerSerial key identifier:");
@@ -222,10 +221,13 @@ public class STRSignatureTest extends or
*/
@Test
public void testX509SignatureSKISTR() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setUserInfo("wss40", "security");
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(doc.getDocumentElement());
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setUserInfo("wss40", "security");
//
// Set up to sign body and use STRTransform to sign
@@ -248,10 +250,7 @@ public class STRSignatureTest extends or
LOG.info("Before Signing STR SKI....");
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
-
- Document signedDoc = builder.build(doc, crypto, secHeader);
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed message with STR SKI key identifier:");
Modified: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureAlgorithmSuiteTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureAlgorithmSuiteTest.java?rev=1771305&r1=1771304&r2=1771305&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureAlgorithmSuiteTest.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureAlgorithmSuiteTest.java Fri Nov 25 12:30:30 2016
@@ -70,15 +70,16 @@ public class SignatureAlgorithmSuiteTest
@Test
public void testSignature() throws Exception {
- WSSecSignature builder = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
builder.setSignatureAlgorithm(WSConstants.RSA_SHA1);
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -104,16 +105,17 @@ public class SignatureAlgorithmSuiteTest
@Test
public void testSignatureMethodDSA() throws Exception {
Crypto dsaCrypto = CryptoFactory.getInstance("wss40.properties");
+
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
- WSSecSignature builder = new WSSecSignature();
+ WSSecSignature builder = new WSSecSignature(secHeader);
builder.setUserInfo("wss40DSA", "security");
builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
builder.setSignatureAlgorithm(WSConstants.DSA);
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, dsaCrypto, secHeader);
+ Document signedDoc = builder.build(doc, dsaCrypto);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -142,16 +144,17 @@ public class SignatureAlgorithmSuiteTest
keyGen.init(128);
SecretKey key = keyGen.generateKey();
byte[] keyData = key.getEncoded();
+
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
- WSSecSignature builder = new WSSecSignature();
+ WSSecSignature builder = new WSSecSignature(secHeader);
builder.setKeyIdentifierType(WSConstants.ENCRYPTED_KEY_SHA1_IDENTIFIER);
builder.setSecretKey(keyData);
builder.setSignatureAlgorithm(SignatureMethod.HMAC_SHA1);
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -205,16 +208,17 @@ public class SignatureAlgorithmSuiteTest
@Test
public void testC14nMethod() throws Exception {
- WSSecSignature builder = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
builder.setSignatureAlgorithm(WSConstants.RSA_SHA1);
builder.setSigCanonicalization(WSConstants.C14N_EXCL_WITH_COMMENTS);
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -238,16 +242,17 @@ public class SignatureAlgorithmSuiteTest
@Test
public void testDigestMethod() throws Exception {
- WSSecSignature builder = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
builder.setSignatureAlgorithm(WSConstants.RSA_SHA1);
builder.setDigestAlgo(WSConstants.SHA256);
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
String outputString =
Modified: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureCertTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureCertTest.java?rev=1771305&r1=1771304&r2=1771305&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureCertTest.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureCertTest.java Fri Nov 25 12:30:30 2016
@@ -93,15 +93,15 @@ public class SignatureCertTest extends o
*/
@Test
public void testSignatureDirectReference() throws Exception {
- WSSecSignature sign = new WSSecSignature();
- sign.setUserInfo("wss40", "security");
- sign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
-
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
-
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- Document signedDoc = sign.build(doc, crypto, secHeader);
+
+ WSSecSignature sign = new WSSecSignature(secHeader);
+ sign.setUserInfo("wss40", "security");
+ sign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
+
+ Document signedDoc = sign.build(doc, crypto);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -123,6 +123,10 @@ public class SignatureCertTest extends o
@Test
@org.junit.Ignore
public void testBSTCertChain() throws Exception {
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
//
// This test fails with the IBM JDK
//
@@ -130,16 +134,12 @@ public class SignatureCertTest extends o
return;
}
Crypto clientCrypto = CryptoFactory.getInstance("wss40_client.properties");
- WSSecSignature sign = new WSSecSignature();
+ WSSecSignature sign = new WSSecSignature(secHeader);
sign.setUserInfo("Client_CertChain", "password");
sign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
sign.setUseSingleCertificate(false);
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
-
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
- Document signedDoc = sign.build(doc, clientCrypto, secHeader);
+ Document signedDoc = sign.build(doc, clientCrypto);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -168,16 +168,16 @@ public class SignatureCertTest extends o
*/
@Test
public void testSignatureDirectReferenceCACert() throws Exception {
- WSSecSignature sign = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecSignature sign = new WSSecSignature(secHeader);
sign.setUserInfo("wss40", "security");
sign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
sign.setUseSingleCertificate(false);
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
-
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
- Document signedDoc = sign.build(doc, crypto, secHeader);
+ Document signedDoc = sign.build(doc, crypto);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -207,15 +207,15 @@ public class SignatureCertTest extends o
*/
@Test
public void testSignatureIssuerSerial() throws Exception {
- WSSecSignature sign = new WSSecSignature();
- sign.setUserInfo("wss40", "security");
- sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
-
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
-
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- Document signedDoc = sign.build(doc, crypto, secHeader);
+
+ WSSecSignature sign = new WSSecSignature(secHeader);
+ sign.setUserInfo("wss40", "security");
+ sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
+
+ Document signedDoc = sign.build(doc, crypto);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -238,16 +238,16 @@ public class SignatureCertTest extends o
*/
@Test
public void testSignatureBadCACert() throws Exception {
- WSSecSignature sign = new WSSecSignature();
- sign.setUserInfo("wss4jcertdsa", "security");
- sign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
-
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
-
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
+
+ WSSecSignature sign = new WSSecSignature(secHeader);
+ sign.setUserInfo("wss4jcertdsa", "security");
+ sign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
+
Document signedDoc =
- sign.build(doc, CryptoFactory.getInstance("wss40badca.properties"), secHeader);
+ sign.build(doc, CryptoFactory.getInstance("wss40badca.properties"));
if (LOG.isDebugEnabled()) {
String outputString =
@@ -316,16 +316,16 @@ public class SignatureCertTest extends o
clientProperties.put("org.apache.wss4j.crypto.merlin.keystore.file", "keys/wss40exp.jks");
Crypto clientCrypto = new Merlin(clientProperties, this.getClass().getClassLoader(), null);
+
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
- WSSecSignature sign = new WSSecSignature();
+ WSSecSignature sign = new WSSecSignature(secHeader);
sign.setUserInfo("wss40exp", "security");
sign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
-
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
- Document signedDoc = sign.build(doc, clientCrypto, secHeader);
+ Document signedDoc = sign.build(doc, clientCrypto);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -356,15 +356,15 @@ public class SignatureCertTest extends o
Crypto clientCrypto = new Merlin(clientProperties, this.getClass().getClassLoader(), null);
- WSSecSignature sign = new WSSecSignature();
- sign.setUserInfo("wss40exp", "security");
- sign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
-
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
-
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- Document signedDoc = sign.build(doc, clientCrypto, secHeader);
+
+ WSSecSignature sign = new WSSecSignature(secHeader);
+ sign.setUserInfo("wss40exp", "security");
+ sign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
+
+ Document signedDoc = sign.build(doc, clientCrypto);
if (LOG.isDebugEnabled()) {
String outputString =
Modified: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureEncryptionTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureEncryptionTest.java?rev=1771305&r1=1771304&r2=1771305&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureEncryptionTest.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureEncryptionTest.java Fri Nov 25 12:30:30 2016
@@ -100,17 +100,17 @@ public class SignatureEncryptionTest ext
*/
@Test
public void testEncryptionSigning() throws Exception {
- WSSecEncrypt encrypt = new WSSecEncrypt();
- WSSecSignature sign = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecEncrypt encrypt = new WSSecEncrypt(secHeader);
+ WSSecSignature sign = new WSSecSignature(secHeader);
encrypt.setUserInfo("wss40");
sign.setUserInfo("wss40", "security");
LOG.info("Before Encryption....");
- Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
-
- Document encryptedDoc = encrypt.build(doc, crypto, secHeader);
+ Document encryptedDoc = encrypt.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("After Encryption....");
@@ -119,7 +119,7 @@ public class SignatureEncryptionTest ext
LOG.debug(outputString);
}
- Document encryptedSignedDoc = sign.build(encryptedDoc, crypto, secHeader);
+ Document encryptedSignedDoc = sign.build(encryptedDoc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("After Signing....");
@@ -142,15 +142,15 @@ public class SignatureEncryptionTest ext
@SuppressWarnings("unchecked")
@Test
public void testEncryptionElementSigning() throws Exception {
- WSSecEncrypt encrypt = new WSSecEncrypt();
- WSSecSignature sign = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecEncrypt encrypt = new WSSecEncrypt(secHeader);
+ WSSecSignature sign = new WSSecSignature(secHeader);
encrypt.setUserInfo("wss40");
sign.setUserInfo("wss40", "security");
LOG.info("Before Encryption....");
- Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
-
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
WSEncryptionPart part =
new WSEncryptionPart(
@@ -159,7 +159,7 @@ public class SignatureEncryptionTest ext
"Element");
encrypt.getParts().add(part);
- Document encryptedDoc = encrypt.build(doc, crypto, secHeader);
+ Document encryptedDoc = encrypt.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("After Encryption....");
@@ -175,7 +175,7 @@ public class SignatureEncryptionTest ext
"Element");
sign.getParts().add(signPart);
- Document encryptedSignedDoc = sign.build(encryptedDoc, crypto, secHeader);
+ Document encryptedSignedDoc = sign.build(encryptedDoc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("After Signing....");
@@ -228,18 +228,18 @@ public class SignatureEncryptionTest ext
*/
@Test
public void testSigningEncryption() throws Exception {
- WSSecEncrypt encrypt = new WSSecEncrypt();
- WSSecSignature sign = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecEncrypt encrypt = new WSSecEncrypt(secHeader);
+ WSSecSignature sign = new WSSecSignature(secHeader);
encrypt.setUserInfo("wss40");
sign.setUserInfo("wss40", "security");
LOG.info("Before Encryption....");
- Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
-
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
- Document signedDoc = sign.build(doc, crypto, secHeader);
- Document encryptedSignedDoc = encrypt.build(signedDoc, crypto, secHeader);
+ Document signedDoc = sign.build(doc, crypto);
+ Document encryptedSignedDoc = encrypt.build(signedDoc, crypto);
LOG.info("After Encryption....");
verify(encryptedSignedDoc);
}
@@ -252,12 +252,15 @@ public class SignatureEncryptionTest ext
*/
@Test
public void testWSS198() throws Exception {
- WSSecEncrypt encrypt = new WSSecEncrypt();
- WSSecSignature sign = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecEncrypt encrypt = new WSSecEncrypt(secHeader);
+ WSSecSignature sign = new WSSecSignature(secHeader);
encrypt.setUserInfo("wss40");
sign.setUserInfo("wss40", "security");
LOG.info("Before Encryption....");
- Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
WSEncryptionPart encP =
new WSEncryptionPart(
@@ -266,11 +269,8 @@ public class SignatureEncryptionTest ext
"");
encrypt.getParts().add(encP);
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
-
- Document signedDoc = sign.build(doc, crypto, secHeader);
- Document encryptedSignedDoc = encrypt.build(signedDoc, crypto, secHeader);
+ Document signedDoc = sign.build(doc, crypto);
+ Document encryptedSignedDoc = encrypt.build(signedDoc, crypto);
LOG.info("WSS198");
if (LOG.isDebugEnabled()) {
String outputString =
@@ -291,23 +291,23 @@ public class SignatureEncryptionTest ext
*/
@Test
public void testSigningEncryptionIS3DES() throws Exception {
- WSSecEncrypt encrypt = new WSSecEncrypt();
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecEncrypt encrypt = new WSSecEncrypt(secHeader);
encrypt.setUserInfo("wss40");
encrypt.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
encrypt.setSymmetricEncAlgorithm(WSConstants.TRIPLE_DES);
- WSSecSignature sign = new WSSecSignature();
+ WSSecSignature sign = new WSSecSignature(secHeader);
sign.setUserInfo("wss40", "security");
sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
LOG.info("Before Sign/Encryption....");
- Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
-
- Document signedDoc = sign.build(doc, crypto, secHeader);
- Document encryptedSignedDoc = encrypt.build(signedDoc, crypto, secHeader);
+ Document signedDoc = sign.build(doc, crypto);
+ Document encryptedSignedDoc = encrypt.build(signedDoc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed and encrypted message with IssuerSerial key identifier (both), 3DES:");
String outputString =
@@ -333,28 +333,28 @@ public class SignatureEncryptionTest ext
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- WSSecEncryptedKey encrKey = new WSSecEncryptedKey();
+ WSSecEncryptedKey encrKey = new WSSecEncryptedKey(secHeader);
encrKey.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
encrKey.setUserInfo("wss40", "security");
encrKey.setSymmetricEncAlgorithm(WSConstants.AES_192);
encrKey.prepare(doc, crypto);
- WSSecEncrypt encrypt = new WSSecEncrypt();
+ WSSecEncrypt encrypt = new WSSecEncrypt(secHeader);
encrypt.setEncKeyId(encrKey.getId());
encrypt.setEphemeralKey(encrKey.getEphemeralKey());
encrypt.setSymmetricEncAlgorithm(WSConstants.TRIPLE_DES);
encrypt.setEncryptSymmKey(false);
encrypt.setEncryptedKeyElement(encrKey.getEncryptedKeyElement());
- WSSecSignature sign = new WSSecSignature();
+ WSSecSignature sign = new WSSecSignature(secHeader);
sign.setKeyIdentifierType(WSConstants.CUSTOM_SYMM_SIGNING);
sign.setCustomTokenId(encrKey.getId());
sign.setSecretKey(encrKey.getEphemeralKey());
sign.setCustomTokenValueType(WSConstants.WSS_ENC_KEY_VALUE_TYPE);
sign.setSignatureAlgorithm(SignatureMethod.HMAC_SHA1);
- Document signedDoc = sign.build(doc, crypto, secHeader);
- Document encryptedSignedDoc = encrypt.build(signedDoc, crypto, secHeader);
+ Document signedDoc = sign.build(doc, crypto);
+ Document encryptedSignedDoc = encrypt.build(signedDoc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed and encrypted message with IssuerSerial key identifier (both), 3DES:");
@@ -459,18 +459,18 @@ public class SignatureEncryptionTest ext
@Test
public void testSigningEncryptionSOAP12Fault() throws Exception {
- WSSecEncrypt encrypt = new WSSecEncrypt();
- WSSecSignature sign = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecEncrypt encrypt = new WSSecEncrypt(secHeader);
+ WSSecSignature sign = new WSSecSignature(secHeader);
encrypt.setUserInfo("wss40");
sign.setUserInfo("wss40", "security");
LOG.info("Before Encryption....");
- Document doc = SOAPUtil.toSOAPPart(SAMPLE_SOAP12_FAULT_MSG);
-
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
- Document signedDoc = sign.build(doc, crypto, secHeader);
- Document encryptedSignedDoc = encrypt.build(signedDoc, crypto, secHeader);
+ Document signedDoc = sign.build(doc, crypto);
+ Document encryptedSignedDoc = encrypt.build(signedDoc, crypto);
LOG.info("After Encryption....");
verify(encryptedSignedDoc);
Modified: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureIssuerCertConstraintsTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureIssuerCertConstraintsTest.java?rev=1771305&r1=1771304&r2=1771305&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureIssuerCertConstraintsTest.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureIssuerCertConstraintsTest.java Fri Nov 25 12:30:30 2016
@@ -65,14 +65,15 @@ public class SignatureIssuerCertConstrai
*/
@Test
public void testBSTSignature() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setUserInfo("wss40", "security");
- builder.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
-
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setUserInfo("wss40", "security");
+ builder.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
+
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed message with BST key identifier:");
@@ -99,15 +100,16 @@ public class SignatureIssuerCertConstrai
*/
@Test
public void testBSTSignaturePKIPath() throws Exception {
- WSSecSignature builder = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
builder.setUserInfo("wss40", "security");
builder.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
builder.setUseSingleCertificate(false);
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed message with BST key identifier:");
Modified: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignaturePartsTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignaturePartsTest.java?rev=1771305&r1=1771304&r2=1771305&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignaturePartsTest.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignaturePartsTest.java Fri Nov 25 12:30:30 2016
@@ -99,14 +99,13 @@ public class SignaturePartsTest extends
@SuppressWarnings("unchecked")
@Test
public void testSOAPHeader() throws Exception {
- WSSecSignature sign = new WSSecSignature();
- sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
-
Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
-
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
+
+ WSSecSignature sign = new WSSecSignature(secHeader);
+ sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
WSEncryptionPart encP =
new WSEncryptionPart(
@@ -115,7 +114,7 @@ public class SignaturePartsTest extends
"");
sign.getParts().add(encP);
- Document signedDoc = sign.build(doc, crypto, secHeader);
+ Document signedDoc = sign.build(doc, crypto);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -157,14 +156,13 @@ public class SignaturePartsTest extends
@Test
public void testOptionalSOAPHeaderPresent() throws Exception {
- WSSecSignature sign = new WSSecSignature();
- sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
-
Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
-
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
+
+ WSSecSignature sign = new WSSecSignature(secHeader);
+ sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
WSEncryptionPart encP =
new WSEncryptionPart(
@@ -182,7 +180,7 @@ public class SignaturePartsTest extends
);
sign.getParts().add(encP);
- Document signedDoc = sign.build(doc, crypto, secHeader);
+ Document signedDoc = sign.build(doc, crypto);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -195,14 +193,13 @@ public class SignaturePartsTest extends
@Test
public void testOptionalSOAPHeaderNotPresent() throws Exception {
- WSSecSignature sign = new WSSecSignature();
- sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
-
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
-
+ Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
+
+ WSSecSignature sign = new WSSecSignature(secHeader);
+ sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
WSEncryptionPart encP =
new WSEncryptionPart(
@@ -220,7 +217,7 @@ public class SignaturePartsTest extends
);
sign.getParts().add(encP);
- Document signedDoc = sign.build(doc, crypto, secHeader);
+ Document signedDoc = sign.build(doc, crypto);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -233,14 +230,13 @@ public class SignaturePartsTest extends
@Test
public void testRequiredSOAPHeaderNotPresent() throws Exception {
- WSSecSignature sign = new WSSecSignature();
- sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
-
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
-
+ Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
+
+ WSSecSignature sign = new WSSecSignature(secHeader);
+ sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
WSEncryptionPart encP =
new WSEncryptionPart(
@@ -258,7 +254,7 @@ public class SignaturePartsTest extends
sign.getParts().add(encP);
try {
- sign.build(doc, crypto, secHeader);
+ sign.build(doc, crypto);
fail("Failure expected on not signing a required element");
} catch (WSSecurityException ex) {
assertTrue(ex.getErrorCode() == WSSecurityException.ErrorCode.FAILED_SIGNATURE);
@@ -293,15 +289,15 @@ public class SignaturePartsTest extends
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(doc);
secHeader.insertSecurityHeader();
+ WSSecSignatureSAML wsSign = new WSSecSignatureSAML(secHeader);
+ wsSign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
+ wsSign.setUserInfo("wss40", "security");
+
WSEncryptionPart encP =
new WSEncryptionPart("STRTransform", "", "Element");
wsSign.getParts().add(encP);
@@ -309,7 +305,7 @@ public class SignaturePartsTest extends
//
// set up for keyHolder
//
- Document signedDoc = wsSign.build(doc, userCrypto, samlAssertion, null, null, null, secHeader);
+ Document signedDoc = wsSign.build(doc, userCrypto, samlAssertion, null, null, null);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed SAML message (key holder):");
@@ -352,14 +348,13 @@ public class SignaturePartsTest extends
*/
@Test
public void testBadLocalname() throws Exception {
- WSSecSignature sign = new WSSecSignature();
- sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
-
Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
-
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
+
+ WSSecSignature sign = new WSSecSignature(secHeader);
+ sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
WSEncryptionPart encP =
new WSEncryptionPart(
@@ -369,7 +364,7 @@ public class SignaturePartsTest extends
sign.getParts().add(encP);
try {
- sign.build(doc, crypto, secHeader);
+ sign.build(doc, crypto);
fail("Failure expected on a bad localname");
} catch (WSSecurityException ex) {
assertTrue(ex.getErrorCode() == WSSecurityException.ErrorCode.FAILED_SIGNATURE);
@@ -381,14 +376,13 @@ public class SignaturePartsTest extends
*/
@Test
public void testBadNamespace() throws Exception {
- WSSecSignature sign = new WSSecSignature();
- sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
-
Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
-
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
+
+ WSSecSignature sign = new WSSecSignature(secHeader);
+ sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
WSEncryptionPart encP =
new WSEncryptionPart(
@@ -398,7 +392,7 @@ public class SignaturePartsTest extends
sign.getParts().add(encP);
try {
- sign.build(doc, crypto, secHeader);
+ sign.build(doc, crypto);
fail("Failure expected on a bad namespace");
} catch (WSSecurityException ex) {
assertTrue(ex.getErrorCode() == WSSecurityException.ErrorCode.FAILED_SIGNATURE);
@@ -410,17 +404,17 @@ public class SignaturePartsTest extends
*/
@Test
public void testSOAPHeaderAndBody() throws Exception {
- WSSecSignature sign = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecSignature sign = new WSSecSignature(secHeader);
sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
- Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
SOAPConstants soapConstants =
WSSecurityUtil.getSOAPConstants(doc.getDocumentElement());
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
-
WSEncryptionPart encP =
new WSEncryptionPart(
soapConstants.getBodyQName().getLocalPart(), // define the body
@@ -434,7 +428,7 @@ public class SignaturePartsTest extends
"");
sign.getParts().add(encP2);
- Document signedDoc = sign.build(doc, crypto, secHeader);
+ Document signedDoc = sign.build(doc, crypto);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -480,17 +474,17 @@ public class SignaturePartsTest extends
*/
@Test
public void testSignaturePartDOMElement() throws Exception {
- WSSecSignature sign = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecSignature sign = new WSSecSignature(secHeader);
sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
- Document doc = SOAPUtil.toSOAPPart(SOAPMSG);
SOAPConstants soapConstants =
WSSecurityUtil.getSOAPConstants(doc.getDocumentElement());
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
-
// Give wrong names to make sure it's picking up the element
WSEncryptionPart encP =
new WSEncryptionPart(
@@ -502,7 +496,7 @@ public class SignaturePartsTest extends
encP.setElement(bodyElement);
sign.getParts().add(encP);
- Document signedDoc = sign.build(doc, crypto, secHeader);
+ Document signedDoc = sign.build(doc, crypto);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -531,12 +525,12 @@ public class SignaturePartsTest extends
@Test
public void testMultipleElements() throws Exception {
Document doc = SOAPUtil.toSOAPPart(SOAPMSG_MULTIPLE);
- WSSecSignature sign = new WSSecSignature();
- sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
-
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
+
+ WSSecSignature sign = new WSSecSignature(secHeader);
+ sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
WSEncryptionPart encP =
new WSEncryptionPart(
@@ -545,7 +539,7 @@ public class SignaturePartsTest extends
"");
sign.getParts().add(encP);
- Document signedDoc = sign.build(doc, crypto, secHeader);
+ Document signedDoc = sign.build(doc, crypto);
String outputString =
XMLUtils.prettyDocumentToString(signedDoc);
Modified: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureTest.java?rev=1771305&r1=1771304&r2=1771305&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureTest.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/SignatureTest.java Fri Nov 25 12:30:30 2016
@@ -82,14 +82,16 @@ public class SignatureTest extends org.j
*/
@Test
public void testX509SignatureIS() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
- LOG.info("Before Signing IS....");
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
+ LOG.info("Before Signing IS....");
+
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed message with IssuerSerial key identifier:");
@@ -111,15 +113,17 @@ public class SignatureTest extends org.j
@Test
public void testX509SignatureISAttached() throws Exception {
- WSSecSignature builder = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
builder.setIncludeSignatureToken(true);
LOG.info("Before Signing IS....");
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
+
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed message with IssuerSerial key identifier:");
@@ -148,13 +152,15 @@ public class SignatureTest extends org.j
*/
@Test
public void testDoubleX509SignatureIS() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
- Document signedDoc1 = builder.build(signedDoc, crypto, secHeader);
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+
+ Document signedDoc = builder.build(doc, crypto);
+ Document signedDoc1 = builder.build(signedDoc, crypto);
verify(signedDoc1);
}
@@ -166,13 +172,14 @@ public class SignatureTest extends org.j
*/
@Test
public void testIssuerSerialSignature() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- LOG.info("Before Signing....");
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ LOG.info("Before Signing....");
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("After Signing....");
@@ -192,14 +199,15 @@ public class SignatureTest extends org.j
*/
@Test
public void testSignatureInclusiveC14N() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setSigCanonicalization(WSConstants.C14N_OMIT_COMMENTS);
- builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- LOG.info("Before Signing....");
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setSigCanonicalization(WSConstants.C14N_OMIT_COMMENTS);
+ builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ LOG.info("Before Signing....");
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("After Signing....");
@@ -233,14 +241,15 @@ public class SignatureTest extends org.j
*/
@Test
public void testSignatureInclusivePrefixes() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setAddInclusivePrefixes(true);
- builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- LOG.info("Before Signing....");
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setAddInclusivePrefixes(true);
+ builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ LOG.info("Before Signing....");
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("After Signing....");
@@ -260,14 +269,15 @@ public class SignatureTest extends org.j
*/
@Test
public void testBSTSignature() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- builder.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
- LOG.info("Before Signing....");
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ builder.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
+ LOG.info("Before Signing....");
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("After Signing....");
@@ -295,17 +305,18 @@ public class SignatureTest extends org.j
*/
@Test
public void testBSTPKIPathSignature() throws Exception {
- WSSecSignature builder = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
builder.setUserInfo("wss40", "security");
builder.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
builder.setUseSingleCertificate(false);
LOG.info("Before Signing....");
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
Crypto pkiCrypto = CryptoFactory.getInstance("wss40.properties");
- Document signedDoc = builder.build(doc, pkiCrypto, secHeader);
+ Document signedDoc = builder.build(doc, pkiCrypto);
if (LOG.isDebugEnabled()) {
LOG.debug("After PKI Signing....");
@@ -325,14 +336,16 @@ public class SignatureTest extends org.j
*/
@Test
public void testX509Signature() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- builder.setKeyIdentifierType(WSConstants.X509_KEY_IDENTIFIER);
- LOG.info("Before Signing....");
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ builder.setKeyIdentifierType(WSConstants.X509_KEY_IDENTIFIER);
+ LOG.info("Before Signing....");
+
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("After Signing....");
@@ -363,16 +376,16 @@ public class SignatureTest extends org.j
*/
@Test
public void testX509SignatureThumb() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- builder.setKeyIdentifierType(WSConstants.THUMBPRINT_IDENTIFIER);
- LOG.info("Before Signing ThumbprintSHA1....");
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
-
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ builder.setKeyIdentifierType(WSConstants.THUMBPRINT_IDENTIFIER);
+ LOG.info("Before Signing ThumbprintSHA1....");
- Document signedDoc = builder.build(doc, crypto, secHeader);
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed message with ThumbprintSHA1 key identifier:");
@@ -395,17 +408,17 @@ public class SignatureTest extends org.j
@Test
public void testX509SignatureThumbAttached() throws Exception {
- WSSecSignature builder = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
builder.setKeyIdentifierType(WSConstants.THUMBPRINT_IDENTIFIER);
builder.setIncludeSignatureToken(true);
LOG.info("Before Signing ThumbprintSHA1....");
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
-
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed message with ThumbprintSHA1 key identifier:");
@@ -435,16 +448,16 @@ public class SignatureTest extends org.j
*/
@Test
public void testDoubleX509SignatureThumb() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- builder.setKeyIdentifierType(WSConstants.THUMBPRINT_IDENTIFIER);
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
-
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ builder.setKeyIdentifierType(WSConstants.THUMBPRINT_IDENTIFIER);
- Document signedDoc = builder.build(doc, crypto, secHeader);
- Document signedDoc1 = builder.build(signedDoc, crypto, secHeader);
+ Document signedDoc = builder.build(doc, crypto);
+ Document signedDoc1 = builder.build(signedDoc, crypto);
verify(signedDoc1);
}
@@ -458,16 +471,17 @@ public class SignatureTest extends org.j
*/
@Test
public void testValidModifiedSignature() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- LOG.info("Before Signing....");
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ LOG.info("Before Signing....");
- WSSecTimestamp timestamp = new WSSecTimestamp();
+ WSSecTimestamp timestamp = new WSSecTimestamp(secHeader);
timestamp.setTimeToLive(300);
- Document createdDoc = timestamp.build(doc, secHeader);
+ Document createdDoc = timestamp.build(doc);
WSEncryptionPart encP =
new WSEncryptionPart(
@@ -476,8 +490,8 @@ public class SignatureTest extends org.j
"");
builder.getParts().add(encP);
- Document signedDoc = builder.build(createdDoc, crypto, secHeader);
- Element secHeaderElement = secHeader.getSecurityHeader();
+ Document signedDoc = builder.build(createdDoc, crypto);
+ Element secHeaderElement = secHeader.getSecurityHeaderElement();
Node timestampNode =
secHeaderElement.getElementsByTagNameNS(WSConstants.WSU_NS, "Timestamp").item(0);
((Element)timestampNode).setAttributeNS(
@@ -502,16 +516,18 @@ public class SignatureTest extends org.j
*/
@Test
public void testX509SignatureSha256() throws Exception {
- WSSecSignature builder = new WSSecSignature();
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
builder.setSignatureAlgorithm("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256");
builder.setDigestAlgo("http://www.w3.org/2001/04/xmlenc#sha256");
LOG.info("Before Signing IS....");
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
+
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed message with IssuerSerial key identifier:");
@@ -578,13 +594,14 @@ public class SignatureTest extends org.j
*/
@Test
public void testWSS234() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- LOG.info("Before Signing....");
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ LOG.info("Before Signing....");
+ Document signedDoc = builder.build(doc, crypto);
// Add a comment node as the first node element
Node firstChild = signedDoc.getFirstChild();
@@ -613,11 +630,11 @@ public class SignatureTest extends org.j
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- WSSecTimestamp timestamp = new WSSecTimestamp();
+ WSSecTimestamp timestamp = new WSSecTimestamp(secHeader);
timestamp.setTimeToLive(300);
- Document createdDoc = timestamp.build(doc, secHeader);
+ Document createdDoc = timestamp.build(doc);
- WSSecSignature builder = new WSSecSignature();
+ WSSecSignature builder = new WSSecSignature(secHeader);
builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
WSEncryptionPart encP =
@@ -627,10 +644,10 @@ public class SignatureTest extends org.j
"");
builder.getParts().add(encP);
- builder.prepare(createdDoc, crypto, secHeader);
+ builder.prepare(createdDoc, crypto);
List<javax.xml.crypto.dsig.Reference> referenceList =
- builder.addReferencesToSign(builder.getParts(), secHeader);
+ builder.addReferencesToSign(builder.getParts());
builder.computeSignature(referenceList, false, null);
@@ -652,16 +669,17 @@ public class SignatureTest extends org.j
*/
@Test
public void testWSS283() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
-
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
Element secHeaderElement = secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
+
Node textNode = doc.createTextNode("This is a text node");
secHeaderElement.appendChild(textNode);
- Document signedDoc = builder.build(doc, crypto, secHeader);
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed message with text node:");
@@ -678,13 +696,14 @@ public class SignatureTest extends org.j
*/
@Test
public void testCustomSTR() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
- LOG.info("Before Signing IS....");
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
+ LOG.info("Before Signing IS....");
SecurityTokenReference secRef = new SecurityTokenReference(doc);
Reference ref = new Reference(doc);
@@ -692,7 +711,7 @@ public class SignatureTest extends org.j
secRef.setReference(ref);
builder.setSecurityTokenReference(secRef);
- Document signedDoc = builder.build(doc, crypto, secHeader);
+ Document signedDoc = builder.build(doc, crypto);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -710,15 +729,16 @@ public class SignatureTest extends org.j
@Test
public void testX509SignatureDefaultPassword() throws Exception {
Crypto passwordCrypto = CryptoFactory.getInstance("alice.properties");
+
+ Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+ WSSecHeader secHeader = new WSSecHeader(doc);
+ secHeader.insertSecurityHeader();
- WSSecSignature builder = new WSSecSignature();
+ WSSecSignature builder = new WSSecSignature(secHeader);
builder.setUserInfo(passwordCrypto.getDefaultX509Identifier(), null);
builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
LOG.info("Before Signing IS....");
- Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
- WSSecHeader secHeader = new WSSecHeader(doc);
- secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, passwordCrypto, secHeader);
+ Document signedDoc = builder.build(doc, passwordCrypto);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed message with IssuerSerial key identifier:");
@@ -898,13 +918,14 @@ public class SignatureTest extends org.j
@Test
public void testCommentInSOAPBody() throws Exception {
- WSSecSignature builder = new WSSecSignature();
- builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
- LOG.info("Before Signing....");
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- Document signedDoc = builder.build(doc, crypto, secHeader);
+
+ WSSecSignature builder = new WSSecSignature(secHeader);
+ builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+ LOG.info("Before Signing....");
+ Document signedDoc = builder.build(doc, crypto);
// Add a comment node
Element body = WSSecurityUtil.findBodyElement(signedDoc);
Modified: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/TimestampTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/TimestampTest.java?rev=1771305&r1=1771304&r2=1771305&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/TimestampTest.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/TimestampTest.java Fri Nov 25 12:30:30 2016
@@ -69,9 +69,9 @@ public class TimestampTest extends org.j
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- WSSecTimestamp timestamp = new WSSecTimestamp();
+ WSSecTimestamp timestamp = new WSSecTimestamp(secHeader);
timestamp.setTimeToLive(300);
- Document createdDoc = timestamp.build(doc, secHeader);
+ Document createdDoc = timestamp.build(doc);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -107,9 +107,9 @@ public class TimestampTest extends org.j
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- WSSecTimestamp timestamp = new WSSecTimestamp();
+ WSSecTimestamp timestamp = new WSSecTimestamp(secHeader);
timestamp.setTimeToLive(0);
- Document createdDoc = timestamp.build(doc, secHeader);
+ Document createdDoc = timestamp.build(doc);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -137,9 +137,9 @@ public class TimestampTest extends org.j
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- WSSecTimestamp timestamp = new WSSecTimestamp();
+ WSSecTimestamp timestamp = new WSSecTimestamp(secHeader);
timestamp.setTimeToLive(0);
- Document createdDoc = timestamp.build(doc, secHeader);
+ Document createdDoc = timestamp.build(doc);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -184,9 +184,9 @@ public class TimestampTest extends org.j
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- WSSecTimestamp timestamp = new WSSecTimestamp();
+ WSSecTimestamp timestamp = new WSSecTimestamp(secHeader);
timestamp.setTimeToLive(-1);
- Document createdDoc = timestamp.build(doc, secHeader);
+ Document createdDoc = timestamp.build(doc);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -214,8 +214,8 @@ public class TimestampTest extends org.j
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- WSSecTimestamp timestamp = new WSSecTimestamp();
- Document createdDoc = timestamp.build(doc, secHeader);
+ WSSecTimestamp timestamp = new WSSecTimestamp(secHeader);
+ Document createdDoc = timestamp.build(doc);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -266,7 +266,7 @@ public class TimestampTest extends org.j
elementCreated.appendChild(doc.createTextNode(zulu.format(createdDate)));
timestampElement.appendChild(elementCreated);
- secHeader.getSecurityHeader().appendChild(timestampElement);
+ secHeader.getSecurityHeaderElement().appendChild(timestampElement);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -314,7 +314,7 @@ public class TimestampTest extends org.j
elementCreated.appendChild(doc.createTextNode(zulu.format(createdDate)));
timestampElement.appendChild(elementCreated);
- secHeader.getSecurityHeader().appendChild(timestampElement);
+ secHeader.getSecurityHeaderElement().appendChild(timestampElement);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -370,7 +370,7 @@ public class TimestampTest extends org.j
elementExpires.appendChild(doc.createTextNode(zulu.format(expiresDate)));
timestampElement.appendChild(elementExpires);
- secHeader.getSecurityHeader().appendChild(timestampElement);
+ secHeader.getSecurityHeaderElement().appendChild(timestampElement);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -398,13 +398,13 @@ public class TimestampTest extends org.j
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- WSSecTimestamp timestamp = new WSSecTimestamp();
+ WSSecTimestamp timestamp = new WSSecTimestamp(secHeader);
timestamp.setTimeToLive(300);
- Document createdDoc = timestamp.build(doc, secHeader);
+ Document createdDoc = timestamp.build(doc);
- timestamp = new WSSecTimestamp();
+ timestamp = new WSSecTimestamp(secHeader);
timestamp.setTimeToLive(60);
- createdDoc = timestamp.build(doc, secHeader);
+ createdDoc = timestamp.build(doc);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -451,7 +451,7 @@ public class TimestampTest extends org.j
timestampElement.appendChild(elementCreated);
timestampElement.appendChild(elementCreated.cloneNode(true));
- secHeader.getSecurityHeader().appendChild(timestampElement);
+ secHeader.getSecurityHeaderElement().appendChild(timestampElement);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -498,7 +498,7 @@ public class TimestampTest extends org.j
elementCreated.appendChild(doc.createTextNode(zulu.format(createdDate)));
timestampElement.appendChild(elementCreated);
- secHeader.getSecurityHeader().appendChild(timestampElement);
+ secHeader.getSecurityHeaderElement().appendChild(timestampElement);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -558,7 +558,7 @@ public class TimestampTest extends org.j
timestampElement.appendChild(elementExpires);
timestampElement.appendChild(elementExpires.cloneNode(true));
- secHeader.getSecurityHeader().appendChild(timestampElement);
+ secHeader.getSecurityHeaderElement().appendChild(timestampElement);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -612,7 +612,7 @@ public class TimestampTest extends org.j
elementExpires.appendChild(doc.createTextNode(zulu.format(new Date())));
timestampElement.appendChild(elementExpires);
- secHeader.getSecurityHeader().appendChild(timestampElement);
+ secHeader.getSecurityHeaderElement().appendChild(timestampElement);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -656,7 +656,7 @@ public class TimestampTest extends org.j
elementCreated.appendChild(doc.createTextNode("2011-02-08T13:13:84.535Z"));
timestampElement.appendChild(elementCreated);
- secHeader.getSecurityHeader().appendChild(timestampElement);
+ secHeader.getSecurityHeaderElement().appendChild(timestampElement);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -706,7 +706,7 @@ public class TimestampTest extends org.j
elementCreated.setAttributeNS(null, "ValueType", WSConstants.WSS_SAML_KI_VALUE_TYPE);
timestampElement.appendChild(elementCreated);
- secHeader.getSecurityHeader().appendChild(timestampElement);
+ secHeader.getSecurityHeaderElement().appendChild(timestampElement);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -770,7 +770,7 @@ public class TimestampTest extends org.j
);
timestampElement.appendChild(elementCustom);
- secHeader.getSecurityHeader().appendChild(timestampElement);
+ secHeader.getSecurityHeaderElement().appendChild(timestampElement);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -801,7 +801,7 @@ public class TimestampTest extends org.j
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- WSSecTimestamp timestamp = new WSSecTimestamp();
+ WSSecTimestamp timestamp = new WSSecTimestamp(secHeader);
timestamp.setTimeToLive(300);
WSTimeSource spoofedTimeSource = new WSTimeSource() {
@@ -815,7 +815,7 @@ public class TimestampTest extends org.j
};
timestamp.setWsTimeSource(spoofedTimeSource);
- Document createdDoc = timestamp.build(doc, secHeader);
+ Document createdDoc = timestamp.build(doc);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -841,10 +841,10 @@ public class TimestampTest extends org.j
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- WSSecTimestamp timestamp = new WSSecTimestamp();
+ WSSecTimestamp timestamp = new WSSecTimestamp(secHeader);
timestamp.setPrecisionInMilliSeconds(false);
timestamp.setTimeToLive(300);
- Document createdDoc = timestamp.build(doc, secHeader);
+ Document createdDoc = timestamp.build(doc);
if (LOG.isDebugEnabled()) {
String outputString =
@@ -872,9 +872,9 @@ public class TimestampTest extends org.j
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
- WSSecTimestamp timestamp = new WSSecTimestamp();
+ WSSecTimestamp timestamp = new WSSecTimestamp(secHeader);
timestamp.setTimeToLive(300);
- Document createdDoc = timestamp.build(doc, secHeader);
+ Document createdDoc = timestamp.build(doc);
//
// Do some processing