cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r1566671 - in /cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j: ./ policyhandlers/
Date Mon, 10 Feb 2014 16:11:29 GMT
Author: coheigea
Date: Mon Feb 10 16:11:29 2014
New Revision: 1566671

URL: http://svn.apache.org/r1566671
Log:
Consolidating Attachment CallbackHandler into a single class

Added:
    cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AttachmentCallbackHandler.java
      - copied, changed from r1566648, cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AttachmentInCallbackHandler.java
Removed:
    cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AttachmentInCallbackHandler.java
    cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AttachmentOutCallbackHandler.java
Modified:
    cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java
    cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JOutInterceptor.java
    cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java
    cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxOutInterceptor.java
    cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractBindingBuilder.java
    cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AsymmetricBindingHandler.java
    cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/SymmetricBindingHandler.java

Copied: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AttachmentCallbackHandler.java
(from r1566648, cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AttachmentInCallbackHandler.java)
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AttachmentCallbackHandler.java?p2=cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AttachmentCallbackHandler.java&p1=cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AttachmentInCallbackHandler.java&r1=1566648&r2=1566671&rev=1566671&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AttachmentInCallbackHandler.java
(original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AttachmentCallbackHandler.java
Mon Feb 10 16:11:29 2014
@@ -37,13 +37,13 @@ import org.apache.wss4j.common.ext.Attac
 import org.apache.wss4j.common.ext.AttachmentResultCallback;
 
 /**
- * A outbound CallbackHandler to be used to sign/encrypt SOAP Attachments.
+ * A CallbackHandler to be used to sign/encrypt SOAP Attachments.
  */
-public class AttachmentInCallbackHandler implements CallbackHandler {
+public class AttachmentCallbackHandler implements CallbackHandler {
     
     private final SoapMessage soapMessage;
     
-    public AttachmentInCallbackHandler(SoapMessage soapMessage) {
+    public AttachmentCallbackHandler(SoapMessage soapMessage) {
         this.soapMessage = soapMessage;
     }
 
@@ -57,36 +57,13 @@ public class AttachmentInCallbackHandler
                 List<org.apache.wss4j.common.ext.Attachment> attachmentList =
                     new ArrayList<org.apache.wss4j.common.ext.Attachment>();
                 attachmentRequestCallback.setAttachments(attachmentList);
-
-                org.apache.cxf.message.Attachment attachment = null;
-
-                final Collection<org.apache.cxf.message.Attachment> attachments = 
-                    soapMessage.getAttachments();
-                // Calling LazyAttachmentCollection.size() here to force it to load the attachments
-                if (attachments.size() > 0) {
-                    for (Iterator<org.apache.cxf.message.Attachment> iterator = attachments.iterator();

-                        iterator.hasNext();) {
-                        attachment = iterator.next();
-    
-                        if (!attachmentRequestCallback.getAttachmentId().equals(attachment.getId()))
{
-                            continue;
-                        }
-    
-                        org.apache.wss4j.common.ext.Attachment att =
-                            new org.apache.wss4j.common.ext.Attachment();
-                        att.setMimeType(attachment.getDataHandler().getContentType());
-                        att.setId(attachment.getId());
-                        att.setSourceStream(attachment.getDataHandler().getInputStream());
-                        Iterator<String> headerIterator = attachment.getHeaderNames();
-                        while (headerIterator.hasNext()) {
-                            String next = headerIterator.next();
-                            att.addHeader(next, attachment.getHeader(next));
-                        }
-                        attachmentList.add(att);
-    
-                        iterator.remove();
-                    }
+                
+                String attachmentId = attachmentRequestCallback.getAttachmentId();
+                if ("Attachments".equals(attachmentId)) {
+                    // Load all attachments
+                    attachmentId = null;
                 }
+                loadAttachments(attachmentList, attachmentId);
             } else if (callback instanceof AttachmentResultCallback) {
                 AttachmentResultCallback attachmentResultCallback = (AttachmentResultCallback)
callback;
 
@@ -115,5 +92,36 @@ public class AttachmentInCallbackHandler
         }
     }
 
+    private void loadAttachments(
+        List<org.apache.wss4j.common.ext.Attachment> attachmentList,
+        String attachmentId
+    ) throws IOException {
+        final Collection<org.apache.cxf.message.Attachment> attachments = soapMessage.getAttachments();
+        // Calling LazyAttachmentCollection.size() here to force it to load the attachments
+        if (attachments != null && attachments.size() > 0) {
+            for (Iterator<org.apache.cxf.message.Attachment> iterator = attachments.iterator();

+                iterator.hasNext();) {
+                org.apache.cxf.message.Attachment attachment = iterator.next();
+
+                if (attachmentId != null && !attachmentId.equals(attachment.getId()))
{
+                    continue;
+                }
+
+                org.apache.wss4j.common.ext.Attachment att =
+                    new org.apache.wss4j.common.ext.Attachment();
+                att.setMimeType(attachment.getDataHandler().getContentType());
+                att.setId(attachment.getId());
+                att.setSourceStream(attachment.getDataHandler().getInputStream());
+                Iterator<String> headerIterator = attachment.getHeaderNames();
+                while (headerIterator.hasNext()) {
+                    String next = headerIterator.next();
+                    att.addHeader(next, attachment.getHeader(next));
+                }
+                attachmentList.add(att);
+
+                iterator.remove();
+            }
+        }
+    }
 
 }

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java?rev=1566671&r1=1566670&r2=1566671&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java
(original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java
Mon Feb 10 16:11:29 2014
@@ -213,7 +213,7 @@ public class WSS4JInInterceptor extends 
          */
         try {
             reqData.setMsgContext(msg);
-            reqData.setAttachmentCallbackHandler(new AttachmentInCallbackHandler(msg));
+            reqData.setAttachmentCallbackHandler(new AttachmentCallbackHandler(msg));
             
             setAlgorithmSuites(msg, reqData);
             

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JOutInterceptor.java?rev=1566671&r1=1566670&r2=1566671&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JOutInterceptor.java
(original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JOutInterceptor.java
Mon Feb 10 16:11:29 2014
@@ -156,7 +156,7 @@ public class WSS4JOutInterceptor extends
             translateProperties(mc);
     
             reqData.setMsgContext(mc);
-            reqData.setAttachmentCallbackHandler(new AttachmentOutCallbackHandler(mc));
+            reqData.setAttachmentCallbackHandler(new AttachmentCallbackHandler(mc));
             
             /*
              * The overall try, just to have a finally at the end to perform some

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java?rev=1566671&r1=1566670&r2=1566671&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java
(original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java
Mon Feb 10 16:11:29 2014
@@ -118,7 +118,7 @@ public class WSS4JStaxInInterceptor exte
             }
             
             if (secProps.getAttachmentCallbackHandler() == null) {
-                secProps.setAttachmentCallbackHandler(new AttachmentInCallbackHandler(soapMessage));
+                secProps.setAttachmentCallbackHandler(new AttachmentCallbackHandler(soapMessage));
             }
             
             TokenStoreCallbackHandler callbackHandler = 

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxOutInterceptor.java?rev=1566671&r1=1566670&r2=1566671&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxOutInterceptor.java
(original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxOutInterceptor.java
Mon Feb 10 16:11:29 2014
@@ -139,7 +139,7 @@ public class WSS4JStaxOutInterceptor ext
             }
             
             if (secProps.getAttachmentCallbackHandler() == null) {
-                secProps.setAttachmentCallbackHandler(new AttachmentOutCallbackHandler(mc));
+                secProps.setAttachmentCallbackHandler(new AttachmentCallbackHandler(mc));
             }
             
             SecurityEventListener securityEventListener = 

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractBindingBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractBindingBuilder.java?rev=1566671&r1=1566670&r2=1566671&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractBindingBuilder.java
(original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractBindingBuilder.java
Mon Feb 10 16:11:29 2014
@@ -72,7 +72,7 @@ import org.apache.cxf.ws.policy.PolicyCo
 import org.apache.cxf.ws.security.SecurityConstants;
 import org.apache.cxf.ws.security.tokenstore.SecurityToken;
 import org.apache.cxf.ws.security.tokenstore.TokenStore;
-import org.apache.cxf.ws.security.wss4j.AttachmentOutCallbackHandler;
+import org.apache.cxf.ws.security.wss4j.AttachmentCallbackHandler;
 import org.apache.cxf.ws.security.wss4j.WSS4JUtils;
 import org.apache.cxf.wsdl.WSDLConstants;
 import org.apache.neethi.Assertion;
@@ -1647,7 +1647,7 @@ public abstract class AbstractBindingBui
         AbstractTokenWrapper wrapper, AbstractToken token, boolean attached, boolean endorse
     ) throws WSSecurityException {
         WSSecSignature sig = new WSSecSignature(wssConfig);
-        sig.setAttachmentCallbackHandler(new AttachmentOutCallbackHandler(message));
+        sig.setAttachmentCallbackHandler(new AttachmentCallbackHandler(message));
         checkForX509PkiPath(sig, token);
         if (token instanceof IssuedToken || token instanceof SamlToken) {
             assertPolicy(token);

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AsymmetricBindingHandler.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AsymmetricBindingHandler.java?rev=1566671&r1=1566670&r2=1566671&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AsymmetricBindingHandler.java
(original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AsymmetricBindingHandler.java
Mon Feb 10 16:11:29 2014
@@ -41,7 +41,7 @@ import org.apache.cxf.ws.policy.Assertio
 import org.apache.cxf.ws.policy.AssertionInfoMap;
 import org.apache.cxf.ws.security.SecurityConstants;
 import org.apache.cxf.ws.security.tokenstore.SecurityToken;
-import org.apache.cxf.ws.security.wss4j.AttachmentOutCallbackHandler;
+import org.apache.cxf.ws.security.wss4j.AttachmentCallbackHandler;
 import org.apache.wss4j.common.WSEncryptionPart;
 import org.apache.wss4j.common.crypto.Crypto;
 import org.apache.wss4j.common.ext.WSSecurityException;
@@ -473,7 +473,7 @@ public class AsymmetricBindingHandler ex
             } else {
                 try {
                     WSSecEncrypt encr = new WSSecEncrypt(wssConfig);
-                    encr.setAttachmentCallbackHandler(new AttachmentOutCallbackHandler(message));
+                    encr.setAttachmentCallbackHandler(new AttachmentCallbackHandler(message));
                     
                     encr.setDocument(saaj.getSOAPPart());
                     Crypto crypto = getEncryptionCrypto(recToken);

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/SymmetricBindingHandler.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/SymmetricBindingHandler.java?rev=1566671&r1=1566670&r2=1566671&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/SymmetricBindingHandler.java
(original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/SymmetricBindingHandler.java
Mon Feb 10 16:11:29 2014
@@ -40,7 +40,7 @@ import org.apache.cxf.ws.policy.Assertio
 import org.apache.cxf.ws.security.SecurityConstants;
 import org.apache.cxf.ws.security.tokenstore.SecurityToken;
 import org.apache.cxf.ws.security.tokenstore.TokenStore;
-import org.apache.cxf.ws.security.wss4j.AttachmentOutCallbackHandler;
+import org.apache.cxf.ws.security.wss4j.AttachmentCallbackHandler;
 import org.apache.wss4j.common.WSEncryptionPart;
 import org.apache.wss4j.common.crypto.Crypto;
 import org.apache.wss4j.common.derivedKey.ConversationConstants;
@@ -511,7 +511,7 @@ public class SymmetricBindingHandler ext
             } else {
                 try {
                     WSSecEncrypt encr = new WSSecEncrypt(wssConfig);
-                    encr.setAttachmentCallbackHandler(new AttachmentOutCallbackHandler(message));
+                    encr.setAttachmentCallbackHandler(new AttachmentCallbackHandler(message));
                     String encrTokId = encrTok.getId();
                     if (attached) {
                         encrTokId = encrTok.getWsuId();
@@ -752,7 +752,7 @@ public class SymmetricBindingHandler ext
             return doSignatureDK(sigs, policyAbstractTokenWrapper, policyToken, tok, included);
         } else {
             WSSecSignature sig = new WSSecSignature(wssConfig);
-            sig.setAttachmentCallbackHandler(new AttachmentOutCallbackHandler(message));
+            sig.setAttachmentCallbackHandler(new AttachmentCallbackHandler(message));
             // If a EncryptedKeyToken is used, set the correct value type to
             // be used in the wsse:Reference in ds:KeyInfo
             int type = included ? WSConstants.CUSTOM_SYMM_SIGNING 



Mime
View raw message