cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [1/2] cxf git commit: Temporarily applying a fix for crypto loading until the next WSS4J release is out
Date Fri, 01 Jul 2016 17:58:26 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 222df318a -> a2702f30d


Temporarily applying a fix for crypto loading until the next WSS4J release is out

# Conflicts:
#	rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JInInterceptor.java


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

Branch: refs/heads/3.0.x-fixes
Commit: 92a7be8049d75100188734648c8ac99cd0b07498
Parents: 222df31
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Fri Jul 1 17:41:34 2016 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Fri Jul 1 17:45:27 2016 +0100

----------------------------------------------------------------------
 .../wss4j/PolicyBasedWSS4JInInterceptor.java    | 70 +++++++++++++++++++-
 1 file changed, 69 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/92a7be80/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JInInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JInInterceptor.java
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JInInterceptor.java
index ec0086a..6eaaee5 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JInInterceptor.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWSS4JInInterceptor.java
@@ -110,8 +110,9 @@ import org.apache.wss4j.policy.model.Wss11;
  * 
  */
 public class PolicyBasedWSS4JInInterceptor extends WSS4JInInterceptor {
+    
     private static final Logger LOG = LogUtils.getL7dLogger(PolicyBasedWSS4JInInterceptor.class);
-
+    
     /**
      * 
      */
@@ -128,6 +129,73 @@ public class PolicyBasedWSS4JInInterceptor extends WSS4JInInterceptor
{
         }
     }
     
+    /**
+     * TODO - This method can be removed when WSS4J 2.1.7 is released - see WSS-582
+     * 
+     * Load a Crypto instance. Firstly, it tries to use the cryptoPropertyRefId tag to retrieve
+     * a Crypto object via a custom reference Id. Failing this, it tries to load the crypto
+     * instance via the cryptoPropertyFile tag.
+     *
+     * @param requestData the RequestData object
+     * @return a Crypto instance to use for Encryption creation/verification
+     */
+    @Override
+    protected Crypto loadCrypto(
+        String cryptoPropertyFile,
+        String cryptoPropertyRefId,
+        RequestData requestData
+    ) throws WSSecurityException {
+        Object mc = requestData.getMsgContext();
+        Crypto crypto = null;
+
+        //
+        // Try the Property Ref Id first
+        //
+        String refId = getString(cryptoPropertyRefId, mc);
+        if (refId != null) {
+            crypto = cryptos.get(refId);
+            if (crypto == null) {
+                Object obj = getProperty(mc, refId);
+                if (obj instanceof Properties) {
+                    crypto = CryptoFactory.getInstance((Properties)obj,
+                                                       Loader.getClassLoader(CryptoFactory.class),
+                                                       getPasswordEncryptor(requestData));
+                    cryptos.put(refId, crypto);
+                } else if (obj instanceof Crypto) {
+                    // No need to cache this as it's already loaded
+                    crypto = (Crypto)obj;
+                }
+            }
+            if (crypto == null) {
+                LOG.warning("The Crypto reference " + refId + " specified by "
+                    + cryptoPropertyRefId + " could not be loaded"
+                );
+            }
+        }
+
+        //
+        // Now try loading the properties file
+        //
+        if (crypto == null) {
+            String propFile = getString(cryptoPropertyFile, mc);
+            if (propFile != null) {
+                crypto = cryptos.get(propFile);
+                if (crypto == null) {
+                    crypto = loadCryptoFromPropertiesFile(propFile, requestData);
+                    cryptos.put(propFile, crypto);
+                }
+                if (crypto == null) {
+                    LOG.warning(
+                         "The Crypto properties file " + propFile + " specified by "
+                         + cryptoPropertyFile + " could not be loaded or found"
+                    );
+                }
+            }
+        }
+
+        return crypto;
+    }
+    
     private void handleWSS11(AssertionInfoMap aim, SoapMessage message) {
         if (isRequestor(message)) {
             message.put(WSHandlerConstants.ENABLE_SIGNATURE_CONFIRMATION, "false");


Mime
View raw message