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 2015/12/15 17:40:42 UTC
svn commit: r1720192 [27/33] - in /webservices/wss4j/trunk:
bindings/src/main/java/org/apache/wss4j/binding/wss10/
bindings/src/main/java/org/apache/wss4j/binding/wss11/
bindings/src/main/java/org/apache/wss4j/binding/wssc13/
bindings/src/main/java/org...
Modified: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/saml/SamlTokenHOKTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/saml/SamlTokenHOKTest.java?rev=1720192&r1=1720191&r2=1720192&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/saml/SamlTokenHOKTest.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/saml/SamlTokenHOKTest.java Tue Dec 15 16:40:37 2015
@@ -44,24 +44,24 @@ import org.w3c.dom.Document;
/**
* Test-case for sending and processing a signed (holder-of-key) SAML Assertion. These tests
- * just cover the case of creating and signing the Assertion, and not using the credential
+ * just cover the case of creating and signing the Assertion, and not using the credential
* information in the SAML Subject to sign the SOAP body.
*/
public class SamlTokenHOKTest extends org.junit.Assert {
- private static final org.slf4j.Logger LOG =
+ private static final org.slf4j.Logger LOG =
org.slf4j.LoggerFactory.getLogger(SamlTokenHOKTest.class);
private WSSecurityEngine secEngine = new WSSecurityEngine();
private Crypto crypto = null;
-
+
@org.junit.AfterClass
public static void cleanup() throws Exception {
SecurityTestUtil.cleanup();
}
-
+
public SamlTokenHOKTest() throws Exception {
WSSConfig config = WSSConfig.getNewInstance();
secEngine.setWssConfig(config);
-
+
crypto = CryptoFactory.getInstance("crypto.properties");
}
@@ -74,11 +74,11 @@ public class SamlTokenHOKTest extends or
callbackHandler.setStatement(SAML1CallbackHandler.Statement.AUTHN);
callbackHandler.setConfirmationMethod(SAML1Constants.CONF_HOLDER_KEY);
callbackHandler.setIssuer("www.example.com");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
-
+
samlAssertion.signAssertion("16c73ab6-b892-458f-abf5-2f875f74882e", "security", crypto, false);
WSSecSAMLToken wsSign = new WSSecSAMLToken();
@@ -86,16 +86,16 @@ public class SamlTokenHOKTest extends or
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
Document signedDoc = wsSign.build(doc, samlAssertion, secHeader);
if (LOG.isDebugEnabled()) {
LOG.debug("SAML 1.1 Authn Assertion (holder-of-key):");
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(signedDoc);
LOG.debug(outputString);
}
-
+
WSHandlerResult results = verify(signedDoc);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_SIGNED).get(0);
@@ -105,7 +105,7 @@ public class SamlTokenHOKTest extends or
assertTrue(receivedSamlAssertion.isSigned());
assertNotNull(receivedSamlAssertion.assertionToString());
}
-
+
/**
* Test that creates, sends and processes a signed SAML 1.1 attribute assertion.
*/
@@ -115,11 +115,11 @@ public class SamlTokenHOKTest extends or
callbackHandler.setStatement(SAML1CallbackHandler.Statement.ATTR);
callbackHandler.setConfirmationMethod(SAML1Constants.CONF_HOLDER_KEY);
callbackHandler.setIssuer("www.example.com");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
-
+
samlAssertion.signAssertion("16c73ab6-b892-458f-abf5-2f875f74882e", "security", crypto, false);
WSSecSAMLToken wsSign = new WSSecSAMLToken();
@@ -127,28 +127,28 @@ public class SamlTokenHOKTest extends or
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
Document signedDoc = wsSign.build(doc, samlAssertion, secHeader);
if (LOG.isDebugEnabled()) {
LOG.debug("SAML 1.1 Attr Assertion (holder-of-key):");
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(signedDoc);
LOG.debug(outputString);
}
-
+
RequestData requestData = new RequestData();
requestData.setValidateSamlSubjectConfirmation(false);
requestData.setCallbackHandler(new KeystoreCallbackHandler());
Crypto decCrypto = CryptoFactory.getInstance("wss40.properties");
requestData.setDecCrypto(decCrypto);
requestData.setSigVerCrypto(crypto);
-
+
WSHandlerResult results = secEngine.processSecurityHeader(doc, requestData);
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(doc);
assertTrue(outputString.indexOf("counter_port_type") > 0 ? true : false);
-
+
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_SIGNED).get(0);
SamlAssertionWrapper receivedSamlAssertion =
@@ -156,7 +156,7 @@ public class SamlTokenHOKTest extends or
assertTrue(receivedSamlAssertion != null);
assertTrue(receivedSamlAssertion.isSigned());
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2 authentication assertion.
*/
@@ -166,11 +166,11 @@ public class SamlTokenHOKTest extends or
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setConfirmationMethod(SAML2Constants.CONF_HOLDER_KEY);
callbackHandler.setIssuer("www.example.com");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
-
+
samlAssertion.signAssertion("16c73ab6-b892-458f-abf5-2f875f74882e", "security", crypto, false);
WSSecSAMLToken wsSign = new WSSecSAMLToken();
@@ -178,16 +178,16 @@ public class SamlTokenHOKTest extends or
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
Document unsignedDoc = wsSign.build(doc, samlAssertion, secHeader);
if (LOG.isDebugEnabled()) {
LOG.debug("SAML 2 Authn Assertion (holder-of-key):");
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(unsignedDoc);
LOG.debug(outputString);
}
-
+
WSHandlerResult results = verify(unsignedDoc);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_SIGNED).get(0);
@@ -196,7 +196,7 @@ public class SamlTokenHOKTest extends or
assertTrue(receivedSamlAssertion != null);
assertTrue(receivedSamlAssertion.isSigned());
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2 attribute assertion.
*/
@@ -206,11 +206,11 @@ public class SamlTokenHOKTest extends or
callbackHandler.setStatement(SAML2CallbackHandler.Statement.ATTR);
callbackHandler.setConfirmationMethod(SAML2Constants.CONF_HOLDER_KEY);
callbackHandler.setIssuer("www.example.com");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
-
+
samlAssertion.signAssertion("16c73ab6-b892-458f-abf5-2f875f74882e", "security", crypto, false);
@@ -219,16 +219,16 @@ public class SamlTokenHOKTest extends or
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
Document unsignedDoc = wsSign.build(doc, samlAssertion, secHeader);
if (LOG.isDebugEnabled()) {
LOG.debug("SAML 2 Attr Assertion (holder-of-key):");
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(unsignedDoc);
LOG.debug(outputString);
}
-
+
RequestData requestData = new RequestData();
requestData.setValidateSamlSubjectConfirmation(false);
requestData.setCallbackHandler(new KeystoreCallbackHandler());
@@ -236,11 +236,11 @@ public class SamlTokenHOKTest extends or
requestData.setDecCrypto(decCrypto);
requestData.setSigVerCrypto(crypto);
WSHandlerResult results = secEngine.processSecurityHeader(doc, requestData);
-
- String outputString =
+
+ String outputString =
XMLUtils.PrettyDocumentToString(doc);
assertTrue(outputString.indexOf("counter_port_type") > 0 ? true : false);
-
+
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_SIGNED).get(0);
SamlAssertionWrapper receivedSamlAssertion =
@@ -251,8 +251,8 @@ public class SamlTokenHOKTest extends or
/**
* Verifies the soap envelope
* <p/>
- *
- * @param envelope
+ *
+ * @param envelope
* @throws Exception Thrown when there is a problem in verification
*/
private WSHandlerResult verify(Document doc) throws Exception {
@@ -260,10 +260,10 @@ public class SamlTokenHOKTest extends or
requestData.setDecCrypto(crypto);
requestData.setSigVerCrypto(crypto);
requestData.setValidateSamlSubjectConfirmation(false);
-
+
WSHandlerResult results = secEngine.processSecurityHeader(doc, requestData);
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(doc);
assertTrue(outputString.indexOf("counter_port_type") > 0 ? true : false);
return results;
Modified: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/saml/SamlTokenSVTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/saml/SamlTokenSVTest.java?rev=1720192&r1=1720191&r2=1720192&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/saml/SamlTokenSVTest.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/saml/SamlTokenSVTest.java Tue Dec 15 16:40:37 2015
@@ -53,22 +53,22 @@ import javax.security.auth.callback.Call
* Test-case for sending and processing a signed (sender vouches) SAML Assertion.
*/
public class SamlTokenSVTest extends org.junit.Assert {
- private static final org.slf4j.Logger LOG =
+ private static final org.slf4j.Logger LOG =
org.slf4j.LoggerFactory.getLogger(SamlTokenSVTest.class);
private WSSecurityEngine secEngine = new WSSecurityEngine();
private CallbackHandler callbackHandler = new KeystoreCallbackHandler();
private Crypto crypto = null;
-
+
@org.junit.AfterClass
public static void cleanup() throws Exception {
SecurityTestUtil.cleanup();
}
-
+
public SamlTokenSVTest() throws Exception {
WSSConfig.init();
crypto = CryptoFactory.getInstance("crypto.properties");
}
-
+
/**
* Test that creates, sends and processes a signed SAML 1.1 authentication assertion.
*/
@@ -79,19 +79,19 @@ public class SamlTokenSVTest extends org
callbackHandler.setStatement(SAML1CallbackHandler.Statement.AUTHN);
callbackHandler.setConfirmationMethod(SAML1Constants.CONF_SENDER_VOUCHES);
callbackHandler.setIssuer("www.example.com");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
-
+
WSSecSignatureSAML wsSign = new WSSecSignatureSAML();
wsSign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
-
+
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
- Document signedDoc =
+
+ Document signedDoc =
wsSign.build(
doc, null, samlAssertion, crypto, "16c73ab6-b892-458f-abf5-2f875f74882e",
"security", secHeader
@@ -99,11 +99,11 @@ public class SamlTokenSVTest extends org
if (LOG.isDebugEnabled()) {
LOG.debug("SAML 1.1 Authn Assertion (sender vouches):");
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(signedDoc);
LOG.debug(outputString);
}
-
+
// Test we processed a SAML assertion
WSHandlerResult results = verify(signedDoc);
WSSecurityEngineResult actionResult =
@@ -111,7 +111,7 @@ public class SamlTokenSVTest extends org
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
-
+
// Test we processed a signature (SAML assertion + SOAP body)
actionResult = results.getActionResults().get(WSConstants.SIGN).get(0);
assertTrue(actionResult != null);
@@ -119,16 +119,16 @@ public class SamlTokenSVTest extends org
final List<WSDataRef> refs =
(List<WSDataRef>) actionResult.get(WSSecurityEngineResult.TAG_DATA_REF_URIS);
assertTrue(refs.size() == 2);
-
+
WSDataRef wsDataRef = refs.get(0);
String xpath = wsDataRef.getXpath();
assertEquals("/SOAP-ENV:Envelope/SOAP-ENV:Body", xpath);
-
+
wsDataRef = refs.get(1);
xpath = wsDataRef.getXpath();
assertEquals("/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/saml1:Assertion", xpath);
}
-
+
/**
* Test that creates, sends and processes a signed SAML 1.1 attribute assertion.
*/
@@ -139,19 +139,19 @@ public class SamlTokenSVTest extends org
callbackHandler.setStatement(SAML1CallbackHandler.Statement.ATTR);
callbackHandler.setConfirmationMethod(SAML1Constants.CONF_SENDER_VOUCHES);
callbackHandler.setIssuer("www.example.com");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
WSSecSignatureSAML wsSign = new WSSecSignatureSAML();
wsSign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
-
+
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
- Document signedDoc =
+
+ Document signedDoc =
wsSign.build(
doc, null, samlAssertion, crypto, "16c73ab6-b892-458f-abf5-2f875f74882e",
"security", secHeader
@@ -159,11 +159,11 @@ public class SamlTokenSVTest extends org
if (LOG.isDebugEnabled()) {
LOG.debug("SAML 1.1 Attr Assertion (sender vouches):");
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(signedDoc);
LOG.debug(outputString);
}
-
+
// Test we processed a SAML assertion
WSHandlerResult results = verify(signedDoc);
WSSecurityEngineResult actionResult =
@@ -171,7 +171,7 @@ public class SamlTokenSVTest extends org
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
-
+
// Test we processed a signature (SAML assertion + SOAP body)
actionResult = results.getActionResults().get(WSConstants.SIGN).get(0);
assertTrue(actionResult != null);
@@ -179,16 +179,16 @@ public class SamlTokenSVTest extends org
final List<WSDataRef> refs =
(List<WSDataRef>) actionResult.get(WSSecurityEngineResult.TAG_DATA_REF_URIS);
assertTrue(refs.size() == 2);
-
+
WSDataRef wsDataRef = refs.get(0);
String xpath = wsDataRef.getXpath();
assertEquals("/SOAP-ENV:Envelope/SOAP-ENV:Body", xpath);
-
+
wsDataRef = refs.get(1);
xpath = wsDataRef.getXpath();
assertEquals("/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/saml1:Assertion", xpath);
}
-
+
/**
* Test that creates, sends and processes a signed SAML 2 authentication assertion.
*/
@@ -199,19 +199,19 @@ public class SamlTokenSVTest extends org
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setConfirmationMethod(SAML2Constants.CONF_SENDER_VOUCHES);
callbackHandler.setIssuer("www.example.com");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
-
+
WSSecSignatureSAML wsSign = new WSSecSignatureSAML();
wsSign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
-
+
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
- Document signedDoc =
+
+ Document signedDoc =
wsSign.build(
doc, null, samlAssertion, crypto, "16c73ab6-b892-458f-abf5-2f875f74882e",
"security", secHeader
@@ -219,11 +219,11 @@ public class SamlTokenSVTest extends org
if (LOG.isDebugEnabled()) {
LOG.debug("SAML 2 Authn Assertion (sender vouches):");
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(signedDoc);
LOG.debug(outputString);
}
-
+
// Test we processed a SAML assertion
WSHandlerResult results = verify(signedDoc);
WSSecurityEngineResult actionResult =
@@ -231,7 +231,7 @@ public class SamlTokenSVTest extends org
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
-
+
// Test we processed a signature (SAML assertion + SOAP body)
actionResult = results.getActionResults().get(WSConstants.SIGN).get(0);
assertTrue(actionResult != null);
@@ -239,16 +239,16 @@ public class SamlTokenSVTest extends org
final List<WSDataRef> refs =
(List<WSDataRef>) actionResult.get(WSSecurityEngineResult.TAG_DATA_REF_URIS);
assertTrue(refs.size() == 2);
-
+
WSDataRef wsDataRef = refs.get(0);
String xpath = wsDataRef.getXpath();
assertEquals("/SOAP-ENV:Envelope/SOAP-ENV:Body", xpath);
-
+
wsDataRef = refs.get(1);
xpath = wsDataRef.getXpath();
assertEquals("/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/saml2:Assertion", xpath);
}
-
+
/**
* Test that creates, sends and processes a signed SAML 2 attribute assertion.
*/
@@ -259,19 +259,19 @@ public class SamlTokenSVTest extends org
callbackHandler.setStatement(SAML2CallbackHandler.Statement.ATTR);
callbackHandler.setConfirmationMethod(SAML2Constants.CONF_SENDER_VOUCHES);
callbackHandler.setIssuer("www.example.com");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
WSSecSignatureSAML wsSign = new WSSecSignatureSAML();
wsSign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
-
+
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
- Document signedDoc =
+
+ Document signedDoc =
wsSign.build(
doc, null, samlAssertion, crypto, "16c73ab6-b892-458f-abf5-2f875f74882e",
"security", secHeader
@@ -279,11 +279,11 @@ public class SamlTokenSVTest extends org
if (LOG.isDebugEnabled()) {
LOG.debug("SAML 2 Attr Assertion (sender vouches):");
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(signedDoc);
LOG.debug(outputString);
}
-
+
// Test we processed a SAML assertion
WSHandlerResult results = verify(signedDoc);
WSSecurityEngineResult actionResult =
@@ -291,7 +291,7 @@ public class SamlTokenSVTest extends org
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
-
+
// Test we processed a signature (SAML assertion + SOAP body)
actionResult = results.getActionResults().get(WSConstants.SIGN).get(0);
assertTrue(actionResult != null);
@@ -299,20 +299,20 @@ public class SamlTokenSVTest extends org
final List<WSDataRef> refs =
(List<WSDataRef>) actionResult.get(WSSecurityEngineResult.TAG_DATA_REF_URIS);
assertTrue(refs.size() == 2);
-
+
WSDataRef wsDataRef = refs.get(0);
String xpath = wsDataRef.getXpath();
assertEquals("/SOAP-ENV:Envelope/SOAP-ENV:Body", xpath);
-
+
wsDataRef = refs.get(1);
xpath = wsDataRef.getXpath();
assertEquals("/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/saml2:Assertion", xpath);
}
-
+
/**
* A test for WSS-62: "the crypto file not being retrieved in the doReceiverAction
* method for the Saml Signed Token"
- *
+ *
* https://issues.apache.org/jira/browse/WSS-62
*/
@org.junit.Test
@@ -321,7 +321,7 @@ public class SamlTokenSVTest extends org
callbackHandler.setStatement(SAML2CallbackHandler.Statement.ATTR);
callbackHandler.setConfirmationMethod(SAML2Constants.CONF_SENDER_VOUCHES);
callbackHandler.setIssuer("www.example.com");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
@@ -333,8 +333,8 @@ public class SamlTokenSVTest extends org
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
- Document signedDoc =
+
+ Document signedDoc =
wsSign.build(
doc, null, samlAssertion, crypto, "16c73ab6-b892-458f-abf5-2f875f74882e",
"security", secHeader
@@ -348,27 +348,27 @@ public class SamlTokenSVTest extends org
java.util.Map<String, Object> msgContext = new java.util.HashMap<String, Object>();
msgContext.put(WSHandlerConstants.SIG_VER_PROP_FILE, "crypto.properties");
reqData.setMsgContext(msgContext);
-
+
CustomHandler handler = new CustomHandler();
handler.receive(Collections.singletonList(WSConstants.ST_SIGNED), reqData);
-
+
secEngine.processSecurityHeader(
signedDoc, null, callbackHandler, reqData.getSigVerCrypto(), reqData.getDecCrypto()
);
}
-
-
+
+
/**
* Verifies the soap envelope
* <p/>
- *
- * @param envelope
+ *
+ * @param envelope
* @throws Exception Thrown when there is a problem in verification
*/
private WSHandlerResult verify(Document doc) throws Exception {
- WSHandlerResult results =
+ WSHandlerResult results =
secEngine.processSecurityHeader(doc, null, callbackHandler, crypto);
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(doc);
assertTrue(outputString.indexOf("counter_port_type") > 0 ? true : false);
return results;
Modified: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/saml/SamlTokenTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/saml/SamlTokenTest.java?rev=1720192&r1=1720191&r2=1720192&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/saml/SamlTokenTest.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/saml/SamlTokenTest.java Tue Dec 15 16:40:37 2015
@@ -86,11 +86,11 @@ import org.w3c.dom.Element;
* Test-case for sending and processing an unsigned (sender vouches) SAML Assertion.
*/
public class SamlTokenTest extends org.junit.Assert {
- private static final org.slf4j.Logger LOG =
+ private static final org.slf4j.Logger LOG =
org.slf4j.LoggerFactory.getLogger(SamlTokenTest.class);
private WSSecurityEngine secEngine = new WSSecurityEngine();
private static final String IP_ADDRESS = "12.34.56.78"; //NOPMD
-
+
@org.junit.AfterClass
public static void cleanup() throws Exception {
SecurityTestUtil.cleanup();
@@ -102,7 +102,7 @@ public class SamlTokenTest extends org.j
config.setValidator(WSConstants.SAML2_TOKEN, new CustomSamlAssertionValidator());
secEngine.setWssConfig(config);
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 1.1 authentication assertion.
*/
@@ -111,8 +111,8 @@ public class SamlTokenTest extends org.j
SAML1CallbackHandler callbackHandler = new SAML1CallbackHandler();
callbackHandler.setStatement(SAML1CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example.com");
-
- WSHandlerResult results =
+
+ WSHandlerResult results =
createAndVerifyMessage(callbackHandler, true);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
@@ -123,7 +123,7 @@ public class SamlTokenTest extends org.j
assertFalse(receivedSamlAssertion.isSigned());
assertTrue(receivedSamlAssertion.getSignatureValue() == null);
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 1.1 authentication assertion.
* It set a DOM Element on the CallbackHandler rather than creating a set of beans for
@@ -133,19 +133,19 @@ public class SamlTokenTest extends org.j
public void testSAML1AuthnAssertionViaElement() throws Exception {
SAMLElementCallbackHandler callbackHandler = new SAMLElementCallbackHandler();
callbackHandler.setIssuer("www.example.com");
-
- WSHandlerResult results =
+
+ WSHandlerResult results =
createAndVerifyMessage(callbackHandler, true);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertFalse(receivedSamlAssertion.isSigned());
assertTrue(receivedSamlAssertion.getSignatureValue() == null);
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 1.1 attribute assertion.
*/
@@ -154,18 +154,18 @@ public class SamlTokenTest extends org.j
SAML1CallbackHandler callbackHandler = new SAML1CallbackHandler();
callbackHandler.setStatement(SAML1CallbackHandler.Statement.ATTR);
callbackHandler.setIssuer("www.example.com");
-
- WSHandlerResult results =
+
+ WSHandlerResult results =
createAndVerifyMessage(callbackHandler, true);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertFalse(receivedSamlAssertion.isSigned());
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 1.1 authorization assertion.
*/
@@ -176,17 +176,17 @@ public class SamlTokenTest extends org.j
callbackHandler.setIssuer("www.example.com");
callbackHandler.setResource("http://resource.org");
- WSHandlerResult results =
+ WSHandlerResult results =
createAndVerifyMessage(callbackHandler, true);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertFalse(receivedSamlAssertion.isSigned());
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2 authentication assertion.
*/
@@ -196,17 +196,17 @@ public class SamlTokenTest extends org.j
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example.com");
- WSHandlerResult results =
+ WSHandlerResult results =
createAndVerifyMessage(callbackHandler, true);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertFalse(receivedSamlAssertion.isSigned());
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2 attribute assertion.
*/
@@ -216,17 +216,17 @@ public class SamlTokenTest extends org.j
callbackHandler.setStatement(SAML2CallbackHandler.Statement.ATTR);
callbackHandler.setIssuer("www.example.com");
- WSHandlerResult results =
+ WSHandlerResult results =
createAndVerifyMessage(callbackHandler, true);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertFalse(receivedSamlAssertion.isSigned());
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2 authorization assertion.
*/
@@ -236,12 +236,12 @@ public class SamlTokenTest extends org.j
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHZ);
callbackHandler.setIssuer("www.example.com");
callbackHandler.setResource("http://resource.org");
-
- WSHandlerResult results =
+
+ WSHandlerResult results =
createAndVerifyMessage(callbackHandler, true);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
@@ -250,7 +250,7 @@ public class SamlTokenTest extends org.j
/**
* This test checks that an unsigned SAML1 sender-vouches authentication assertion
- * can be created by the WSHandler implementation
+ * can be created by the WSHandler implementation
*/
@org.junit.Test
public void testSaml1Action() throws Exception {
@@ -260,34 +260,34 @@ public class SamlTokenTest extends org.j
java.util.Map<String, Object> config = new java.util.TreeMap<String, Object>();
config.put(WSHandlerConstants.SAML_CALLBACK_REF, new SAML1CallbackHandler());
reqData.setMsgContext(config);
-
+
final Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
CustomHandler handler = new CustomHandler();
HandlerAction action = new HandlerAction(WSConstants.ST_UNSIGNED);
handler.send(
- doc,
- reqData,
+ doc,
+ reqData,
Collections.singletonList(action),
true
);
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(doc);
if (LOG.isDebugEnabled()) {
LOG.debug("Unsigned SAML 1.1 authentication assertion via an Action:");
LOG.debug(outputString);
}
assertFalse (outputString.contains("Signature"));
-
+
WSHandlerResult results = verify(doc);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertFalse(receivedSamlAssertion.isSigned());
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 1.1 authentication assertion.
* The issuer is different from what the custom Validator is expecting, so it throws an
@@ -298,10 +298,10 @@ public class SamlTokenTest extends org.j
SAML1CallbackHandler callbackHandler = new SAML1CallbackHandler();
callbackHandler.setStatement(SAML1CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example2.com");
-
+
createAndVerifyMessage(callbackHandler, false);
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2 authentication assertion.
* The issuer is different from what the custom Validator is expecting, so it throws an
@@ -312,10 +312,10 @@ public class SamlTokenTest extends org.j
SAML2CallbackHandler callbackHandler = new SAML2CallbackHandler();
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example2.com");
-
+
createAndVerifyMessage(callbackHandler, false);
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 1.1 authentication assertion with
* a user-specified SubjectNameIDFormat.
@@ -326,7 +326,7 @@ public class SamlTokenTest extends org.j
callbackHandler.setStatement(SAML1CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example.com");
callbackHandler.setSubjectNameIDFormat(SAML1Constants.NAMEID_FORMAT_EMAIL_ADDRESS);
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
@@ -336,27 +336,27 @@ public class SamlTokenTest extends org.j
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
Document unsignedDoc = wsSign.build(doc, samlAssertion, secHeader);
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(unsignedDoc);
if (LOG.isDebugEnabled()) {
LOG.debug("SAML 1.1 Authn Assertion (sender vouches):");
LOG.debug(outputString);
}
assertTrue(outputString.contains(SAML1Constants.NAMEID_FORMAT_EMAIL_ADDRESS));
-
+
WSHandlerResult results = verify(unsignedDoc);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertFalse(receivedSamlAssertion.isSigned());
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2 authentication assertion with
* a user-specified SubjectNameIDFormat.
@@ -367,7 +367,7 @@ public class SamlTokenTest extends org.j
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example.com");
callbackHandler.setSubjectNameIDFormat(SAML1Constants.NAMEID_FORMAT_EMAIL_ADDRESS);
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
@@ -377,27 +377,27 @@ public class SamlTokenTest extends org.j
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
Document unsignedDoc = wsSign.build(doc, samlAssertion, secHeader);
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(unsignedDoc);
if (LOG.isDebugEnabled()) {
LOG.debug("SAML 2 Authn Assertion (sender vouches):");
LOG.debug(outputString);
}
assertTrue(outputString.contains(SAML1Constants.NAMEID_FORMAT_EMAIL_ADDRESS));
-
+
WSHandlerResult results = verify(unsignedDoc);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertFalse(receivedSamlAssertion.isSigned());
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 1.1 authentication assertion with
* a user-specified SubjectLocality statement.
@@ -408,7 +408,7 @@ public class SamlTokenTest extends org.j
callbackHandler.setStatement(SAML1CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example.com");
callbackHandler.setSubjectLocality(IP_ADDRESS, "test-dns");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
@@ -418,10 +418,10 @@ public class SamlTokenTest extends org.j
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
Document unsignedDoc = wsSign.build(doc, samlAssertion, secHeader);
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(unsignedDoc);
if (LOG.isDebugEnabled()) {
LOG.debug("SAML 1.1 Authn Assertion (sender vouches):");
@@ -429,17 +429,17 @@ public class SamlTokenTest extends org.j
}
assertTrue(outputString.contains(IP_ADDRESS));
assertTrue(outputString.contains("test-dns"));
-
+
WSHandlerResult results = verify(unsignedDoc);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertFalse(receivedSamlAssertion.isSigned());
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2.0 authentication assertion with
* a user-specified SessionNotOnOrAfter DateTime.
@@ -450,7 +450,7 @@ public class SamlTokenTest extends org.j
callbackHandler.setStatement(SAML1CallbackHandler.Statement.AUTHN);
callbackHandler.setSessionNotOnOrAfter(new DateTime().plusHours(1));
callbackHandler.setIssuer("www.example.com");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
@@ -460,27 +460,27 @@ public class SamlTokenTest extends org.j
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
Document unsignedDoc = wsSign.build(doc, samlAssertion, secHeader);
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(unsignedDoc);
if (LOG.isDebugEnabled()) {
LOG.debug("SAML 2.0 Authn Assertion (sender vouches):");
LOG.debug(outputString);
}
assertTrue(outputString.contains("SessionNotOnOrAfter"));
-
+
WSHandlerResult results = verify(unsignedDoc);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertFalse(receivedSamlAssertion.isSigned());
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2 authentication assertion with
* a user-specified SubjectLocality statement.
@@ -491,7 +491,7 @@ public class SamlTokenTest extends org.j
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example.com");
callbackHandler.setSubjectLocality(IP_ADDRESS, "test-dns");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
@@ -501,10 +501,10 @@ public class SamlTokenTest extends org.j
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
Document unsignedDoc = wsSign.build(doc, samlAssertion, secHeader);
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(unsignedDoc);
if (LOG.isDebugEnabled()) {
LOG.debug("SAML 2 Authn Assertion (sender vouches):");
@@ -512,17 +512,17 @@ public class SamlTokenTest extends org.j
}
assertTrue(outputString.contains(IP_ADDRESS));
assertTrue(outputString.contains("test-dns"));
-
+
WSHandlerResult results = verify(unsignedDoc);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertFalse(receivedSamlAssertion.isSigned());
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 1.1 authorization assertion
* with a Resource URI.
@@ -533,7 +533,7 @@ public class SamlTokenTest extends org.j
callbackHandler.setStatement(SAML1CallbackHandler.Statement.AUTHZ);
callbackHandler.setIssuer("www.example.com");
callbackHandler.setResource("http://resource.org");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
@@ -543,27 +543,27 @@ public class SamlTokenTest extends org.j
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
Document unsignedDoc = wsSign.build(doc, samlAssertion, secHeader);
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(unsignedDoc);
if (LOG.isDebugEnabled()) {
LOG.debug("SAML 1.1 Authz Assertion (sender vouches):");
LOG.debug(outputString);
}
assertTrue(outputString.contains("http://resource.org"));
-
+
WSHandlerResult results = verify(unsignedDoc);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertFalse(receivedSamlAssertion.isSigned());
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2 attribute assertion. The attributeValue
* has a custom XMLObject (not a String) value.
@@ -574,23 +574,23 @@ public class SamlTokenTest extends org.j
SAML2CallbackHandler callbackHandler = new SAML2CallbackHandler();
callbackHandler.setStatement(SAML2CallbackHandler.Statement.ATTR);
callbackHandler.setIssuer("www.example.com");
-
+
// Create and add a custom Attribute (conditions Object)
- XMLObjectBuilderFactory builderFactory =
+ XMLObjectBuilderFactory builderFactory =
XMLObjectProviderRegistrySupport.getBuilderFactory();
-
- SAMLObjectBuilder<Conditions> conditionsV2Builder =
+
+ SAMLObjectBuilder<Conditions> conditionsV2Builder =
(SAMLObjectBuilder<Conditions>)builderFactory.getBuilder(Conditions.DEFAULT_ELEMENT_NAME);
Conditions conditions = conditionsV2Builder.buildObject();
DateTime newNotBefore = new DateTime();
conditions.setNotBefore(newNotBefore);
conditions.setNotOnOrAfter(newNotBefore.plusMinutes(5));
-
- XMLObjectBuilder<XSAny> xsAnyBuilder =
+
+ XMLObjectBuilder<XSAny> xsAnyBuilder =
(XMLObjectBuilder<XSAny>)builderFactory.getBuilder(XSAny.TYPE_NAME);
XSAny attributeValue = xsAnyBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
attributeValue.getUnknownXMLObjects().add(conditions);
-
+
List<Object> attributeValues = new ArrayList<>();
attributeValues.add(attributeValue);
callbackHandler.setCustomAttributeValues(attributeValues);
@@ -604,26 +604,26 @@ public class SamlTokenTest extends org.j
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
Document unsignedDoc = wsSign.build(doc, samlAssertion, secHeader);
if (LOG.isDebugEnabled()) {
LOG.debug("SAML 2 Attr Assertion (sender vouches):");
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(unsignedDoc);
LOG.debug(outputString);
}
-
+
WSHandlerResult results = verify(unsignedDoc);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertFalse(receivedSamlAssertion.isSigned());
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2 attribute assertion. The attributeValue
* has a custom XMLObject (xsd:type="xsd:int") value.
@@ -634,16 +634,16 @@ public class SamlTokenTest extends org.j
SAML2CallbackHandler callbackHandler = new SAML2CallbackHandler();
callbackHandler.setStatement(SAML2CallbackHandler.Statement.ATTR);
callbackHandler.setIssuer("www.example.com");
-
+
// Create and add a custom Attribute (Integer)
XMLObjectBuilderFactory builderFactory = XMLObjectProviderRegistrySupport.getBuilderFactory();
-
- XMLObjectBuilder<XSInteger> xsIntegerBuilder =
+
+ XMLObjectBuilder<XSInteger> xsIntegerBuilder =
(XMLObjectBuilder<XSInteger>)builderFactory.getBuilder(XSInteger.TYPE_NAME);
- XSInteger attributeValue =
+ XSInteger attributeValue =
xsIntegerBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSInteger.TYPE_NAME);
attributeValue.setValue(5);
-
+
List<Object> attributeValues = new ArrayList<>();
attributeValues.add(attributeValue);
callbackHandler.setCustomAttributeValues(attributeValues);
@@ -651,13 +651,13 @@ public class SamlTokenTest extends org.j
WSHandlerResult results = createAndVerifyMessage(callbackHandler, true);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertFalse(receivedSamlAssertion.isSigned());
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2 authentication assertion with
* SubjectConfirmationData information.
@@ -667,44 +667,44 @@ public class SamlTokenTest extends org.j
SAML2CallbackHandler callbackHandler = new SAML2CallbackHandler();
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example.com");
-
+
SubjectConfirmationDataBean subjectConfirmationData = new SubjectConfirmationDataBean();
subjectConfirmationData.setAddress("http://apache.org");
subjectConfirmationData.setInResponseTo("12345");
subjectConfirmationData.setNotAfter(new DateTime().plusMinutes(5));
subjectConfirmationData.setRecipient("http://recipient.apache.org");
callbackHandler.setSubjectConfirmationData(subjectConfirmationData);
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
-
+
WSSecSAMLToken wsSign = new WSSecSAMLToken();
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
Document unsignedDoc = wsSign.build(doc, samlAssertion, secHeader);
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(unsignedDoc);
if (LOG.isDebugEnabled()) {
LOG.debug("SAML 2 Authn Assertion (sender vouches):");
LOG.debug(outputString);
}
assertTrue(outputString.contains("http://recipient.apache.org"));
-
+
WSHandlerResult results = createAndVerifyMessage(callbackHandler, true);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertFalse(receivedSamlAssertion.isSigned());
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2 authentication assertion, which
* is encrypted in a saml2:EncryptedAssertion Element in the security header
@@ -714,7 +714,7 @@ public class SamlTokenTest extends org.j
SAML2CallbackHandler callbackHandler = new SAML2CallbackHandler();
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example.com");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
@@ -724,16 +724,16 @@ public class SamlTokenTest extends org.j
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
wsSign.prepare(doc, samlAssertion);
-
+
// Get the Element + add it to the security header as an EncryptedAssertion
Element assertionElement = wsSign.getElement();
- Element encryptedAssertionElement =
+ Element encryptedAssertionElement =
doc.createElementNS(WSConstants.SAML2_NS, WSConstants.ENCRYPED_ASSERTION_LN);
encryptedAssertionElement.appendChild(assertionElement);
secHeader.getSecurityHeader().appendChild(encryptedAssertionElement);
-
+
// Encrypt the Assertion
KeyGenerator keygen = KeyGenerator.getInstance("AES");
keygen.init(128);
@@ -743,42 +743,42 @@ public class SamlTokenTest extends org.j
cryptoType.setAlias("wss40");
X509Certificate[] certs = crypto.getX509Certificates(cryptoType);
assertTrue(certs != null && certs.length > 0 && certs[0] != null);
-
+
encryptElement(doc, assertionElement, WSConstants.AES_128, secretKey,
WSConstants.KEYTRANSPORT_RSAOEP, certs[0], false, true);
-
+
if (LOG.isDebugEnabled()) {
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(doc);
LOG.debug(outputString);
}
-
+
RequestData requestData = new RequestData();
requestData.setValidateSamlSubjectConfirmation(false);
requestData.setCallbackHandler(new KeystoreCallbackHandler());
requestData.setDecCrypto(crypto);
requestData.setSigVerCrypto(crypto);
WSHandlerResult results = secEngine.processSecurityHeader(doc, requestData);
-
+
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertTrue(receivedSamlAssertion.getElement() != null);
assertTrue("Assertion".equals(receivedSamlAssertion.getElement().getLocalName()));
-
+
actionResult = results.getActionResults().get(WSConstants.ENCR).get(0);
assertTrue(actionResult != null);
}
-
+
@org.junit.Test
public void testSAML2EncryptedAssertionNoSTR() throws Exception {
SAML2CallbackHandler callbackHandler = new SAML2CallbackHandler();
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example.com");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
@@ -788,16 +788,16 @@ public class SamlTokenTest extends org.j
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
wsSign.prepare(doc, samlAssertion);
-
+
// Get the Element + add it to the security header as an EncryptedAssertion
Element assertionElement = wsSign.getElement();
- Element encryptedAssertionElement =
+ Element encryptedAssertionElement =
doc.createElementNS(WSConstants.SAML2_NS, WSConstants.ENCRYPED_ASSERTION_LN);
encryptedAssertionElement.appendChild(assertionElement);
secHeader.getSecurityHeader().appendChild(encryptedAssertionElement);
-
+
// Encrypt the Assertion
KeyGenerator keygen = KeyGenerator.getInstance("AES");
keygen.init(128);
@@ -807,16 +807,16 @@ public class SamlTokenTest extends org.j
cryptoType.setAlias("wss40");
X509Certificate[] certs = crypto.getX509Certificates(cryptoType);
assertTrue(certs != null && certs.length > 0 && certs[0] != null);
-
+
encryptElement(doc, assertionElement, WSConstants.AES_128, secretKey,
WSConstants.KEYTRANSPORT_RSAOEP, certs[0], false, false);
-
+
if (LOG.isDebugEnabled()) {
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(doc);
LOG.debug(outputString);
}
-
+
RequestData data = new RequestData();
data.setDecCrypto(crypto);
List<BSPRule> ignoredRules = new ArrayList<>();
@@ -824,85 +824,85 @@ public class SamlTokenTest extends org.j
data.setIgnoredBSPRules(ignoredRules);
data.setCallbackHandler(new KeystoreCallbackHandler());
data.setValidateSamlSubjectConfirmation(false);
-
+
WSSecurityEngine newEngine = new WSSecurityEngine();
-
+
WSSConfig config = WSSConfig.getNewInstance();
config.setValidator(WSConstants.SAML_TOKEN, new CustomSamlAssertionValidator());
config.setValidator(WSConstants.SAML2_TOKEN, new CustomSamlAssertionValidator());
newEngine.setWssConfig(config);
-
+
WSHandlerResult results = newEngine.processSecurityHeader(doc, data);
-
+
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertTrue(receivedSamlAssertion.getElement() != null);
assertTrue("Assertion".equals(receivedSamlAssertion.getElement().getLocalName()));
-
+
actionResult = results.getActionResults().get(WSConstants.ENCR).get(0);
assertTrue(actionResult != null);
}
-
+
@org.junit.Test
public void testAssertionWrapper() throws Exception {
SAML1CallbackHandler callbackHandler = new SAML1CallbackHandler();
callbackHandler.setStatement(SAML1CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example.com");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
-
+
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
Document doc = dbf.newDocumentBuilder().newDocument();
String assertionString = DOM2Writer.nodeToString(samlAssertion.toDOM(doc));
-
+
// Convert String to DOM + into an assertionWrapper
InputStream in = new ByteArrayInputStream(assertionString.getBytes());
Document newDoc = dbf.newDocumentBuilder().parse(in);
-
- SamlAssertionWrapper newAssertion =
+
+ SamlAssertionWrapper newAssertion =
new SamlAssertionWrapper(newDoc.getDocumentElement());
String secondAssertionString = newAssertion.assertionToString();
assertEquals(assertionString, secondAssertionString);
}
-
+
@org.junit.Test
public void testAssertionWrapperNoDocument() throws Exception {
SAML1CallbackHandler callbackHandler = new SAML1CallbackHandler();
callbackHandler.setStatement(SAML1CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example.com");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
-
+
String assertionString = DOM2Writer.nodeToString(samlAssertion.toDOM(null));
-
+
// Convert String to DOM + into an assertionWrapper
InputStream in = new ByteArrayInputStream(assertionString.getBytes());
-
+
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
Document newDoc = dbf.newDocumentBuilder().parse(in);
-
- SamlAssertionWrapper newAssertion =
+
+ SamlAssertionWrapper newAssertion =
new SamlAssertionWrapper(newDoc.getDocumentElement());
String secondAssertionString = newAssertion.assertionToString();
assertEquals(assertionString, secondAssertionString);
}
-
+
@org.junit.Test
public void testRequiredSubjectConfirmationMethod() throws Exception {
SAML2CallbackHandler callbackHandler = new SAML2CallbackHandler();
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example.com");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
@@ -912,7 +912,7 @@ public class SamlTokenTest extends org.j
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
Document unsignedDoc = wsSign.build(doc, samlAssertion, secHeader);
WSSConfig config = WSSConfig.getNewInstance();
@@ -920,17 +920,17 @@ public class SamlTokenTest extends org.j
assertionValidator.setRequiredSubjectConfirmationMethod(SAML2Constants.CONF_SENDER_VOUCHES);
config.setValidator(WSConstants.SAML_TOKEN, assertionValidator);
config.setValidator(WSConstants.SAML2_TOKEN, assertionValidator);
-
+
WSSecurityEngine newEngine = new WSSecurityEngine();
newEngine.setWssConfig(config);
RequestData requestData = new RequestData();
requestData.setValidateSamlSubjectConfirmation(false);
-
+
newEngine.processSecurityHeader(doc, requestData);
-
+
// Now create a Bearer assertion
callbackHandler.setConfirmationMethod(SAML2Constants.CONF_BEARER);
-
+
samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
samlAssertion = new SamlAssertionWrapper(samlCallback);
@@ -940,7 +940,7 @@ public class SamlTokenTest extends org.j
doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
unsignedDoc = wsSign.build(doc, samlAssertion, secHeader);
try {
newEngine.processSecurityHeader(unsignedDoc, null, null, null);
@@ -949,14 +949,14 @@ public class SamlTokenTest extends org.j
assertTrue(ex.getErrorCode() == WSSecurityException.ErrorCode.FAILURE);
}
}
-
+
@org.junit.Test
public void testStandardSubjectConfirmationMethod() throws Exception {
SAML2CallbackHandler callbackHandler = new SAML2CallbackHandler();
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example.com");
callbackHandler.setConfirmationMethod("urn:oasis:names:tc:SAML:2.0:cm:custom");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
@@ -966,9 +966,9 @@ public class SamlTokenTest extends org.j
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
Document unsignedDoc = wsSign.build(doc, samlAssertion, secHeader);
-
+
WSSecurityEngine newEngine = new WSSecurityEngine();
try {
newEngine.processSecurityHeader(unsignedDoc, null, null, null);
@@ -983,22 +983,22 @@ public class SamlTokenTest extends org.j
assertionValidator.setRequireStandardSubjectConfirmationMethod(false);
config.setValidator(WSConstants.SAML_TOKEN, assertionValidator);
config.setValidator(WSConstants.SAML2_TOKEN, assertionValidator);
-
+
newEngine.setWssConfig(config);
-
+
RequestData requestData = new RequestData();
requestData.setValidateSamlSubjectConfirmation(false);
-
+
newEngine.processSecurityHeader(doc, requestData);
}
-
+
@org.junit.Test
public void testUnsignedBearer() throws Exception {
SAML2CallbackHandler callbackHandler = new SAML2CallbackHandler();
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example.com");
callbackHandler.setConfirmationMethod(SAML2Constants.CONF_BEARER);
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
@@ -1008,9 +1008,9 @@ public class SamlTokenTest extends org.j
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
Document unsignedDoc = wsSign.build(doc, samlAssertion, secHeader);
-
+
WSSecurityEngine newEngine = new WSSecurityEngine();
try {
newEngine.processSecurityHeader(unsignedDoc, null, null, null);
@@ -1025,35 +1025,35 @@ public class SamlTokenTest extends org.j
assertionValidator.setRequireBearerSignature(false);
config.setValidator(WSConstants.SAML_TOKEN, assertionValidator);
config.setValidator(WSConstants.SAML2_TOKEN, assertionValidator);
-
+
newEngine.setWssConfig(config);
-
+
RequestData requestData = new RequestData();
requestData.setValidateSamlSubjectConfirmation(false);
-
+
newEngine.processSecurityHeader(doc, requestData);
}
-
+
@org.junit.Test
public void testSAML2Advice() throws Exception {
// Create a "Advice" Element first
SAML2CallbackHandler callbackHandler = new SAML2CallbackHandler();
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example.com");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
-
+
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
Element adviceElement = samlAssertion.toDOM(doc);
-
+
// Now create a SAML Assertion that uses the advice Element
callbackHandler = new SAML2CallbackHandler();
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example.com");
callbackHandler.setAssertionAdviceElement(adviceElement);
-
+
samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
samlAssertion = new SamlAssertionWrapper(samlCallback);
@@ -1062,26 +1062,26 @@ public class SamlTokenTest extends org.j
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
Document unsignedDoc = wsSign.build(doc, samlAssertion, secHeader);
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(unsignedDoc);
if (LOG.isDebugEnabled()) {
LOG.debug(outputString);
}
assertTrue(outputString.contains("Advice"));
-
+
WSHandlerResult results = verify(unsignedDoc);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertFalse(receivedSamlAssertion.isSigned());
}
-
+
@org.junit.Test
public void testSAML2SpecialCharacter() throws Exception {
SAML2CallbackHandler callbackHandler = new SAML2CallbackHandler();
@@ -1114,55 +1114,55 @@ public class SamlTokenTest extends org.j
RequestData requestData = new RequestData();
requestData.setValidateSamlSubjectConfirmation(false);
-
+
WSSecurityEngine newEngine = new WSSecurityEngine();
WSHandlerResult results = newEngine.processSecurityHeader(doc, requestData);
-
+
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertFalse(receivedSamlAssertion.isSigned());
}
-
+
@org.junit.Test
public void testSAML2IssuerFormat() throws Exception {
SAML2CallbackHandler callbackHandler = new SAML2CallbackHandler();
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example.com");
callbackHandler.setIssuerFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
-
+
WSSecSAMLToken wsSign = new WSSecSAMLToken();
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
Document unsignedDoc = wsSign.build(doc, samlAssertion, secHeader);
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(unsignedDoc);
if (LOG.isDebugEnabled()) {
LOG.debug(outputString);
}
assertTrue(outputString.contains("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"));
-
+
WSHandlerResult results = createAndVerifyMessage(callbackHandler, true);
WSSecurityEngineResult actionResult =
results.getActionResults().get(WSConstants.ST_UNSIGNED).get(0);
-
+
SamlAssertionWrapper receivedSamlAssertion =
(SamlAssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(receivedSamlAssertion != null);
assertFalse(receivedSamlAssertion.isSigned());
}
-
+
private void encryptElement(
Document document,
Element elementToEncrypt,
@@ -1190,7 +1190,7 @@ public class SamlTokenTest extends org.j
);
encryptedKey.setKeyInfo(encryptedKeyKeyInfo);
}
-
+
if (useSecurityTokenReference) {
SecurityTokenReference securityTokenReference = new SecurityTokenReference(document);
securityTokenReference.addWSSENamespace();
@@ -1199,7 +1199,7 @@ public class SamlTokenTest extends org.j
} else {
X509Data x509Data = new X509Data(document);
// x509Data.addCertificate(wrappingCert);
- x509Data.addIssuerSerial(wrappingCert.getIssuerX500Principal().getName(),
+ x509Data.addIssuerSerial(wrappingCert.getIssuerX500Principal().getName(),
wrappingCert.getSerialNumber());
encryptedKeyKeyInfo.add(x509Data);
}
@@ -1220,7 +1220,7 @@ public class SamlTokenTest extends org.j
cipher.doFinal(document, elementToEncrypt, content);
}
-
+
private WSHandlerResult createAndVerifyMessage(
CallbackHandler samlCallbackHandler, boolean success
) throws Exception {
@@ -1237,7 +1237,7 @@ public class SamlTokenTest extends org.j
Document unsignedDoc = wsSign.build(doc, samlAssertion, secHeader);
if (LOG.isDebugEnabled()) {
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(unsignedDoc);
LOG.debug(outputString);
}
@@ -1258,16 +1258,16 @@ public class SamlTokenTest extends org.j
/**
* Verifies the soap envelope
* <p/>
- *
- * @param envelope
+ *
+ * @param envelope
* @throws Exception Thrown when there is a problem in verification
*/
private WSHandlerResult verify(Document doc) throws Exception {
RequestData requestData = new RequestData();
requestData.setValidateSamlSubjectConfirmation(false);
-
+
WSHandlerResult results = secEngine.processSecurityHeader(doc, requestData);
- String outputString =
+ String outputString =
XMLUtils.PrettyDocumentToString(doc);
assertTrue(outputString.indexOf("counter_port_type") > 0 ? true : false);
return results;