cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [2/2] git commit: More cleanup work
Date Wed, 16 Apr 2014 11:27:19 GMT
More cleanup work


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

Branch: refs/heads/master
Commit: caca7e1138202d15df04278a20426bcf07c04528
Parents: c2eb9df
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Wed Apr 16 12:17:03 2014 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Wed Apr 16 12:17:03 2014 +0100

----------------------------------------------------------------------
 .../wss4j/AbstractWSS4JStaxInterceptor.java     | 47 +++++++++-----------
 .../PolicyBasedWSS4JStaxInInterceptor.java      | 35 ++++++---------
 .../PolicyBasedWSS4JStaxOutInterceptor.java     | 41 ++++++++---------
 .../security/wss4j/WSS4JStaxInInterceptor.java  |  7 +--
 4 files changed, 58 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/caca7e11/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JStaxInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JStaxInterceptor.java
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JStaxInterceptor.java
index 74eef5d..c76a13e 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JStaxInterceptor.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JStaxInterceptor.java
@@ -24,7 +24,6 @@ import java.net.URI;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Properties;
@@ -440,24 +439,20 @@ public abstract class AbstractWSS4JStaxInterceptor implements SoapInterceptor,
         return null;
     }
     
-    protected Collection<AssertionInfo> getAllAssertionsByLocalname(
+    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 ((sp11Ais != null && !sp11Ais.isEmpty()) || (sp12Ais != null &&
!sp12Ais.isEmpty())) {
-            Collection<AssertionInfo> ais = new HashSet<AssertionInfo>();
-            if (sp11Ais != null) {
-                ais.addAll(sp11Ais);
-            }
-            if (sp12Ais != null) {
-                ais.addAll(sp12Ais);
-            }
-            return ais;
+        if (sp12Ais != null && !sp12Ais.isEmpty()) {
+            return sp12Ais.iterator().next();
         }
 
-        return Collections.emptySet();
+        return null;
     }
     
     private static Properties getProps(Object o, URL propsURL, SoapMessage message) {
@@ -503,10 +498,11 @@ public abstract class AbstractWSS4JStaxInterceptor implements SoapInterceptor,
     protected Crypto getEncryptionCrypto(
             Object e, SoapMessage message, WSSSecurityProperties securityProperties
     ) throws WSSecurityException {
-        Crypto encrCrypto = null;
-        if (e instanceof Crypto) {
-            encrCrypto = (Crypto)e;
-        } else if (e != null) {
+        if (e == null) {
+            return null;
+        } else if (e instanceof Crypto) {
+            return (Crypto)e;
+        } else {
             URL propsURL = getPropertiesFileURL(e, message);
             Properties props = getProps(e, propsURL, message);
             if (props == null) {
@@ -515,7 +511,7 @@ public abstract class AbstractWSS4JStaxInterceptor implements SoapInterceptor,
                 throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, ex);
             }
 
-            encrCrypto = CryptoFactory.getInstance(props,
+            Crypto encrCrypto = CryptoFactory.getInstance(props,
                     Loader.getClassLoader(CryptoFactory.class),
                     getPasswordEncryptor(message, securityProperties));
 
@@ -523,17 +519,18 @@ public abstract class AbstractWSS4JStaxInterceptor implements SoapInterceptor,
             synchronized (info) {
                 info.setProperty(SecurityConstants.ENCRYPT_CRYPTO, encrCrypto);
             }
+            return encrCrypto;
         }
-        return encrCrypto;
     }
         
     protected Crypto getSignatureCrypto(
         Object s, SoapMessage message, WSSSecurityProperties securityProperties
     ) throws WSSecurityException {
-        Crypto signCrypto = null;
-        if (s instanceof Crypto) {
-            signCrypto = (Crypto)s;
-        } else if (s != null) {
+        if (s == null) {
+            return null;
+        } else if (s instanceof Crypto) {
+            return (Crypto)s;
+        } else {
             URL propsURL = getPropertiesFileURL(s, message);
             Properties props = getProps(s, propsURL, message);
             if (props == null) {
@@ -542,7 +539,7 @@ public abstract class AbstractWSS4JStaxInterceptor implements SoapInterceptor,
                 throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, ex);
             }
 
-            signCrypto = CryptoFactory.getInstance(props,
+            Crypto signCrypto = CryptoFactory.getInstance(props,
                     Loader.getClassLoader(CryptoFactory.class),
                     getPasswordEncryptor(message, securityProperties));
 
@@ -550,8 +547,8 @@ public abstract class AbstractWSS4JStaxInterceptor implements SoapInterceptor,
             synchronized (info) {
                 info.setProperty(SecurityConstants.SIGNATURE_CRYPTO, signCrypto);
             }
+            return signCrypto;
         }
-        return signCrypto;
     }
 
     private ClassLoader getClassLoader() {

http://git-wip-us.apache.org/repos/asf/cxf/blob/caca7e11/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxInInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxInInterceptor.java
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxInInterceptor.java
index 2fb0a9d..770e2bd 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxInInterceptor.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxInInterceptor.java
@@ -87,9 +87,8 @@ public class PolicyBasedWSS4JStaxInInterceptor extends WSS4JStaxInInterceptor
{
     private void checkAsymmetricBinding(
         AssertionInfoMap aim, SoapMessage message, WSSSecurityProperties securityProperties
     ) throws WSSecurityException {
-        Collection<AssertionInfo> ais = 
-            getAllAssertionsByLocalname(aim, SPConstants.ASYMMETRIC_BINDING);
-        if (ais.isEmpty()) {
+        AssertionInfo ais = getFirstAssertionByLocalname(aim, SPConstants.ASYMMETRIC_BINDING);
+        if (ais == null) {
             return;
         }
         
@@ -125,9 +124,10 @@ public class PolicyBasedWSS4JStaxInInterceptor extends WSS4JStaxInInterceptor
{
         AssertionInfoMap aim, SoapMessage message, WSSSecurityProperties securityProperties
     ) throws XMLSecurityException {
         boolean transportPolicyInEffect = 
-            !getAllAssertionsByLocalname(aim, SPConstants.TRANSPORT_BINDING).isEmpty();
-        if (!transportPolicyInEffect && !(getAllAssertionsByLocalname(aim, SPConstants.SYMMETRIC_BINDING).isEmpty()
-            && getAllAssertionsByLocalname(aim, SPConstants.ASYMMETRIC_BINDING).isEmpty()))
{
+            getFirstAssertionByLocalname(aim, SPConstants.TRANSPORT_BINDING) != null;
+        if (!transportPolicyInEffect 
+            && !(getFirstAssertionByLocalname(aim, SPConstants.SYMMETRIC_BINDING)
== null
+                && getFirstAssertionByLocalname(aim, SPConstants.ASYMMETRIC_BINDING)
== null)) {
             return;
         }
         
@@ -192,9 +192,8 @@ public class PolicyBasedWSS4JStaxInInterceptor extends WSS4JStaxInInterceptor
{
     private void checkSymmetricBinding(
         AssertionInfoMap aim, SoapMessage message, WSSSecurityProperties securityProperties
     ) throws WSSecurityException {
-        Collection<AssertionInfo> ais = 
-            getAllAssertionsByLocalname(aim, SPConstants.SYMMETRIC_BINDING);
-        if (ais.isEmpty()) {
+        AssertionInfo ais = getFirstAssertionByLocalname(aim, SPConstants.SYMMETRIC_BINDING);
+        if (ais == null) {
             return;
         }
         
@@ -283,10 +282,8 @@ public class PolicyBasedWSS4JStaxInInterceptor extends WSS4JStaxInInterceptor
{
     protected boolean isNonceCacheRequired(SoapMessage msg, WSSSecurityProperties securityProperties)
{
         AssertionInfoMap aim = msg.get(AssertionInfoMap.class);
         if (aim != null) {
-            Collection<AssertionInfo> ais = 
-                getAllAssertionsByLocalname(aim, SPConstants.USERNAME_TOKEN);
-            
-            if (!ais.isEmpty()) {
+            AssertionInfo ais = getFirstAssertionByLocalname(aim, SPConstants.USERNAME_TOKEN);
+            if (ais != null) {
                 return true;
             }
         }
@@ -301,10 +298,8 @@ public class PolicyBasedWSS4JStaxInInterceptor extends WSS4JStaxInInterceptor
{
     protected boolean isTimestampCacheRequired(SoapMessage msg, WSSSecurityProperties securityProperties)
{
         AssertionInfoMap aim = msg.get(AssertionInfoMap.class);
         if (aim != null) {
-            Collection<AssertionInfo> ais = 
-                getAllAssertionsByLocalname(aim, SPConstants.INCLUDE_TIMESTAMP);
-            
-            if (!ais.isEmpty()) {
+            AssertionInfo ais = getFirstAssertionByLocalname(aim, SPConstants.INCLUDE_TIMESTAMP);
+            if (ais != null) {
                 return true;
             }
         }
@@ -319,10 +314,8 @@ public class PolicyBasedWSS4JStaxInInterceptor extends WSS4JStaxInInterceptor
{
     protected boolean isSamlCacheRequired(SoapMessage msg, WSSSecurityProperties securityProperties)
{
         AssertionInfoMap aim = msg.get(AssertionInfoMap.class);
         if (aim != null) {
-            Collection<AssertionInfo> ais = 
-                getAllAssertionsByLocalname(aim, SPConstants.SAML_TOKEN);
-            
-            if (!ais.isEmpty()) {
+            AssertionInfo ais = getFirstAssertionByLocalname(aim, SPConstants.SAML_TOKEN);
+            if (ais != null) {
                 return true;
             }
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/caca7e11/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxOutInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxOutInterceptor.java
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxOutInterceptor.java
index a3befb3..f5093c4 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxOutInterceptor.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JStaxOutInterceptor.java
@@ -19,8 +19,6 @@
 
 package org.apache.cxf.ws.security.wss4j;
 
-import java.util.Collection;
-
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.MessageUtils;
@@ -62,7 +60,7 @@ public class PolicyBasedWSS4JStaxOutInterceptor extends WSS4JStaxOutInterceptor
     }
     
     private void checkAsymmetricBinding(
-        AssertionInfoMap aim, SoapMessage message, WSSSecurityProperties securityProperties
+        SoapMessage message, WSSSecurityProperties securityProperties
     ) throws WSSecurityException {
         Object s = message.getContextualProperty(SecurityConstants.SIGNATURE_CRYPTO);
         if (s == null) {
@@ -93,7 +91,7 @@ public class PolicyBasedWSS4JStaxOutInterceptor extends WSS4JStaxOutInterceptor
     }
     
     private void checkTransportBinding(
-        AssertionInfoMap aim, SoapMessage message, WSSSecurityProperties securityProperties
+        SoapMessage message, WSSSecurityProperties securityProperties
     ) throws WSSecurityException {
         Object s = message.getContextualProperty(SecurityConstants.SIGNATURE_CRYPTO);
         if (s == null) {
@@ -124,7 +122,7 @@ public class PolicyBasedWSS4JStaxOutInterceptor extends WSS4JStaxOutInterceptor
     }
     
     private void checkSymmetricBinding(
-        AssertionInfoMap aim, SoapMessage message, WSSSecurityProperties securityProperties
+        SoapMessage message, WSSSecurityProperties securityProperties
     ) throws WSSecurityException {
         Object s = message.getContextualProperty(SecurityConstants.SIGNATURE_CRYPTO);
         if (s == null) {
@@ -185,36 +183,33 @@ public class PolicyBasedWSS4JStaxOutInterceptor extends WSS4JStaxOutInterceptor
     ) throws WSSecurityException {
         AssertionInfoMap aim = msg.get(AssertionInfoMap.class);
         
-        Collection<AssertionInfo> asymAis = 
-            getAllAssertionsByLocalname(aim, SPConstants.ASYMMETRIC_BINDING);
-        if (!asymAis.isEmpty()) {
-            checkAsymmetricBinding(aim, msg, securityProperties);
+        AssertionInfo asymAis = getFirstAssertionByLocalname(aim, SPConstants.ASYMMETRIC_BINDING);
+        if (asymAis != null) {
+            checkAsymmetricBinding(msg, securityProperties);
         }
         
-        Collection<AssertionInfo> symAis = 
-            getAllAssertionsByLocalname(aim, SPConstants.SYMMETRIC_BINDING);
-        if (!symAis.isEmpty()) {
-            checkSymmetricBinding(aim, msg, securityProperties);
+        AssertionInfo symAis = getFirstAssertionByLocalname(aim, SPConstants.SYMMETRIC_BINDING);
+        if (symAis != null) {
+            checkSymmetricBinding(msg, securityProperties);
         }
         
-        Collection<AssertionInfo> transAis = 
-            getAllAssertionsByLocalname(aim, SPConstants.TRANSPORT_BINDING);
-        if (!transAis.isEmpty()) {
-            checkTransportBinding(aim, msg, securityProperties);
+        AssertionInfo transAis = getFirstAssertionByLocalname(aim, SPConstants.TRANSPORT_BINDING);
+        if (transAis != null) {
+            checkTransportBinding(msg, securityProperties);
         }
         
         super.configureProperties(msg, outboundSecurityContext, securityProperties);
         
-        if (!transAis.isEmpty()) {
-            TransportBinding binding = (TransportBinding)transAis.iterator().next().getAssertion();
+        if (transAis != null) {
+            TransportBinding binding = (TransportBinding)transAis.getAssertion();
             new StaxTransportBindingHandler(
                 securityProperties, msg, binding, outboundSecurityContext).handleBinding();
-        } else if (!asymAis.isEmpty()) {
-            AsymmetricBinding binding = (AsymmetricBinding)asymAis.iterator().next().getAssertion();
+        } else if (asymAis != null) {
+            AsymmetricBinding binding = (AsymmetricBinding)asymAis.getAssertion();
             new StaxAsymmetricBindingHandler(
                 securityProperties, msg, binding, outboundSecurityContext).handleBinding();
-        } else if (!symAis.isEmpty()) {
-            SymmetricBinding binding = (SymmetricBinding)symAis.iterator().next().getAssertion();
+        } else if (symAis != null) {
+            SymmetricBinding binding = (SymmetricBinding)symAis.getAssertion();
             new StaxSymmetricBindingHandler(
                 securityProperties, msg, binding, outboundSecurityContext).handleBinding();
         } else {

http://git-wip-us.apache.org/repos/asf/cxf/blob/caca7e11/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java
index f0a4a79..d0f0c12 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java
@@ -386,6 +386,9 @@ public class WSS4JStaxInInterceptor extends AbstractWSS4JStaxInterceptor
{
     
     private Validator loadValidator(String validatorKey, SoapMessage message) throws WSSecurityException
{
         Object o = message.getContextualProperty(validatorKey);
+        if (o == null) {
+            return null;
+        }
         try {
             if (o instanceof Validator) {
                 return (Validator)o;
@@ -395,7 +398,7 @@ public class WSS4JStaxInInterceptor extends AbstractWSS4JStaxInterceptor
{
                 return (Validator)ClassLoaderUtils.loadClass(o.toString(),
                                                              WSS4JStaxInInterceptor.class)
                                                              .newInstance();
-            } else if (o != null) {
+            } else {
                 throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, 
                                                   "Cannot load Validator: " + o);
             }
@@ -404,8 +407,6 @@ public class WSS4JStaxInInterceptor extends AbstractWSS4JStaxInterceptor
{
         } catch (Exception ex) {
             throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, ex);
         }
-        
-        return null;
     }
 
     private class TokenStoreCallbackHandler implements CallbackHandler {


Mime
View raw message