Author: coheigea
Date: Tue Feb 11 11:48:09 2014
New Revision: 1567069
URL: http://svn.apache.org/r1567069
Log:
Added more derived interop tests
Modified:
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/action/EncryptionDerivedAction.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/action/SignatureDerivedAction.java
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/util/WSSecurityUtil.java
webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java
webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/DerivedKeyTokenTest.java
webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SecurityContextTokenTest.java
Modified:
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/action/EncryptionDerivedAction.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/action/EncryptionDerivedAction.java?rev=1567069&r1=1567068&r2=1567069&view=diff
==============================================================================
---
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/action/EncryptionDerivedAction.java
(original)
+++
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/action/EncryptionDerivedAction.java
Tue Feb 11 11:48:09 2014
@@ -93,7 +93,6 @@ public class EncryptionDerivedAction imp
wsEncrypt.setCustomValueType(WSConstants.WSC_SCT);
}
- wsEncrypt.setTokenIdDirectId(true);
wsEncrypt.setExternalKey(passwordCallback.getKey(), sctId);
} else {
Modified:
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/action/SignatureDerivedAction.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/action/SignatureDerivedAction.java?rev=1567069&r1=1567068&r2=1567069&view=diff
==============================================================================
---
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/action/SignatureDerivedAction.java
(original)
+++
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/action/SignatureDerivedAction.java
Tue Feb 11 11:48:09 2014
@@ -111,7 +111,6 @@ public class SignatureDerivedAction impl
wsSign.setCustomValueType(WSConstants.WSC_SCT);
}
- wsSign.setTokenIdDirectId(true);
wsSign.setExternalKey(passwordCallback.getKey(), sctId);
} else {
Modified:
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/util/WSSecurityUtil.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/util/WSSecurityUtil.java?rev=1567069&r1=1567068&r2=1567069&view=diff
==============================================================================
---
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/util/WSSecurityUtil.java
(original)
+++
webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/util/WSSecurityUtil.java
Tue Feb 11 11:48:09 2014
@@ -929,6 +929,8 @@ public final class WSSecurityUtil {
actions.add(WSConstants.DKT_SIGN);
} else if (single[i].equals(WSHandlerConstants.ENCRYPT)) {
actions.add(WSConstants.ENCR);
+ } else if (single[i].equals(WSHandlerConstants.ENCRYPT_DERIVED)) {
+ actions.add(WSConstants.DKT_ENCR);
} else if
(single[i].equals(WSHandlerConstants.SAML_TOKEN_UNSIGNED)) {
actions.add(WSConstants.ST_UNSIGNED);
} else if (single[i].equals(WSHandlerConstants.SAML_TOKEN_SIGNED))
{
@@ -977,6 +979,8 @@ public final class WSSecurityUtil {
actions.add(new HandlerAction(WSConstants.DKT_SIGN));
} else if (single[i].equals(WSHandlerConstants.ENCRYPT)) {
actions.add(new HandlerAction(WSConstants.ENCR));
+ } else if (single[i].equals(WSHandlerConstants.ENCRYPT_DERIVED)) {
+ actions.add(new HandlerAction(WSConstants.DKT_ENCR));
} else if
(single[i].equals(WSHandlerConstants.SAML_TOKEN_UNSIGNED)) {
actions.add(new HandlerAction(WSConstants.ST_UNSIGNED));
} else if (single[i].equals(WSHandlerConstants.SAML_TOKEN_SIGNED))
{
Modified:
webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java?rev=1567069&r1=1567068&r2=1567069&view=diff
==============================================================================
---
webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java
(original)
+++
webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java
Tue Feb 11 11:48:09 2014
@@ -213,7 +213,9 @@ public abstract class AbstractTestBase e
RequestData requestData = new RequestData();
requestData.setMsgContext(messageContext);
- requestData.setCallbackHandler(new WSS4JCallbackHandlerImpl());
+ if (messageContext.get(WSHandlerConstants.PW_CALLBACK_REF) == null) {
+ requestData.setCallbackHandler(new WSS4JCallbackHandlerImpl());
+ }
requestData.setWssConfig(WSSConfig.getNewInstance());
wss4JHandler.doSender(messageContext, requestData, true);
Modified:
webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/DerivedKeyTokenTest.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/DerivedKeyTokenTest.java?rev=1567069&r1=1567068&r2=1567069&view=diff
==============================================================================
---
webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/DerivedKeyTokenTest.java
(original)
+++
webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/DerivedKeyTokenTest.java
Tue Feb 11 11:48:09 2014
@@ -212,6 +212,83 @@ public class DerivedKeyTokenTest extends
org.junit.Assert.assertEquals(securityEventListener.getReceivedSecurityEvents().size(),
operationSecurityEvents.size() + encryptedPartSecurityEvents.size());
}
}
+
+ @Test
+ public void testEncryptionDecryptionTRIPLEDESInboundAction() throws
Exception {
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ {
+ InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml");
+ String action = WSHandlerConstants.ENCRYPT_DERIVED;
+
+ Properties properties = new Properties();
+ properties.put(WSHandlerConstants.DERIVED_TOKEN_REFERENCE,
"EncryptedKey");
+ if (version == ConversationConstants.VERSION_05_02) {
+ properties.put(WSHandlerConstants.USE_2005_12_NAMESPACE,
"false");
+ }
+ properties.put(WSHandlerConstants.USER, "receiver");
+ properties.put(WSHandlerConstants.ENC_SYM_ALGO,
+ "http://www.w3.org/2001/04/xmlenc#tripledes-cbc");
+ Document securedDocument =
doOutboundSecurityWithWSS4J(sourceDocument, action, properties);
+
+ //some test that we can really sure we get what we want from WSS4J
+ NodeList nodeList =
securedDocument.getElementsByTagNameNS(WSSConstants.TAG_xenc_EncryptedData.getNamespaceURI(),
WSSConstants.TAG_xenc_EncryptedData.getLocalPart());
+
Assert.assertEquals(nodeList.item(0).getParentNode().getLocalName(),
WSSConstants.TAG_soap11_Body.getLocalPart());
+
+ javax.xml.transform.Transformer transformer =
TRANSFORMER_FACTORY.newTransformer();
+ transformer.transform(new DOMSource(securedDocument), new
StreamResult(baos));
+ }
+
+ {
+ WSSSecurityProperties securityProperties = new
WSSSecurityProperties();
+
securityProperties.loadDecryptionKeystore(this.getClass().getClassLoader().getResource("receiver.jks"),
"default".toCharArray());
+ securityProperties.setCallbackHandler(new CallbackHandlerImpl());
+ InboundWSSec wsSecIn = WSSec.getInboundWSSec(securityProperties);
+
+ SecurityEventConstants.Event[] expectedSecurityEvents = new
SecurityEventConstants.Event[]{
+ WSSecurityEventConstants.AlgorithmSuite,
+ WSSecurityEventConstants.AlgorithmSuite,
+ WSSecurityEventConstants.AlgorithmSuite,
+ WSSecurityEventConstants.AlgorithmSuite,
+ WSSecurityEventConstants.X509Token,
+ WSSecurityEventConstants.EncryptedPart,
+ WSSecurityEventConstants.Operation,
+ };
+ final TestSecurityEventListener securityEventListener = new
TestSecurityEventListener(expectedSecurityEvents);
+ XMLStreamReader xmlStreamReader = wsSecIn.processInMessage(
+ xmlInputFactory.createXMLStreamReader(
+ new ByteArrayInputStream(baos.toByteArray())),
null, securityEventListener);
+
+ Document document =
StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), xmlStreamReader);
+
+ NodeList nodeList =
document.getElementsByTagNameNS(WSSConstants.TAG_xenc_EncryptedData.getNamespaceURI(),
WSSConstants.TAG_xenc_EncryptedData.getLocalPart());
+ Assert.assertEquals(nodeList.getLength(), 0);
+
+ securityEventListener.compare();
+
+ EncryptedPartSecurityEvent encryptedPartSecurityEvent =
securityEventListener.getSecurityEvent(WSSecurityEventConstants.EncryptedPart);
+ OperationSecurityEvent operationSecurityEvent =
securityEventListener.getSecurityEvent(WSSecurityEventConstants.Operation);
+ String encryptedPartCorrelationID =
encryptedPartSecurityEvent.getCorrelationID();
+ String operationCorrelationID =
operationSecurityEvent.getCorrelationID();
+
+ List<SecurityEvent> operationSecurityEvents = new
ArrayList<SecurityEvent>();
+ List<SecurityEvent> encryptedPartSecurityEvents = new
ArrayList<SecurityEvent>();
+
+ List<SecurityEvent> securityEvents =
securityEventListener.getReceivedSecurityEvents();
+ for (int i = 0; i < securityEvents.size(); i++) {
+ SecurityEvent securityEvent = securityEvents.get(i);
+ if
(securityEvent.getCorrelationID().equals(encryptedPartCorrelationID)) {
+ encryptedPartSecurityEvents.add(securityEvent);
+ } else if
(securityEvent.getCorrelationID().equals(operationCorrelationID)) {
+ operationSecurityEvents.add(securityEvent);
+ }
+ }
+
+ org.junit.Assert.assertEquals(6,
encryptedPartSecurityEvents.size());
+ org.junit.Assert.assertEquals(1, operationSecurityEvents.size());
+
org.junit.Assert.assertEquals(securityEventListener.getReceivedSecurityEvents().size(),
operationSecurityEvents.size() + encryptedPartSecurityEvents.size());
+ }
+ }
@Test
public void testEncryptionDecryptionAES128Outbound() throws Exception {
@@ -298,6 +375,46 @@ public class DerivedKeyTokenTest extends
Assert.assertEquals(nodeList.getLength(), 0);
}
}
+
+ @Test
+ public void testEncryptionDecryptionAES128InboundAction() throws Exception
{
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ {
+ InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml");
+ String action = WSHandlerConstants.ENCRYPT_DERIVED;
+
+ Properties properties = new Properties();
+ properties.put(WSHandlerConstants.DERIVED_TOKEN_REFERENCE,
"EncryptedKey");
+ if (version == ConversationConstants.VERSION_05_02) {
+ properties.put(WSHandlerConstants.USE_2005_12_NAMESPACE,
"false");
+ }
+ properties.put(WSHandlerConstants.USER, "receiver");
+ properties.put(WSHandlerConstants.ENC_SYM_ALGO,
+ "http://www.w3.org/2001/04/xmlenc#aes128-cbc");
+ Document securedDocument =
doOutboundSecurityWithWSS4J(sourceDocument, action, properties);
+
+ //some test that we can really sure we get what we want from WSS4J
+ NodeList nodeList =
securedDocument.getElementsByTagNameNS(WSSConstants.TAG_xenc_EncryptedData.getNamespaceURI(),
WSSConstants.TAG_xenc_EncryptedData.getLocalPart());
+
Assert.assertEquals(nodeList.item(0).getParentNode().getLocalName(),
WSSConstants.TAG_soap11_Body.getLocalPart());
+
+ javax.xml.transform.Transformer transformer =
TRANSFORMER_FACTORY.newTransformer();
+ transformer.transform(new DOMSource(securedDocument), new
StreamResult(baos));
+ }
+
+ {
+ WSSSecurityProperties securityProperties = new
WSSSecurityProperties();
+
securityProperties.loadDecryptionKeystore(this.getClass().getClassLoader().getResource("receiver.jks"),
"default".toCharArray());
+ securityProperties.setCallbackHandler(new CallbackHandlerImpl());
+ InboundWSSec wsSecIn = WSSec.getInboundWSSec(securityProperties);
+ XMLStreamReader xmlStreamReader =
wsSecIn.processInMessage(xmlInputFactory.createXMLStreamReader(new
ByteArrayInputStream(baos.toByteArray())));
+
+ Document document =
StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), xmlStreamReader);
+
+ NodeList nodeList =
document.getElementsByTagNameNS(WSSConstants.TAG_xenc_EncryptedData.getNamespaceURI(),
WSSConstants.TAG_xenc_EncryptedData.getLocalPart());
+ Assert.assertEquals(nodeList.getLength(), 0);
+ }
+ }
@Test
public void testSignatureOutbound() throws Exception {
Modified:
webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SecurityContextTokenTest.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SecurityContextTokenTest.java?rev=1567069&r1=1567068&r2=1567069&view=diff
==============================================================================
---
webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SecurityContextTokenTest.java
(original)
+++
webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SecurityContextTokenTest.java
Tue Feb 11 11:48:09 2014
@@ -31,12 +31,14 @@ import org.apache.wss4j.stax.securityEve
import org.apache.wss4j.stax.securityEvent.OperationSecurityEvent;
import org.apache.wss4j.stax.securityEvent.SignedPartSecurityEvent;
import org.apache.xml.security.stax.securityEvent.SecurityEvent;
+import org.apache.xml.security.stax.securityEvent.SecurityEventConstants;
import org.apache.wss4j.stax.WSSec;
import org.apache.wss4j.stax.ext.InboundWSSec;
import org.apache.wss4j.stax.ext.OutboundWSSec;
import org.apache.wss4j.stax.ext.WSSConstants;
import org.apache.wss4j.stax.ext.WSSSecurityProperties;
import org.apache.wss4j.stax.securityEvent.WSSecurityEventConstants;
+import org.apache.wss4j.stax.test.AbstractTestBase.TestSecurityEventListener;
import org.apache.wss4j.stax.test.utils.SOAPUtil;
import org.apache.wss4j.stax.test.utils.SecretKeyCallbackHandler;
import org.apache.wss4j.stax.test.utils.StAX2DOM;
@@ -58,6 +60,7 @@ import javax.xml.transform.stream.Stream
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -215,6 +218,87 @@ public class SecurityContextTokenTest ex
);
}
}
+
+ @Test
+ public void testSCTDKTEncryptInboundAction() throws Exception {
+
+ byte[] tempSecret = WSSecurityUtil.generateNonce(16);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ {
+ InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml");
+ String action = WSHandlerConstants.ENCRYPT_DERIVED;
+
+ Properties properties = new Properties();
+ CallbackHandlerImpl callbackHandler = new
CallbackHandlerImpl(tempSecret);
+ properties.put(WSHandlerConstants.PW_CALLBACK_REF,
callbackHandler);
+ properties.put(WSHandlerConstants.DERIVED_TOKEN_REFERENCE,
"SecurityContextToken");
+ if (version == ConversationConstants.VERSION_05_02) {
+ properties.put(WSHandlerConstants.USE_2005_12_NAMESPACE,
"false");
+ }
+ properties.put(WSHandlerConstants.USER, "receiver");
+ properties.put(WSHandlerConstants.ENC_SYM_ALGO,
+ "http://www.w3.org/2001/04/xmlenc#aes128-cbc");
+ Document securedDocument =
doOutboundSecurityWithWSS4J(sourceDocument, action, properties);
+
+ //some test that we can really sure we get what we want from WSS4J
+ NodeList nodeList =
securedDocument.getElementsByTagNameNS(WSSConstants.TAG_xenc_EncryptedData.getNamespaceURI(),
WSSConstants.TAG_xenc_EncryptedData.getLocalPart());
+
Assert.assertEquals(nodeList.item(0).getParentNode().getLocalName(),
WSSConstants.TAG_soap11_Body.getLocalPart());
+
+ javax.xml.transform.Transformer transformer =
TRANSFORMER_FACTORY.newTransformer();
+ transformer.transform(new DOMSource(securedDocument), new
StreamResult(baos));
+ }
+
+ {
+ WSSSecurityProperties securityProperties = new
WSSSecurityProperties();
+
securityProperties.loadDecryptionKeystore(this.getClass().getClassLoader().getResource("receiver.jks"),
"default".toCharArray());
+ CallbackHandlerImpl callbackHandler = new
CallbackHandlerImpl(tempSecret);
+ securityProperties.setCallbackHandler(callbackHandler);
+ InboundWSSec wsSecIn = WSSec.getInboundWSSec(securityProperties);
+
+ WSSecurityEventConstants.Event[] expectedSecurityEvents = new
WSSecurityEventConstants.Event[]{
+ WSSecurityEventConstants.AlgorithmSuite,
+ WSSecurityEventConstants.AlgorithmSuite,
+ WSSecurityEventConstants.AlgorithmSuite,
+ WSSecurityEventConstants.SecurityContextToken,
+ WSSecurityEventConstants.EncryptedPart,
+ WSSecurityEventConstants.Operation,
+ };
+ final TestSecurityEventListener securityEventListener = new
TestSecurityEventListener(expectedSecurityEvents);
+
+ XMLStreamReader xmlStreamReader =
wsSecIn.processInMessage(xmlInputFactory.createXMLStreamReader(new
ByteArrayInputStream(baos.toByteArray())), null, securityEventListener);
+
+ Document document =
StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), xmlStreamReader);
+
+ NodeList nodeList =
document.getElementsByTagNameNS(WSSConstants.TAG_xenc_EncryptedData.getNamespaceURI(),
WSSConstants.TAG_xenc_EncryptedData.getLocalPart());
+ Assert.assertEquals(nodeList.getLength(), 0);
+
+ securityEventListener.compare();
+
+ EncryptedPartSecurityEvent encryptedPartSecurityEvent =
securityEventListener.getSecurityEvent(WSSecurityEventConstants.EncryptedPart);
+ OperationSecurityEvent operationSecurityEvent =
securityEventListener.getSecurityEvent(WSSecurityEventConstants.Operation);
+ String encryptedPartCorrelationID =
encryptedPartSecurityEvent.getCorrelationID();
+ String operationCorrelationID =
operationSecurityEvent.getCorrelationID();
+
+ List<SecurityEvent> operationSecurityEvents = new
ArrayList<SecurityEvent>();
+ List<SecurityEvent> encryptedPartSecurityEvents = new
ArrayList<SecurityEvent>();
+
+ List<SecurityEvent> securityEvents =
securityEventListener.getReceivedSecurityEvents();
+ for (int i = 0; i < securityEvents.size(); i++) {
+ SecurityEvent securityEvent = securityEvents.get(i);
+ if
(securityEvent.getCorrelationID().equals(encryptedPartCorrelationID)) {
+ encryptedPartSecurityEvents.add(securityEvent);
+ } else if
(securityEvent.getCorrelationID().equals(operationCorrelationID)) {
+ operationSecurityEvents.add(securityEvent);
+ }
+ }
+
+ org.junit.Assert.assertEquals(5,
encryptedPartSecurityEvents.size());
+
org.junit.Assert.assertEquals(securityEventListener.getReceivedSecurityEvents().size(),
+ operationSecurityEvents.size() +
+ encryptedPartSecurityEvents.size()
+ );
+ }
+ }
@Test
public void testSCTKDKTSignOutbound() throws Exception {
@@ -354,6 +438,95 @@ public class SecurityContextTokenTest ex
}
@Test
+ public void testSCTKDKTSignInboundAction() throws Exception {
+
+ byte[] tempSecret = WSSecurityUtil.generateNonce(16);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ {
+ InputStream sourceDocument =
this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml");
+ String action = WSHandlerConstants.SIGNATURE_DERIVED;
+
+ Properties properties = new Properties();
+ CallbackHandlerImpl callbackHandler = new
CallbackHandlerImpl(tempSecret);
+ properties.put(WSHandlerConstants.PW_CALLBACK_REF,
callbackHandler);
+ properties.put(WSHandlerConstants.DERIVED_TOKEN_REFERENCE,
"SecurityContextToken");
+ if (version == ConversationConstants.VERSION_05_02) {
+ properties.put(WSHandlerConstants.USE_2005_12_NAMESPACE,
"false");
+ }
+ properties.put(WSHandlerConstants.USER, "transmitter");
+ properties.put(WSHandlerConstants.ENC_SYM_ALGO,
+ "http://www.w3.org/2001/04/xmlenc#aes128-cbc");
+ Document securedDocument =
doOutboundSecurityWithWSS4J(sourceDocument, action, properties);
+
+ //some test that we can really sure we get what we want from WSS4J
+ NodeList nodeList =
securedDocument.getElementsByTagNameNS(WSSConstants.TAG_dsig_Signature.getNamespaceURI(),
WSSConstants.TAG_dsig_Signature.getLocalPart());
+ Assert.assertEquals(nodeList.getLength(), 1);
+
+ javax.xml.transform.Transformer transformer =
TRANSFORMER_FACTORY.newTransformer();
+ transformer.transform(new DOMSource(securedDocument), new
StreamResult(baos));
+ }
+
+ {
+ WSSSecurityProperties securityProperties = new
WSSSecurityProperties();
+
securityProperties.loadSignatureVerificationKeystore(this.getClass().getClassLoader().getResource("receiver.jks"),
"default".toCharArray());
+
securityProperties.loadDecryptionKeystore(this.getClass().getClassLoader().getResource("receiver.jks"),
"default".toCharArray());
+ CallbackHandlerImpl callbackHandler = new
CallbackHandlerImpl(tempSecret);
+ securityProperties.setCallbackHandler(callbackHandler);
+ InboundWSSec wsSecIn = WSSec.getInboundWSSec(securityProperties);
+
+ WSSecurityEventConstants.Event[] expectedSecurityEvents = new
WSSecurityEventConstants.Event[]{
+ WSSecurityEventConstants.AlgorithmSuite,
+ WSSecurityEventConstants.AlgorithmSuite,
+ WSSecurityEventConstants.AlgorithmSuite,
+ WSSecurityEventConstants.AlgorithmSuite,
+ WSSecurityEventConstants.AlgorithmSuite,
+ WSSecurityEventConstants.AlgorithmSuite,
+ WSSecurityEventConstants.SecurityContextToken,
+ WSSecurityEventConstants.SignatureValue,
+ WSSecurityEventConstants.SignedPart,
+ WSSecurityEventConstants.Operation,
+ };
+ final TestSecurityEventListener securityEventListener = new
TestSecurityEventListener(expectedSecurityEvents);
+
+ XMLStreamReader xmlStreamReader =
wsSecIn.processInMessage(xmlInputFactory.createXMLStreamReader(new
ByteArrayInputStream(baos.toByteArray())), null, securityEventListener);
+
+ StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(),
xmlStreamReader);
+
+ securityEventListener.compare();
+
+ SignedPartSecurityEvent signedPartSecurityEvent =
securityEventListener.getSecurityEvent(WSSecurityEventConstants.SignedPart);
+ SignatureValueSecurityEvent signatureValueSecurityEvent =
securityEventListener.getSecurityEvent(WSSecurityEventConstants.SignatureValue);
+ OperationSecurityEvent operationSecurityEvent =
securityEventListener.getSecurityEvent(WSSecurityEventConstants.Operation);
+ String signedElementCorrelationID =
signedPartSecurityEvent.getCorrelationID();
+ String signatureValueCorrelationID =
signatureValueSecurityEvent.getCorrelationID();
+ String operationCorrelationID =
operationSecurityEvent.getCorrelationID();
+
+ List<SecurityEvent> operationSecurityEvents = new
ArrayList<SecurityEvent>();
+ List<SecurityEvent> signedElementSecurityEvents = new
ArrayList<SecurityEvent>();
+ List<SecurityEvent> signatureValueSecurityEvents = new
ArrayList<SecurityEvent>();
+
+ List<SecurityEvent> securityEvents =
securityEventListener.getReceivedSecurityEvents();
+ for (int i = 0; i < securityEvents.size(); i++) {
+ SecurityEvent securityEvent = securityEvents.get(i);
+ if
(securityEvent.getCorrelationID().equals(signedElementCorrelationID)) {
+ signedElementSecurityEvents.add(securityEvent);
+ } else if
(securityEvent.getCorrelationID().equals(signatureValueCorrelationID)) {
+ signatureValueSecurityEvents.add(securityEvent);
+ } else if
(securityEvent.getCorrelationID().equals(operationCorrelationID)) {
+ operationSecurityEvents.add(securityEvent);
+ }
+ }
+
+ org.junit.Assert.assertEquals(3,
signedElementSecurityEvents.size());
+ org.junit.Assert.assertEquals(6,
signatureValueSecurityEvents.size());
+
org.junit.Assert.assertEquals(securityEventListener.getReceivedSecurityEvents().size(),
+ operationSecurityEvents.size() +
+ signedElementSecurityEvents.size() +
signatureValueSecurityEvents.size()
+ );
+ }
+ }
+
+ @Test
public void testSCTKDKTSignAbsoluteInbound() throws Exception {
byte[] tempSecret = WSSecurityUtil.generateNonce(16);