cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject git commit: More minor optimisations
Date Thu, 17 Apr 2014 16:40:14 GMT
Repository: cxf
Updated Branches:
  refs/heads/master d512d5273 -> 1bd380a4c


More minor optimisations


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/1bd380a4
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/1bd380a4
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/1bd380a4

Branch: refs/heads/master
Commit: 1bd380a4c9269ce42b635a260976855ac2a993cf
Parents: d512d52
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Thu Apr 17 17:39:47 2014 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Thu Apr 17 17:40:08 2014 +0100

----------------------------------------------------------------------
 .../policyhandlers/AbstractBindingBuilder.java  |   1 +
 .../AbstractCommonBindingHandler.java           |  34 ++---
 .../AbstractStaxBindingHandler.java             | 150 ++++++++++---------
 .../StaxAsymmetricBindingHandler.java           |   9 +-
 .../StaxSymmetricBindingHandler.java            |   9 +-
 5 files changed, 99 insertions(+), 104 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/1bd380a4/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractBindingBuilder.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractBindingBuilder.java
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractBindingBuilder.java
index 704dc09..6fbf4d7 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractBindingBuilder.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractBindingBuilder.java
@@ -390,6 +390,7 @@ public abstract class AbstractBindingBuilder extends AbstractCommonBindingHandle
         if (tokensInfos != null) {
             for (AssertionInfo assertionInfo : tokensInfos) {
                 if (assertionInfo.getAssertion() instanceof SupportingTokens) {
+                    assertionInfo.setAsserted(true);
                     handleSupportingTokens((SupportingTokens)assertionInfo.getAssertion(),
endorse, ret);
                 }
             }

http://git-wip-us.apache.org/repos/asf/cxf/blob/1bd380a4/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractCommonBindingHandler.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractCommonBindingHandler.java
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractCommonBindingHandler.java
index a8cf858..5c8250c 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractCommonBindingHandler.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractCommonBindingHandler.java
@@ -19,11 +19,9 @@
 
 package org.apache.cxf.ws.security.wss4j.policyhandlers;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -410,6 +408,22 @@ public abstract class AbstractCommonBindingHandler {
         }
     }
     
+    protected AssertionInfo getFirstAssertionByLocalname(
+        AssertionInfoMap aim, String localname
+    ) {
+        Collection<AssertionInfo> sp11Ais = aim.get(new QName(SP11Constants.SP_NS,
localname));
+        if (sp11Ais != null && !sp11Ais.isEmpty()) {
+            return sp11Ais.iterator().next();
+        }
+
+        Collection<AssertionInfo> sp12Ais = aim.get(new QName(SP12Constants.SP_NS,
localname));
+        if (sp12Ais != null && !sp12Ais.isEmpty()) {
+            return sp12Ais.iterator().next();
+        }
+
+        return null;
+    }
+    
     protected Collection<AssertionInfo> getAllAssertionsByLocalname(String localname)
{
         AssertionInfoMap aim = message.get(AssertionInfoMap.class);
         return getAllAssertionsByLocalname(aim, localname);
@@ -500,21 +514,7 @@ public abstract class AbstractCommonBindingHandler {
         }
         return st;
     }
-    
-    protected Collection<Assertion> findAndAssertPolicy(QName n) {
-        AssertionInfoMap aim = message.get(AssertionInfoMap.class);
-        Collection<AssertionInfo> ais = aim.getAssertionInfo(n);
-        if (ais != null && !ais.isEmpty()) {
-            List<Assertion> p = new ArrayList<Assertion>(ais.size());
-            for (AssertionInfo ai : ais) {
-                ai.setAsserted(true);
-                p.add(ai.getAssertion());
-            }
-            return p;
-        }
-        return null;
-    } 
-    
+   
     protected void assertPolicy(QName n) {
         AssertionInfoMap aim = message.get(AssertionInfoMap.class);
         Collection<AssertionInfo> ais = aim.getAssertionInfo(n);

http://git-wip-us.apache.org/repos/asf/cxf/blob/1bd380a4/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractStaxBindingHandler.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractStaxBindingHandler.java
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractStaxBindingHandler.java
index 14e20be..e761ef5 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractStaxBindingHandler.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/AbstractStaxBindingHandler.java
@@ -46,7 +46,6 @@ 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.tokenstore.TokenStore;
-import org.apache.neethi.Assertion;
 import org.apache.wss4j.common.ext.WSPasswordCallback;
 import org.apache.wss4j.common.ext.WSSecurityException;
 import org.apache.wss4j.common.saml.SAMLCallback;
@@ -54,8 +53,6 @@ import org.apache.wss4j.common.saml.bean.KeyInfoBean;
 import org.apache.wss4j.common.saml.bean.SubjectBean;
 import org.apache.wss4j.common.util.KeyUtils;
 import org.apache.wss4j.dom.WSConstants;
-import org.apache.wss4j.policy.SP11Constants;
-import org.apache.wss4j.policy.SP12Constants;
 import org.apache.wss4j.policy.SPConstants;
 import org.apache.wss4j.policy.SPConstants.IncludeTokenType;
 import org.apache.wss4j.policy.model.AbstractBinding;
@@ -609,15 +606,18 @@ public abstract class AbstractStaxBindingHandler extends AbstractCommonBindingHa
     }
     
     protected Map<AbstractToken, SecurePart> handleSupportingTokens(
-        Collection<Assertion> tokens, 
+        Collection<AssertionInfo> tokenAssertions, 
         boolean signed,
         boolean endorse
     ) throws Exception {
-        Map<AbstractToken, SecurePart> ret = new HashMap<AbstractToken, SecurePart>();
-        if (tokens != null) {
-            for (Assertion pa : tokens) {
-                if (pa instanceof SupportingTokens) {
-                    handleSupportingTokens((SupportingTokens)pa, signed, endorse, ret);
+        Map<AbstractToken, SecurePart> ret = null;
+        if (tokenAssertions != null) {
+            ret = new HashMap<AbstractToken, SecurePart>();
+            for (AssertionInfo assertionInfo : tokenAssertions) {
+                if (assertionInfo.getAssertion() instanceof SupportingTokens) {
+                    assertionInfo.setAsserted(true);
+                    handleSupportingTokens((SupportingTokens)assertionInfo.getAssertion(),

+                            signed, endorse, ret);
                 }
             }
         }
@@ -721,68 +721,76 @@ public abstract class AbstractStaxBindingHandler extends AbstractCommonBindingHa
     
     protected void addSupportingTokens() throws Exception {
         
-        Collection<Assertion> sgndSuppTokens = 
-            findAndAssertPolicy(SP12Constants.SIGNED_SUPPORTING_TOKENS);
-        Map<AbstractToken, SecurePart> sigSuppTokMap = 
-            this.handleSupportingTokens(sgndSuppTokens, true, false);
-        sgndSuppTokens = findAndAssertPolicy(SP11Constants.SIGNED_SUPPORTING_TOKENS);
-        sigSuppTokMap.putAll(this.handleSupportingTokens(sgndSuppTokens, true, false));
+        Collection<AssertionInfo> sgndSuppTokens = 
+            getAllAssertionsByLocalname(SPConstants.SIGNED_SUPPORTING_TOKENS);
+        if (!sgndSuppTokens.isEmpty()) {
+            Map<AbstractToken, SecurePart> sigSuppTokMap = 
+                this.handleSupportingTokens(sgndSuppTokens, true, false);
+            addSignatureParts(sigSuppTokMap);
+        }
         
-        Collection<Assertion> endSuppTokens = 
-            findAndAssertPolicy(SP12Constants.ENDORSING_SUPPORTING_TOKENS);
-        endSuppTokMap = this.handleSupportingTokens(endSuppTokens, false, true);
-        endSuppTokens = findAndAssertPolicy(SP11Constants.ENDORSING_SUPPORTING_TOKENS);
-        endSuppTokMap.putAll(this.handleSupportingTokens(endSuppTokens, false, true));
+        Collection<AssertionInfo> endSuppTokens = 
+            getAllAssertionsByLocalname(SPConstants.ENDORSING_SUPPORTING_TOKENS);
+        if (!endSuppTokens.isEmpty()) {
+            endSuppTokMap = this.handleSupportingTokens(endSuppTokens, false, true);
+        }
 
-        Collection<Assertion> sgndEndSuppTokens 
-            = findAndAssertPolicy(SP12Constants.SIGNED_ENDORSING_SUPPORTING_TOKENS);
-        sgndEndSuppTokMap = this.handleSupportingTokens(sgndEndSuppTokens, true, true);
-        sgndEndSuppTokens = findAndAssertPolicy(SP11Constants.SIGNED_ENDORSING_SUPPORTING_TOKENS);
-        sgndEndSuppTokMap.putAll(this.handleSupportingTokens(sgndEndSuppTokens, true, true));
+        Collection<AssertionInfo> sgndEndSuppTokens 
+            = getAllAssertionsByLocalname(SPConstants.SIGNED_ENDORSING_SUPPORTING_TOKENS);
+        if (!sgndEndSuppTokens.isEmpty()) {
+            sgndEndSuppTokMap = this.handleSupportingTokens(sgndEndSuppTokens, true, true);
+            addSignatureParts(sgndEndSuppTokMap);
+        }
         
-        Collection<Assertion> sgndEncryptedSuppTokens 
-            = findAndAssertPolicy(SP12Constants.SIGNED_ENCRYPTED_SUPPORTING_TOKENS);
-        Map<AbstractToken, SecurePart> sgndEncSuppTokMap = 
-            this.handleSupportingTokens(sgndEncryptedSuppTokens, true, false);
+        Collection<AssertionInfo> sgndEncryptedSuppTokens 
+            = getAllAssertionsByLocalname(SPConstants.SIGNED_ENCRYPTED_SUPPORTING_TOKENS);
+        if (!sgndEncryptedSuppTokens.isEmpty()) {
+            Map<AbstractToken, SecurePart> sgndEncSuppTokMap = 
+                this.handleSupportingTokens(sgndEncryptedSuppTokens, true, false);
+            addSignatureParts(sgndEncSuppTokMap);
+        }
         
-        Collection<Assertion> endorsingEncryptedSuppTokens 
-            = findAndAssertPolicy(SP12Constants.ENDORSING_ENCRYPTED_SUPPORTING_TOKENS);
-        endEncSuppTokMap 
-            = this.handleSupportingTokens(endorsingEncryptedSuppTokens, false, true);
-
-        Collection<Assertion> sgndEndEncSuppTokens 
-            = findAndAssertPolicy(SP12Constants.SIGNED_ENDORSING_ENCRYPTED_SUPPORTING_TOKENS);
-        sgndEndEncSuppTokMap = this.handleSupportingTokens(sgndEndEncSuppTokens, true, true);
+        Collection<AssertionInfo> endorsingEncryptedSuppTokens 
+            = getAllAssertionsByLocalname(SPConstants.ENDORSING_ENCRYPTED_SUPPORTING_TOKENS);
+        if (!endorsingEncryptedSuppTokens.isEmpty()) {
+            endEncSuppTokMap 
+                = this.handleSupportingTokens(endorsingEncryptedSuppTokens, false, true);
+        }
 
-        Collection<Assertion> supportingToks 
-            = findAndAssertPolicy(SP12Constants.SUPPORTING_TOKENS);
-        this.handleSupportingTokens(supportingToks, false, false);
-        supportingToks = findAndAssertPolicy(SP11Constants.SUPPORTING_TOKENS);
-        this.handleSupportingTokens(supportingToks, false, false);
+        Collection<AssertionInfo> sgndEndEncSuppTokens 
+            = getAllAssertionsByLocalname(SPConstants.SIGNED_ENDORSING_ENCRYPTED_SUPPORTING_TOKENS);
+        if (!sgndEndEncSuppTokens.isEmpty()) {
+            sgndEndEncSuppTokMap = this.handleSupportingTokens(sgndEndEncSuppTokens, true,
true);
+            addSignatureParts(sgndEndEncSuppTokMap);
+        }
 
-        Collection<Assertion> encryptedSupportingToks 
-            = findAndAssertPolicy(SP12Constants.ENCRYPTED_SUPPORTING_TOKENS);
-        this.handleSupportingTokens(encryptedSupportingToks, false, false);
+        Collection<AssertionInfo> supportingToks 
+            = getAllAssertionsByLocalname(SPConstants.SUPPORTING_TOKENS);
+        if (!supportingToks.isEmpty()) {
+            this.handleSupportingTokens(supportingToks, false, false);
+        }
 
-        //Setup signature parts
-        addSignatureParts(sigSuppTokMap);
-        addSignatureParts(sgndEncSuppTokMap);
-        addSignatureParts(sgndEndSuppTokMap);
-        addSignatureParts(sgndEndEncSuppTokMap);
+        Collection<AssertionInfo> encryptedSupportingToks 
+            = getAllAssertionsByLocalname(SPConstants.ENCRYPTED_SUPPORTING_TOKENS);
+        if (!encryptedSupportingToks.isEmpty()) {
+            this.handleSupportingTokens(encryptedSupportingToks, false, false);
+        }
     }
     
     protected void addSignatureParts(Map<AbstractToken, SecurePart> tokenMap) {
-        for (AbstractToken token : tokenMap.keySet()) {
-            SecurePart part = tokenMap.get(token);
-
-            QName name = part.getName();
-            List<WSSConstants.Action> actionList = properties.getActions();
-
-            // Don't add a signed SAML Token as a part, as it will be automatically signed
by WSS4J
-            if (!((WSSConstants.TAG_saml_Assertion.equals(name) 
-                || WSSConstants.TAG_saml2_Assertion.equals(name))
-                && actionList != null && actionList.contains(WSSConstants.SAML_TOKEN_SIGNED)))
{
-                properties.addSignaturePart(part);
+        if (tokenMap != null) {
+            for (AbstractToken token : tokenMap.keySet()) {
+                SecurePart part = tokenMap.get(token);
+    
+                QName name = part.getName();
+                List<WSSConstants.Action> actionList = properties.getActions();
+    
+                // Don't add a signed SAML Token as a part, as it will be automatically signed
by WSS4J
+                if (!((WSSConstants.TAG_saml_Assertion.equals(name) 
+                    || WSSConstants.TAG_saml2_Assertion.equals(name))
+                    && actionList != null && actionList.contains(WSSConstants.SAML_TOKEN_SIGNED)))
{
+                    properties.addSignaturePart(part);
+                }
             }
         }
         
@@ -820,20 +828,16 @@ public abstract class AbstractStaxBindingHandler extends AbstractCommonBindingHa
         SignedElements elements = null;
         
         AssertionInfoMap aim = message.get(AssertionInfoMap.class);
-        Collection<AssertionInfo> ais = getAllAssertionsByLocalname(aim, SPConstants.SIGNED_PARTS);
-        if (!ais.isEmpty()) {
-            for (AssertionInfo ai : ais) {
-                parts = (SignedParts)ai.getAssertion();
-                ai.setAsserted(true);
-            }            
+        AssertionInfo assertionInfo = getFirstAssertionByLocalname(aim, SPConstants.SIGNED_PARTS);
+        if (assertionInfo != null) {
+            parts = (SignedParts)assertionInfo.getAssertion();
+            assertionInfo.setAsserted(true);
         }
         
-        ais = getAllAssertionsByLocalname(aim, SPConstants.SIGNED_ELEMENTS);
-        if (!ais.isEmpty()) {
-            for (AssertionInfo ai : ais) {
-                elements = (SignedElements)ai.getAssertion();
-                ai.setAsserted(true);
-            }            
+        assertionInfo = getFirstAssertionByLocalname(aim, SPConstants.SIGNED_ELEMENTS);
+        if (assertionInfo != null) {
+            elements = (SignedElements)assertionInfo.getAssertion();
+            assertionInfo.setAsserted(true);
         }
         
         List<SecurePart> signedParts = new ArrayList<SecurePart>();

http://git-wip-us.apache.org/repos/asf/cxf/blob/1bd380a4/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxAsymmetricBindingHandler.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxAsymmetricBindingHandler.java
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxAsymmetricBindingHandler.java
index d830058..2d1ebb1 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxAsymmetricBindingHandler.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxAsymmetricBindingHandler.java
@@ -355,10 +355,7 @@ public class StaxAsymmetricBindingHandler extends AbstractStaxBindingHandler
{
             }
             properties.addAction(actionToPerform);
             
-            for (SecurePart encPart : encrParts) {
-                properties.addEncryptionPart(encPart);
-            }
-            
+            properties.getEncryptionSecureParts().addAll(encrParts);
             properties.setEncryptionKeyIdentifier(getKeyIdentifierType(recToken, encrToken));
             
             // Find out do we also need to include the token as per the Inclusion requirement
@@ -424,9 +421,7 @@ public class StaxAsymmetricBindingHandler extends AbstractStaxBindingHandler
{
             actionList.add(actionToPerform);
         }
         
-        for (SecurePart sigPart : sigParts) {
-            properties.addSignaturePart(sigPart);
-        }
+        properties.getSignatureSecureParts().addAll(sigParts);
         
         AbstractToken sigToken = wrapper.getToken();
         configureSignature(wrapper, sigToken, false);

http://git-wip-us.apache.org/repos/asf/cxf/blob/1bd380a4/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxSymmetricBindingHandler.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxSymmetricBindingHandler.java
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxSymmetricBindingHandler.java
index 98c7141..e1b0dac 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxSymmetricBindingHandler.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxSymmetricBindingHandler.java
@@ -419,10 +419,7 @@ public class StaxSymmetricBindingHandler extends AbstractStaxBindingHandler
{
                 properties.setUse200512Namespace(true);
             }
             
-            for (SecurePart encPart : encrParts) {
-                properties.addEncryptionPart(encPart);
-            }
-            
+            properties.getEncryptionSecureParts().addAll(encrParts);
             properties.addAction(actionToPerform);
 
             if (isRequestor()) {
@@ -532,9 +529,7 @@ public class StaxSymmetricBindingHandler extends AbstractStaxBindingHandler
{
             actionList.add(actionToPerform);
         }
 
-        for (SecurePart sigPart : sigParts) {
-            properties.addSignaturePart(sigPart);
-        }
+        properties.getSignatureSecureParts().addAll(sigParts);
         
         AbstractToken sigToken = wrapper.getToken();
         if (sbinding.isProtectTokens() && sigToken instanceof X509Token &&
isRequestor()) {


Mime
View raw message