You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by gi...@apache.org on 2012/08/27 22:13:11 UTC

svn commit: r1377818 [1/2] - in /webservices/wss4j/trunk: ws-security-policy-stax/src/test/java/org/apache/ws/security/policy/stax/test/ ws-security-stax/src/main/java/org/apache/ws/security/stax/ext/ ws-security-stax/src/main/java/org/apache/ws/securi...

Author: giger
Date: Mon Aug 27 20:13:09 2012
New Revision: 1377818

URL: http://svn.apache.org/viewvc?rev=1377818&view=rev
Log:
correlate security events. @see SANTUARIO-326

Modified:
    webservices/wss4j/trunk/ws-security-policy-stax/src/test/java/org/apache/ws/security/policy/stax/test/AbstractPolicyTestBase.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/ext/WSSUtils.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/InboundWSSecurityContextImpl.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/BinarySecurityTokenInputHandler.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/DecryptInputProcessor.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/DerivedKeyTokenInputHandler.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/OperationInputProcessor.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/SecurityContextTokenInputHandler.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/TimestampInputHandler.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/UsernameTokenInputHandler.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/WSSSignatureInputHandler.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/WSSSignatureReferenceVerifyInputProcessor.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/BinarySecurityTokenOutputProcessor.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/DerivedKeyTokenOutputProcessor.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/EncryptOutputProcessor.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/EncryptedKeyOutputProcessor.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/SAMLTokenOutputProcessor.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/SecurityContextTokenOutputProcessor.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/HttpsSecurityToken.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SAMLSecurityToken.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SecureConversationSecurityToken.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SecurityTokenFactoryImpl.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SecurityTokenReference.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/UsernameSecurityToken.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/X509SecurityToken.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/securityEvent/HttpsTokenSecurityEvent.java
    webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/AbstractTestBase.java
    webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/DerivedKeyTokenTest.java
    webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/EncDecryptionTest.java
    webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/InboundWSSecurityContextImplTest.java
    webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/InteroperabilityTest.java
    webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/SecurityContextTokenTest.java
    webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/SignatureTest.java

Modified: webservices/wss4j/trunk/ws-security-policy-stax/src/test/java/org/apache/ws/security/policy/stax/test/AbstractPolicyTestBase.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-policy-stax/src/test/java/org/apache/ws/security/policy/stax/test/AbstractPolicyTestBase.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-policy-stax/src/test/java/org/apache/ws/security/policy/stax/test/AbstractPolicyTestBase.java (original)
+++ webservices/wss4j/trunk/ws-security-policy-stax/src/test/java/org/apache/ws/security/policy/stax/test/AbstractPolicyTestBase.java Mon Aug 27 20:13:09 2012
@@ -93,7 +93,7 @@ public class AbstractPolicyTestBase exte
             }
 
             @Override
-            public Key getSecretKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+            public Key getSecretKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage, String correlationID) throws XMLSecurityException {
                 try {
                     return keyStore.getKey(keyAlias, "default".toCharArray());
                 } catch (Exception e) {
@@ -102,7 +102,7 @@ public class AbstractPolicyTestBase exte
             }
 
             @Override
-            public PublicKey getPublicKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+            public PublicKey getPublicKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage, String correlationID) throws XMLSecurityException {
                 try {
                     return keyStore.getCertificate(keyAlias).getPublicKey();
                 } catch (Exception e) {

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/ext/WSSUtils.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/ext/WSSUtils.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/ext/WSSUtils.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/ext/WSSUtils.java Mon Aug 27 20:13:09 2012
@@ -301,7 +301,8 @@ public class WSSUtils extends XMLSecurit
         abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, WSSConstants.TAG_wsse_Reference);
     }
 
-    public static TokenSecurityEvent createTokenSecurityEvent(final SecurityToken securityToken) throws WSSecurityException {
+    public static TokenSecurityEvent createTokenSecurityEvent(final SecurityToken securityToken, String correlationID)
+            throws WSSecurityException {
         WSSConstants.TokenType tokenType = (WSSConstants.TokenType) securityToken.getTokenType();
 
         TokenSecurityEvent tokenSecurityEvent;
@@ -338,6 +339,7 @@ public class WSSUtils extends XMLSecurit
             throw new WSSecurityException(WSSecurityException.ErrorCode.UNSUPPORTED_SECURITY_TOKEN);
         }
         tokenSecurityEvent.setSecurityToken(securityToken);
+        tokenSecurityEvent.setCorrelationID(correlationID);
         return tokenSecurityEvent;
     }
 

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/InboundWSSecurityContextImpl.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/InboundWSSecurityContextImpl.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/InboundWSSecurityContextImpl.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/InboundWSSecurityContextImpl.java Mon Aug 27 20:13:09 2012
@@ -56,7 +56,7 @@ public class InboundWSSecurityContextImp
     public synchronized void registerSecurityEvent(SecurityEvent securityEvent) throws XMLSecurityException {
 
         if (operationSecurityEventOccured) {
-            if (!this.messageEncryptionTokenOccured 
+            if (!this.messageEncryptionTokenOccured
                     && (securityEvent instanceof TokenSecurityEvent)) {
                 TokenSecurityEvent tokenSecurityEvent = ((TokenSecurityEvent) securityEvent);
                 if (tokenSecurityEvent.getSecurityToken().getTokenUsages().contains(SecurityToken.TokenUsage.Encryption)) {
@@ -66,9 +66,9 @@ public class InboundWSSecurityContextImp
                         while (securityToken.getKeyWrappingToken() != null) {
                             securityToken = securityToken.getKeyWrappingToken();
                         }
-                        TokenSecurityEvent newTokenSecurityEvent = WSSUtils.createTokenSecurityEvent(securityToken);
+                        TokenSecurityEvent newTokenSecurityEvent = WSSUtils.createTokenSecurityEvent(securityToken, tokenSecurityEvent.getCorrelationID());
                         setTokenUsage(newTokenSecurityEvent, SecurityToken.TokenUsage.MainEncryption);
-                        forwardSecurityEvent(newTokenSecurityEvent);
+                        securityEvent = newTokenSecurityEvent;
                     } catch (XMLSecurityException e) {
                         throw new WSSecurityException(e.getMessage(), e);
                     }
@@ -160,7 +160,7 @@ public class InboundWSSecurityContextImp
                     securityToken = securityToken.getKeyWrappingToken();
                 }
                 if (!containsSecurityToken(supportingTokens, securityToken)) {
-                    TokenSecurityEvent newTokenSecurityEvent = WSSUtils.createTokenSecurityEvent(securityToken);
+                    TokenSecurityEvent newTokenSecurityEvent = WSSUtils.createTokenSecurityEvent(securityToken, tokenSecurityEvent.getCorrelationID());
                     supportingTokens = addTokenSecurityEvent(newTokenSecurityEvent, supportingTokens);
                     securityEventDeque.offer(newTokenSecurityEvent);
                 }

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/BinarySecurityTokenInputHandler.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/BinarySecurityTokenInputHandler.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/BinarySecurityTokenInputHandler.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/BinarySecurityTokenInputHandler.java Mon Aug 27 20:13:09 2012
@@ -112,6 +112,7 @@ public class BinarySecurityTokenInputHan
         //fire a tokenSecurityEvent
         X509TokenSecurityEvent x509TokenSecurityEvent = new X509TokenSecurityEvent();
         x509TokenSecurityEvent.setSecurityToken(securityTokenProvider.getSecurityToken());
+        x509TokenSecurityEvent.setCorrelationID(binarySecurityTokenType.getId());
         securityContext.registerSecurityEvent(x509TokenSecurityEvent);
     }
 

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/DecryptInputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/DecryptInputProcessor.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/DecryptInputProcessor.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/DecryptInputProcessor.java Mon Aug 27 20:13:09 2012
@@ -92,7 +92,7 @@ public class DecryptInputProcessor exten
     }
 
     protected void handleEncryptedContent(InputProcessorChain inputProcessorChain, XMLSecStartElement parentStartXMLEvent,
-                                          SecurityToken securityToken) throws XMLSecurityException {
+                                          SecurityToken securityToken, EncryptedDataType encryptedDataType) throws XMLSecurityException {
 
         final DocumentContext documentContext = inputProcessorChain.getDocumentContext();
         List<QName> elementPath = parentStartXMLEvent.getElementPath();
@@ -102,22 +102,24 @@ public class DecryptInputProcessor exten
                     new EncryptedPartSecurityEvent(securityToken, true, documentContext.getProtectionOrder());
             encryptedPartSecurityEvent.setElementPath(elementPath);
             encryptedPartSecurityEvent.setXmlSecEvent(parentStartXMLEvent);
+            encryptedPartSecurityEvent.setCorrelationID(encryptedDataType.getId());
             ((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(encryptedPartSecurityEvent);
         } else {
             ContentEncryptedElementSecurityEvent contentEncryptedElementSecurityEvent =
                     new ContentEncryptedElementSecurityEvent(securityToken, true, documentContext.getProtectionOrder());
             contentEncryptedElementSecurityEvent.setElementPath(elementPath);
             contentEncryptedElementSecurityEvent.setXmlSecEvent(parentStartXMLEvent);
+            contentEncryptedElementSecurityEvent.setCorrelationID(encryptedDataType.getId());
             ((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(contentEncryptedElementSecurityEvent);
         }
     }
 
     @Override
     protected AbstractDecryptedEventReaderInputProcessor newDecryptedEventReaderInputProcessor(
-            boolean encryptedHeader, XMLSecStartElement xmlSecStartElement, EncryptedDataType currentEncryptedDataType,
+            boolean encryptedHeader, XMLSecStartElement xmlSecStartElement, EncryptedDataType encryptedDataType,
             SecurityToken securityToken, SecurityContext securityContext) throws WSSecurityException {
 
-        String encryptionAlgorithm = currentEncryptedDataType.getEncryptionMethod().getAlgorithm();
+        String encryptionAlgorithm = encryptedDataType.getEncryptionMethod().getAlgorithm();
         if (!WSSConstants.NS_XENC_TRIPLE_DES.equals(encryptionAlgorithm)
                 && !WSSConstants.NS_XENC_AES128.equals(encryptionAlgorithm)
                 && !WSSConstants.NS_XENC11_AES128_GCM.equals(encryptionAlgorithm)
@@ -127,15 +129,15 @@ public class DecryptInputProcessor exten
         }
 
         return new DecryptedEventReaderInputProcessor(getSecurityProperties(),
-                SecurePart.Modifier.getModifier(currentEncryptedDataType.getType()),
-                encryptedHeader, xmlSecStartElement, this, securityToken);
+                SecurePart.Modifier.getModifier(encryptedDataType.getType()),
+                encryptedHeader, xmlSecStartElement, encryptedDataType, this, securityToken);
     }
 
     @Override
     protected void handleSecurityToken(SecurityToken securityToken, SecurityContext securityContext,
                                        EncryptedDataType encryptedDataType) throws XMLSecurityException {
         securityToken.addTokenUsage(SecurityToken.TokenUsage.Encryption);
-        TokenSecurityEvent tokenSecurityEvent = WSSUtils.createTokenSecurityEvent(securityToken);
+        TokenSecurityEvent tokenSecurityEvent = WSSUtils.createTokenSecurityEvent(securityToken, encryptedDataType.getId());
         securityContext.registerSecurityEvent(tokenSecurityEvent);
     }
     
@@ -164,15 +166,17 @@ public class DecryptInputProcessor exten
         DecryptedEventReaderInputProcessor(
                 XMLSecurityProperties securityProperties, SecurePart.Modifier encryptionModifier,
                 boolean encryptedHeader, XMLSecStartElement xmlSecStartElement,
+                EncryptedDataType encryptedDataType,
                 DecryptInputProcessor decryptInputProcessor,
                 SecurityToken securityToken
         ) {
-            super(securityProperties, encryptionModifier, encryptedHeader, xmlSecStartElement, decryptInputProcessor, securityToken);
+            super(securityProperties, encryptionModifier, encryptedHeader, xmlSecStartElement,
+                    encryptedDataType, decryptInputProcessor, securityToken);
         }
 
         @Override
         protected void handleEncryptedElement(InputProcessorChain inputProcessorChain, XMLSecStartElement xmlSecStartElement,
-                                              SecurityToken securityToken) throws XMLSecurityException {
+                                              SecurityToken securityToken, EncryptedDataType encryptedDataType) throws XMLSecurityException {
             //fire a SecurityEvent:
             final DocumentContext documentContext = inputProcessorChain.getDocumentContext();
             List<QName> elementPath = xmlSecStartElement.getElementPath();
@@ -181,12 +185,14 @@ public class DecryptInputProcessor exten
                         new EncryptedPartSecurityEvent(securityToken, true, documentContext.getProtectionOrder());
                 encryptedPartSecurityEvent.setElementPath(elementPath);
                 encryptedPartSecurityEvent.setXmlSecEvent(xmlSecStartElement);
+                encryptedPartSecurityEvent.setCorrelationID(encryptedDataType.getId());
                 ((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(encryptedPartSecurityEvent);
             } else {
                 EncryptedElementSecurityEvent encryptedElementSecurityEvent =
                         new EncryptedElementSecurityEvent(securityToken, true, documentContext.getProtectionOrder());
                 encryptedElementSecurityEvent.setElementPath(elementPath);
                 encryptedElementSecurityEvent.setXmlSecEvent(xmlSecStartElement);
+                encryptedElementSecurityEvent.setCorrelationID(encryptedDataType.getId());
                 ((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(encryptedElementSecurityEvent);
             }
         }

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/DerivedKeyTokenInputHandler.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/DerivedKeyTokenInputHandler.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/DerivedKeyTokenInputHandler.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/DerivedKeyTokenInputHandler.java Mon Aug 27 20:13:09 2012
@@ -103,7 +103,8 @@ public class DerivedKeyTokenInputHandler
                         return false;
                     }
 
-                    protected Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+                    protected Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                         String correlationID) throws XMLSecurityException {
                         byte[] secret;
                         SecurityToken referencedSecurityToken = getReferencedSecurityToken();
                         if (referencedSecurityToken != null) {
@@ -118,7 +119,7 @@ public class DerivedKeyTokenInputHandler
                                 SAMLSecurityToken samlSecurityToken = (SAMLSecurityToken) referencedSecurityToken;
                                 secret = samlSecurityToken.getSamlKeyInfo().getSecret();
                             } else {
-                                secret = referencedSecurityToken.getSecretKey(algorithmURI, keyUsage).getEncoded();
+                                secret = referencedSecurityToken.getSecretKey(algorithmURI, keyUsage, correlationID).getEncoded();
                             }
                         } else {
                             throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_CHECK, "unsupportedKeyId");
@@ -149,6 +150,7 @@ public class DerivedKeyTokenInputHandler
                         algorithmSuiteSecurityEvent.setAlgorithmURI(derivedKeyAlgorithm);
                         algorithmSuiteSecurityEvent.setKeyUsage(derivedKeyUsage);
                         algorithmSuiteSecurityEvent.setKeyLength(keyBytes.length * 8);
+                        algorithmSuiteSecurityEvent.setCorrelationID(correlationID);
                         inputProcessorChain.getSecurityContext().registerSecurityEvent(algorithmSuiteSecurityEvent);
 
                         String algo = JCEAlgorithmMapper.getJCERequiredKeyFromURI(algorithmURI);
@@ -156,7 +158,8 @@ public class DerivedKeyTokenInputHandler
                     }
 
                     @Override
-                    protected PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage)
+                    protected PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                                  String correlationID)
                             throws XMLSecurityException {
                         return null;
                     }
@@ -183,6 +186,7 @@ public class DerivedKeyTokenInputHandler
         //fire a tokenSecurityEvent
         DerivedKeyTokenSecurityEvent derivedKeyTokenSecurityEvent = new DerivedKeyTokenSecurityEvent();
         derivedKeyTokenSecurityEvent.setSecurityToken(securityTokenProvider.getSecurityToken());
+        derivedKeyTokenSecurityEvent.setCorrelationID(derivedKeyTokenType.getId());
         ((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(derivedKeyTokenSecurityEvent);
     }
 }

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/OperationInputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/OperationInputProcessor.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/OperationInputProcessor.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/OperationInputProcessor.java Mon Aug 27 20:13:09 2012
@@ -28,6 +28,7 @@ import org.apache.xml.security.stax.ext.
 import org.apache.xml.security.stax.ext.XMLSecurityProperties;
 import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
 import org.apache.xml.security.stax.ext.stax.XMLSecStartElement;
+import org.apache.xml.security.stax.impl.util.IDGenerator;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamConstants;
@@ -64,6 +65,7 @@ public class OperationInputProcessor ext
             if (elementPath.size() == 3 && WSSUtils.isInSOAPBody(elementPath)) {
                 OperationSecurityEvent operationSecurityEvent = new OperationSecurityEvent();
                 operationSecurityEvent.setOperation(xmlSecEvent.asStartElement().getName());
+                operationSecurityEvent.setCorrelationID(IDGenerator.generateID(null));
                 ((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(operationSecurityEvent);
                 inputProcessorChain.removeProcessor(this);
             }

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/SecurityContextTokenInputHandler.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/SecurityContextTokenInputHandler.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/SecurityContextTokenInputHandler.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/SecurityContextTokenInputHandler.java Mon Aug 27 20:13:09 2012
@@ -72,7 +72,8 @@ public class SecurityContextTokenInputHa
                         return false;
                     }
 
-                    public Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+                    public Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                      String correlationID) throws XMLSecurityException {
                         String algo = JCEAlgorithmMapper.translateURItoJCEID(algorithmURI);
                         WSPasswordCallback passwordCallback = new WSPasswordCallback(identifier, WSPasswordCallback.Usage.SECURITY_CONTEXT_TOKEN);
                         WSSUtils.doSecretKeyCallback(securityProperties.getCallbackHandler(), passwordCallback, null);
@@ -83,7 +84,8 @@ public class SecurityContextTokenInputHa
                     }
 
                     @Override
-                    public PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+                    public PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                               String correlationID) throws XMLSecurityException {
                         return null;
                     }
 
@@ -114,6 +116,7 @@ public class SecurityContextTokenInputHa
         //fire a tokenSecurityEvent
         SecurityContextTokenSecurityEvent securityContextTokenSecurityEvent = new SecurityContextTokenSecurityEvent();
         securityContextTokenSecurityEvent.setSecurityToken(securityTokenProvider.getSecurityToken());
+        securityContextTokenSecurityEvent.setCorrelationID(securityContextTokenType.getId());
         ((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(securityContextTokenSecurityEvent);
 
         //also register a SecurityProvider with the identifier. @see SecurityContexTest#testSCTKDKTSignAbsolute

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/TimestampInputHandler.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/TimestampInputHandler.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/TimestampInputHandler.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/TimestampInputHandler.java Mon Aug 27 20:13:09 2012
@@ -27,6 +27,7 @@ import org.apache.ws.security.stax.ext.W
 import org.apache.ws.security.stax.securityEvent.TimestampSecurityEvent;
 import org.apache.xml.security.stax.ext.*;
 import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
+import org.apache.xml.security.stax.impl.util.IDGenerator;
 
 import javax.xml.bind.JAXBElement;
 import javax.xml.datatype.DatatypeConstants;
@@ -66,6 +67,9 @@ public class TimestampInputHandler exten
         if (timestampType.getCreated() == null) {
             throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY, "missingCreated");
         }
+        if (timestampType.getId() == null) {
+            timestampType.setId(IDGenerator.generateID(null));
+        }
 
         try {
             // Validate whether the security semantics have expired
@@ -119,6 +123,7 @@ public class TimestampInputHandler exten
             TimestampSecurityEvent timestampSecurityEvent = new TimestampSecurityEvent();
             timestampSecurityEvent.setCreated(crea);
             timestampSecurityEvent.setExpires(exp);
+            timestampSecurityEvent.setCorrelationID(timestampType.getId());
             ((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(timestampSecurityEvent);
             inputProcessorChain.getSecurityContext().put(WSSConstants.PROP_TIMESTAMP_SECURITYEVENT, timestampSecurityEvent);
 
@@ -167,7 +172,7 @@ public class TimestampInputHandler exten
             }
             curIdx++;
         }
-        
+
         if (timestampType.getCreated() != null) {
             XMLGregorianCalendar createdCalendar;
             try {
@@ -191,7 +196,7 @@ public class TimestampInputHandler exten
         } else {
             securityContext.handleBSPRule(BSPRule.R3203);
         }
-        
+
         if (timestampType.getExpires() != null) {
             XMLGregorianCalendar expiresCalendar;
             try {

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/UsernameTokenInputHandler.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/UsernameTokenInputHandler.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/UsernameTokenInputHandler.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/UsernameTokenInputHandler.java Mon Aug 27 20:13:09 2012
@@ -257,6 +257,7 @@ public class UsernameTokenInputHandler e
         usernameTokenSecurityEvent.setUsernameTokenPasswordType(usernameTokenPasswordType);
         usernameTokenSecurityEvent.setSecurityToken(securityTokenProvider.getSecurityToken());
         usernameTokenSecurityEvent.setUsernameTokenProfile(WSSConstants.NS_USERNAMETOKEN_PROFILE11);
+        usernameTokenSecurityEvent.setCorrelationID(usernameTokenType.getId());
         ((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(usernameTokenSecurityEvent);
     }
 

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/WSSSignatureInputHandler.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/WSSSignatureInputHandler.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/WSSSignatureInputHandler.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/WSSSignatureInputHandler.java Mon Aug 27 20:13:09 2012
@@ -74,17 +74,18 @@ public class WSSSignatureInputHandler ex
             protected void handleSecurityToken(SecurityToken securityToken) throws XMLSecurityException {
                 //we have to emit a TokenSecurityEvent here too since it could be an embedded token
                 securityToken.addTokenUsage(SecurityToken.TokenUsage.Signature);
-                TokenSecurityEvent tokenSecurityEvent = WSSUtils.createTokenSecurityEvent(securityToken);
-                tokenSecurityEvent.setSecurityToken(securityToken);
+                TokenSecurityEvent tokenSecurityEvent = WSSUtils.createTokenSecurityEvent(securityToken, signatureType.getId());
                 securityContext.registerSecurityEvent(tokenSecurityEvent);
 
                 SignatureValueSecurityEvent signatureValueSecurityEvent = new SignatureValueSecurityEvent();
                 signatureValueSecurityEvent.setSignatureValue(signatureType.getSignatureValue().getValue());
+                signatureValueSecurityEvent.setCorrelationID(signatureType.getId());
                 securityContext.registerSecurityEvent(signatureValueSecurityEvent);
 
                 AlgorithmSuiteSecurityEvent algorithmSuiteSecurityEvent = new AlgorithmSuiteSecurityEvent();
                 algorithmSuiteSecurityEvent.setAlgorithmURI(signatureType.getSignedInfo().getCanonicalizationMethod().getAlgorithm());
                 algorithmSuiteSecurityEvent.setKeyUsage(WSSConstants.C14n);
+                algorithmSuiteSecurityEvent.setCorrelationID(signatureType.getId());
                 securityContext.registerSecurityEvent(algorithmSuiteSecurityEvent);
                 super.handleSecurityToken(securityToken);
             }

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/WSSSignatureReferenceVerifyInputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/WSSSignatureReferenceVerifyInputProcessor.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/WSSSignatureReferenceVerifyInputProcessor.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/input/WSSSignatureReferenceVerifyInputProcessor.java Mon Aug 27 20:13:09 2012
@@ -150,8 +150,8 @@ public class WSSSignatureReferenceVerify
     }
 
     @Override
-    protected void processElementPath(List<QName> elementPath,
-                                      InputProcessorChain inputProcessorChain, XMLSecEvent xmlSecEvent)
+    protected void processElementPath(List<QName> elementPath, InputProcessorChain inputProcessorChain,
+                                      XMLSecEvent xmlSecEvent, ReferenceType referenceType)
             throws XMLSecurityException {
         //fire a SecurityEvent:
         final DocumentContext documentContext = inputProcessorChain.getDocumentContext();
@@ -160,12 +160,14 @@ public class WSSSignatureReferenceVerify
                     new SignedPartSecurityEvent(getSecurityToken(), true, documentContext.getProtectionOrder());
             signedPartSecurityEvent.setElementPath(elementPath);
             signedPartSecurityEvent.setXmlSecEvent(xmlSecEvent);
+            signedPartSecurityEvent.setCorrelationID(referenceType.getId());
             ((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(signedPartSecurityEvent);
         } else {
             SignedElementSecurityEvent signedElementSecurityEvent =
                     new SignedElementSecurityEvent(getSecurityToken(), true, documentContext.getProtectionOrder());
             signedElementSecurityEvent.setElementPath(elementPath);
             signedElementSecurityEvent.setXmlSecEvent(xmlSecEvent);
+            signedElementSecurityEvent.setCorrelationID(referenceType.getId());
             ((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(signedElementSecurityEvent);
         }
     }
@@ -244,6 +246,7 @@ public class WSSSignatureReferenceVerify
             AlgorithmSuiteSecurityEvent algorithmSuiteSecurityEvent = new AlgorithmSuiteSecurityEvent();
             algorithmSuiteSecurityEvent.setAlgorithmURI(algorithm);
             algorithmSuiteSecurityEvent.setKeyUsage(WSSConstants.C14n);
+            algorithmSuiteSecurityEvent.setCorrelationID(referenceType.getId());
             ((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(algorithmSuiteSecurityEvent);
 
             InclusiveNamespaces inclusiveNamespacesType = XMLSecurityUtils.getQNameType(transformType.getContent(), XMLSecurityConstants.TAG_c14nExcl_InclusiveNamespaces);

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/BinarySecurityTokenOutputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/BinarySecurityTokenOutputProcessor.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/BinarySecurityTokenOutputProcessor.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/BinarySecurityTokenOutputProcessor.java Mon Aug 27 20:13:09 2012
@@ -109,12 +109,14 @@ public class BinarySecurityTokenOutputPr
                 }
 
                 @Override
-                public Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws WSSecurityException {
+                public Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                  String correlationID) throws WSSecurityException {
                     return key;
                 }
 
                 @Override
-                public PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws WSSecurityException {
+                public PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                           String correlationID) throws WSSecurityException {
                     return x509Certificates[0].getPublicKey();
                 }
 

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/DerivedKeyTokenOutputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/DerivedKeyTokenOutputProcessor.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/DerivedKeyTokenOutputProcessor.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/DerivedKeyTokenOutputProcessor.java Mon Aug 27 20:13:09 2012
@@ -116,7 +116,7 @@ public class DerivedKeyTokenOutputProces
                     }
                     secret = passwordCallback.getKey();
                 } else {
-                    secret = wrappingSecurityToken.getSecretKey(null, null).getEncoded();
+                    secret = wrappingSecurityToken.getSecretKey(null, null, null).getEncoded();
                 }
 
                 derivedKeyBytes = derivationAlgorithm.createKey(secret, seed, offset, length);
@@ -134,7 +134,8 @@ public class DerivedKeyTokenOutputProces
                 }
 
                 @Override
-                public Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws WSSecurityException {
+                public Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                  String correlationID) throws WSSecurityException {
                     if (keyTable.containsKey(algorithmURI)) {
                         return keyTable.get(algorithmURI);
                     } else {
@@ -146,7 +147,8 @@ public class DerivedKeyTokenOutputProces
                 }
 
                 @Override
-                public PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws WSSecurityException {
+                public PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                           String correlationID) throws WSSecurityException {
                     return null;
                 }
 

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/EncryptOutputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/EncryptOutputProcessor.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/EncryptOutputProcessor.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/EncryptOutputProcessor.java Mon Aug 27 20:13:09 2012
@@ -87,7 +87,7 @@ public class EncryptOutputProcessor exte
                         encryptionPartDef.setModifier(securePart.getModifier());
                         encryptionPartDef.setEncRefId(IDGenerator.generateID(null));
                         encryptionPartDef.setKeyId(securityTokenProvider.getId());
-                        encryptionPartDef.setSymmetricKey(securityTokenProvider.getSecurityToken().getSecretKey(getSecurityProperties().getEncryptionSymAlgorithm(), null));
+                        encryptionPartDef.setSymmetricKey(securityTokenProvider.getSecurityToken().getSecretKey(getSecurityProperties().getEncryptionSymAlgorithm(), null, null));
                         outputProcessorChain.getSecurityContext().putAsList(EncryptionPartDef.class, encryptionPartDef);
                         internalEncryptionOutputProcessor =
                                 new InternalEncryptionOutputProcessor(

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/EncryptedKeyOutputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/EncryptedKeyOutputProcessor.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/EncryptedKeyOutputProcessor.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/EncryptedKeyOutputProcessor.java Mon Aug 27 20:13:09 2012
@@ -97,11 +97,13 @@ public class EncryptedKeyOutputProcessor
                     return false;
                 }
 
-                public Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+                public Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                  String correlationID) throws XMLSecurityException {
                     return symmetricKey;
                 }
 
-                public PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+                public PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                           String correlationID) throws XMLSecurityException {
                     return null;
                 }
 
@@ -229,7 +231,7 @@ public class EncryptedKeyOutputProcessor
                         Cipher cipher = Cipher.getInstance(jceid);
                         cipher.init(Cipher.WRAP_MODE, x509Certificate);
 
-                        Key secretKey = securityToken.getSecretKey(null, null);
+                        Key secretKey = securityToken.getSecretKey(null, null, null);
 
                         int blockSize = cipher.getBlockSize();
                         if (blockSize > 0 && blockSize < secretKey.getEncoded().length) {

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/SAMLTokenOutputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/SAMLTokenOutputProcessor.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/SAMLTokenOutputProcessor.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/SAMLTokenOutputProcessor.java Mon Aug 27 20:13:09 2012
@@ -154,11 +154,13 @@ public class SAMLTokenOutputProcessor ex
                         return true;
                     }
 
-                    public Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws WSSecurityException {
+                    public Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                      String correlationID) throws WSSecurityException {
                         return secretKey;
                     }
 
-                    public PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws WSSecurityException {
+                    public PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                               String correlationID) throws WSSecurityException {
                         return x509Certificates[0].getPublicKey();
                     }
 

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/SecurityContextTokenOutputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/SecurityContextTokenOutputProcessor.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/SecurityContextTokenOutputProcessor.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/processor/output/SecurityContextTokenOutputProcessor.java Mon Aug 27 20:13:09 2012
@@ -74,13 +74,15 @@ public class SecurityContextTokenOutputP
                 }
 
                 @Override
-                public Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
-                    return wrappingSecurityToken.getSecretKey(algorithmURI, null);
+                public Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                  String correlationID) throws XMLSecurityException {
+                    return wrappingSecurityToken.getSecretKey(algorithmURI, keyUsage, correlationID);
                 }
 
                 @Override
-                public PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
-                    return wrappingSecurityToken.getPublicKey(null, null);
+                public PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                           String correlationID) throws XMLSecurityException {
+                    return wrappingSecurityToken.getPublicKey(algorithmURI, keyUsage, correlationID);
                 }
 
                 @Override

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/HttpsSecurityToken.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/HttpsSecurityToken.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/HttpsSecurityToken.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/HttpsSecurityToken.java Mon Aug 27 20:13:09 2012
@@ -70,11 +70,13 @@ public class HttpsSecurityToken extends 
         return true;
     }
 
-    protected Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws WSSecurityException {
+    protected Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                         String correlationID) throws WSSecurityException {
         return null;
     }
 
-    protected PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws WSSecurityException {
+    protected PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                  String correlationID) throws WSSecurityException {
         if (x509Certificate != null) {
             return x509Certificate.getPublicKey();
         }

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SAMLSecurityToken.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SAMLSecurityToken.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SAMLSecurityToken.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SAMLSecurityToken.java Mon Aug 27 20:13:09 2012
@@ -73,11 +73,13 @@ public class SAMLSecurityToken extends A
         return true;
     }
 
-    protected Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+    protected Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                         String correlationID) throws XMLSecurityException {
         return samlKeyInfo.getPrivateKey();
     }
 
-    protected PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+    protected PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                  String correlationID) throws XMLSecurityException {
         PublicKey publicKey = samlKeyInfo.getPublicKey();
         if (publicKey == null) {
             publicKey = getX509Certificates()[0].getPublicKey();

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SecureConversationSecurityToken.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SecureConversationSecurityToken.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SecureConversationSecurityToken.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SecureConversationSecurityToken.java Mon Aug 27 20:13:09 2012
@@ -49,11 +49,13 @@ public class SecureConversationSecurityT
         return false;
     }
 
-    protected Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+    protected Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                         String correlationID) throws XMLSecurityException {
         return null;
     }
 
-    protected PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+    protected PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                  String correlationID) throws XMLSecurityException {
         return null;
     }
 

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SecurityTokenFactoryImpl.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SecurityTokenFactoryImpl.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SecurityTokenFactoryImpl.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SecurityTokenFactoryImpl.java Mon Aug 27 20:13:09 2012
@@ -206,7 +206,7 @@ public class SecurityTokenFactoryImpl ex
                             callbackHandler, WSSConstants.WSSKeyIdentifierType.KEY_VALUE) {
                 @Override
                 public void verify() throws XMLSecurityException {
-                    crypto.verifyTrust(getPubKey("", null));
+                    crypto.verifyTrust(getPubKey("", null, null));
                 }
             };
         }
@@ -217,7 +217,7 @@ public class SecurityTokenFactoryImpl ex
                     callbackHandler, WSSConstants.WSSKeyIdentifierType.KEY_VALUE) {
                 @Override
                 public void verify() throws XMLSecurityException {
-                    crypto.verifyTrust(getPubKey("", null));
+                    crypto.verifyTrust(getPubKey("", null, null));
                 }
             };
         }
@@ -228,7 +228,7 @@ public class SecurityTokenFactoryImpl ex
                     callbackHandler, WSSConstants.WSSKeyIdentifierType.KEY_VALUE) {
                 @Override
                 public void verify() throws XMLSecurityException {
-                    crypto.verifyTrust(getPubKey("", null));
+                    crypto.verifyTrust(getPubKey("", null, null));
                 }  
             };
         }

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SecurityTokenReference.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SecurityTokenReference.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SecurityTokenReference.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/SecurityTokenReference.java Mon Aug 27 20:13:09 2012
@@ -56,12 +56,14 @@ public class SecurityTokenReference exte
         return securityToken.isAsymmetric();
     }
 
-    protected Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
-        return securityToken.getSecretKey(algorithmURI, keyUsage);
+    protected Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                         String correlationID) throws XMLSecurityException {
+        return securityToken.getSecretKey(algorithmURI, keyUsage, correlationID);
     }
 
-    protected PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
-        return securityToken.getPublicKey(algorithmURI, keyUsage);
+    protected PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                  String correlationID) throws XMLSecurityException {
+        return securityToken.getPublicKey(algorithmURI, keyUsage, correlationID);
     }
 
     public X509Certificate[] getX509Certificates() throws XMLSecurityException {

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/UsernameSecurityToken.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/UsernameSecurityToken.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/UsernameSecurityToken.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/UsernameSecurityToken.java Mon Aug 27 20:13:09 2012
@@ -112,7 +112,7 @@ public class UsernameSecurityToken exten
      *
      */
     public byte[] generateDerivedKey(String rawPassword, byte[] salt, long iteration) throws WSSecurityException {
-        
+
         if (wsSecurityContext != null) {
             if (salt == null || salt.length == 0) {
                 wsSecurityContext.handleBSPRule(BSPRule.R4217);
@@ -234,7 +234,8 @@ public class UsernameSecurityToken exten
 
     private Map<String, Key> keyTable = new Hashtable<String, Key>();
 
-    protected Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+    protected Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                         String correlationID) throws XMLSecurityException {
         byte[] secretToken;
         if (getSalt() != null && getIteration() != null) {
             byte[] salt = getSalt();
@@ -253,7 +254,8 @@ public class UsernameSecurityToken exten
         }
     }
 
-    protected PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+    protected PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                  String correlationID) throws XMLSecurityException {
         return null;
     }
 

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/X509SecurityToken.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/X509SecurityToken.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/X509SecurityToken.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/impl/securityToken/X509SecurityToken.java Mon Aug 27 20:13:09 2012
@@ -56,14 +56,16 @@ public abstract class X509SecurityToken 
     }
 
     @Override
-    public Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+    public Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                      String correlationID) throws XMLSecurityException {
         WSPasswordCallback pwCb = new WSPasswordCallback(getAlias(), WSPasswordCallback.Usage.DECRYPT);
         XMLSecurityUtils.doPasswordCallback(getCallbackHandler(), pwCb);
         return getCrypto().getPrivateKey(getAlias(), pwCb.getPassword());
     }
     
     @Override
-    public PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+    public PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                               String correlationID) throws XMLSecurityException {
         X509Certificate[] x509Certificates = getX509Certificates();
         if (x509Certificates == null || x509Certificates.length == 0) {
             return null;

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/securityEvent/HttpsTokenSecurityEvent.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/securityEvent/HttpsTokenSecurityEvent.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/securityEvent/HttpsTokenSecurityEvent.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/ws/security/stax/securityEvent/HttpsTokenSecurityEvent.java Mon Aug 27 20:13:09 2012
@@ -71,12 +71,14 @@ public class HttpsTokenSecurityEvent ext
         if (securityToken == null) {
             securityToken = new AbstractSecurityToken(null, null, null, null) {
                 @Override
-                protected Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+                protected Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                     String correlationID) throws XMLSecurityException {
                     return null;
                 }
 
                 @Override
-                protected PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+                protected PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage,
+                                              String correlationID) throws XMLSecurityException {
                     return null;
                 }
 

Modified: webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/AbstractTestBase.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/AbstractTestBase.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/AbstractTestBase.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/AbstractTestBase.java Mon Aug 27 20:13:09 2012
@@ -281,7 +281,7 @@ public abstract class AbstractTestBase {
 
         RequestData requestData = new RequestData();
         requestData.setMsgContext(messageContext);
-        
+
         // Disable PrefixList checking as the stax code doesn't support this yet
         List<BSPRule> ignoredRules = new ArrayList<BSPRule>();
         ignoredRules.add(BSPRule.R5404);
@@ -290,7 +290,7 @@ public abstract class AbstractTestBase {
         ignoredRules.add(BSPRule.R5417);
         ignoredRules.add(BSPRule.R3063);
         requestData.setIgnoredBSPRules(ignoredRules);
-        
+
         wss4JHandler.doReceiver(messageContext, requestData, false);
 
         return messageContext;
@@ -606,8 +606,29 @@ public abstract class AbstractTestBase {
             return receivedSecurityEvents;
         }
 
+        public <T> T getSecurityEvent(SecurityEventConstants.Event securityEvent) {
+            for (SecurityEvent event : receivedSecurityEvents) {
+                if (event.getSecurityEventType() == securityEvent) {
+                    return (T)event;
+                }
+            }
+            return null;
+        }
+
+        public <T> List<T> getSecurityEvents(SecurityEventConstants.Event securityEvent) {
+            List<T> foundEvents = new ArrayList<T>();
+            for (SecurityEvent event : receivedSecurityEvents) {
+                if (event.getSecurityEventType() == securityEvent) {
+                    foundEvents.add((T)event);
+                }
+            }
+            return foundEvents;
+        }
+
         @Override
         public void registerSecurityEvent(SecurityEvent securityEvent) throws WSSecurityException {
+            Assert.assertNotNull(securityEvent.getCorrelationID());
+            Assert.assertNotEquals("", securityEvent.getCorrelationID());
             receivedSecurityEvents.add(securityEvent);
         }
 

Modified: webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/DerivedKeyTokenTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/DerivedKeyTokenTest.java?rev=1377818&r1=1377817&r2=1377818&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/DerivedKeyTokenTest.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/ws/security/stax/test/DerivedKeyTokenTest.java Mon Aug 27 20:13:09 2012
@@ -27,6 +27,8 @@ import org.apache.ws.security.common.der
 import org.apache.ws.security.dom.handler.WSHandlerConstants;
 import org.apache.ws.security.dom.message.*;
 import org.apache.ws.security.dom.message.token.SecurityTokenReference;
+import org.apache.ws.security.stax.securityEvent.EncryptedPartSecurityEvent;
+import org.apache.ws.security.stax.securityEvent.OperationSecurityEvent;
 import org.apache.xml.security.stax.securityEvent.SecurityEvent;
 import org.apache.xml.security.stax.securityEvent.SecurityEventConstants;
 import org.apache.ws.security.stax.WSSec;
@@ -38,6 +40,8 @@ import org.apache.ws.security.stax.secur
 import org.apache.ws.security.stax.test.utils.SOAPUtil;
 import org.apache.ws.security.stax.test.utils.StAX2DOM;
 import org.apache.ws.security.stax.test.utils.XmlReaderToWriter;
+import org.apache.xml.security.stax.securityEvent.SignatureValueSecurityEvent;
+import org.apache.xml.security.stax.securityEvent.SignedElementSecurityEvent;
 import org.testng.Assert;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.DataProvider;
@@ -54,6 +58,7 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.security.cert.X509Certificate;
 import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @author $Author$
@@ -173,6 +178,28 @@ public class DerivedKeyTokenTest extends
             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());
         }
     }
 
@@ -664,6 +691,41 @@ public class DerivedKeyTokenTest extends
             Assert.assertEquals(nodeList.getLength(), 0);
 
             securityEventListener.compare();
+
+            EncryptedPartSecurityEvent encryptedPartSecurityEvent = securityEventListener.getSecurityEvent(WSSecurityEventConstants.EncryptedPart);
+            SignedElementSecurityEvent signedElementSecurityEvent = securityEventListener.getSecurityEvent(WSSecurityEventConstants.SignedElement);
+            SignatureValueSecurityEvent signatureValueSecurityEvent = securityEventListener.getSecurityEvent(WSSecurityEventConstants.SignatureValue);
+            OperationSecurityEvent operationSecurityEvent = securityEventListener.getSecurityEvent(WSSecurityEventConstants.Operation);
+            String encryptedPartCorrelationID = encryptedPartSecurityEvent.getCorrelationID();
+            String signedElementCorrelationID = signedElementSecurityEvent.getCorrelationID();
+            String signatureValueCorrelationID = signatureValueSecurityEvent.getCorrelationID();
+            String operationCorrelationID = operationSecurityEvent.getCorrelationID();
+
+            List<SecurityEvent> operationSecurityEvents = new ArrayList<SecurityEvent>();
+            List<SecurityEvent> encryptedPartSecurityEvents = 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(encryptedPartCorrelationID)) {
+                    encryptedPartSecurityEvents.add(securityEvent);
+                } else if (securityEvent.getCorrelationID().equals(operationCorrelationID)) {
+                    operationSecurityEvents.add(securityEvent);
+                } else if (securityEvent.getCorrelationID().equals(signedElementCorrelationID)) {
+                    signedElementSecurityEvents.add(securityEvent);
+                } else if (securityEvent.getCorrelationID().equals(signatureValueCorrelationID)) {
+                    signatureValueSecurityEvents.add(securityEvent);
+                }
+            }
+
+            org.junit.Assert.assertEquals(6, encryptedPartSecurityEvents.size());
+            org.junit.Assert.assertEquals(3, signedElementSecurityEvents.size());
+            org.junit.Assert.assertEquals(6, signatureValueSecurityEvents.size());
+            org.junit.Assert.assertEquals(securityEventListener.getReceivedSecurityEvents().size(),
+                    operationSecurityEvents.size() + encryptedPartSecurityEvents.size() +
+                            signedElementSecurityEvents.size() + signatureValueSecurityEvents.size());
         }
     }