You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ff...@apache.org on 2009/02/12 12:57:25 UTC

svn commit: r743698 - in /cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j: AbstractWSS4JInterceptor.java WSS4JInInterceptor.java

Author: ffang
Date: Thu Feb 12 11:57:25 2009
New Revision: 743698

URL: http://svn.apache.org/viewvc?rev=743698&view=rev
Log:
[CXF-2038]changes for signaturePropFile and decryptionPropFile of WSS4JInteceptor can't be reloaded if we use cxf in container

Modified:
    cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JInterceptor.java
    cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JInterceptor.java?rev=743698&r1=743697&r2=743698&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JInterceptor.java (original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JInterceptor.java Thu Feb 12 11:57:25 2009
@@ -24,6 +24,7 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -53,6 +54,9 @@
 import org.apache.cxf.ws.security.policy.model.UsernameToken;
 import org.apache.cxf.ws.security.policy.model.Wss11;
 import org.apache.ws.security.WSConstants;
+import org.apache.ws.security.WSSecurityException;
+import org.apache.ws.security.components.crypto.Crypto;
+import org.apache.ws.security.components.crypto.CryptoFactory;
 import org.apache.ws.security.handler.RequestData;
 import org.apache.ws.security.handler.WSHandler;
 import org.apache.ws.security.handler.WSHandlerConstants;
@@ -72,6 +76,7 @@
     private Set<String> after = new HashSet<String>();
     private String phase;
     private String id;
+    private Map<String, Crypto> cryptoTable = new Hashtable<String, Crypto>();
     
     public AbstractWSS4JInterceptor() {
         super();
@@ -435,4 +440,129 @@
         }        
         return action;
     }
+    
+    public Crypto loadSignatureCrypto(RequestData reqData) 
+        throws WSSecurityException {
+        Crypto crypto = null;
+        /*
+         *Get crypto property file for signature. If none specified throw
+         * fault, otherwise get a crypto instance.
+         */
+        String sigPropFile = getString(WSHandlerConstants.SIG_PROP_FILE,
+                   reqData.getMsgContext());
+        if (sigPropFile != null) {
+            if (cryptoTable.get(sigPropFile) == null) {
+                crypto = CryptoFactory.getInstance(sigPropFile, this
+                        .getClassLoader(reqData.getMsgContext()));
+                cryptoTable.put(sigPropFile, crypto);
+            } else {
+                crypto = cryptoTable.get(sigPropFile);
+            }
+        } else if (getString(WSHandlerConstants.SIG_PROP_REF_ID, reqData
+            .getMsgContext()) != null) {
+            /*
+             * If the property file is missing then 
+             * look for the Properties object 
+             */
+            String refId = getString(WSHandlerConstants.SIG_PROP_REF_ID,
+                reqData.getMsgContext());
+            if (refId != null) {
+                Object propObj = getProperty(reqData.getMsgContext(), refId);
+                if (propObj instanceof Properties) {
+                    if (cryptoTable.get(refId) == null) {
+                        crypto = CryptoFactory.getInstance((Properties)propObj);
+                        cryptoTable.put(refId, crypto);
+                    } else {
+                        crypto = cryptoTable.get(refId);
+                    }
+                } else {
+                    return crypto;
+                }
+            }
+        } 
+        return crypto;
+    }
+
+    protected Crypto loadDecryptionCrypto(RequestData reqData) 
+        throws WSSecurityException {
+        Crypto crypto = null;
+        String decPropFile = getString(WSHandlerConstants.DEC_PROP_FILE,
+                 reqData.getMsgContext());
+        if (decPropFile != null) {
+            if (cryptoTable.get(decPropFile) == null) {
+                crypto = CryptoFactory.getInstance(decPropFile, this
+                        .getClassLoader(reqData.getMsgContext()));
+                cryptoTable.put(decPropFile, crypto);
+            } else {
+                crypto = cryptoTable.get(decPropFile);
+            }
+        } else if (getString(WSHandlerConstants.DEC_PROP_REF_ID, reqData
+            .getMsgContext()) != null) {
+            /*
+             * If the property file is missing then 
+             * look for the Properties object 
+             */
+            String refId = getString(WSHandlerConstants.DEC_PROP_REF_ID,
+                reqData.getMsgContext());
+            if (refId != null) {
+                Object propObj = getProperty(reqData.getMsgContext(), refId);
+                if (propObj instanceof Properties) {
+                    if (cryptoTable.get(refId) == null) {
+                        crypto = CryptoFactory.getInstance((Properties)propObj);
+                        cryptoTable.put(refId, crypto);
+                    } else {
+                        crypto = cryptoTable.get(refId);
+                    }
+                } else {
+                    return crypto;
+                }
+            }
+        } 
+        return crypto;
+    }
+    
+    protected Crypto loadEncryptionCrypto(RequestData reqData) 
+        throws WSSecurityException {
+        Crypto crypto = null;
+        /*
+        * Get encryption crypto property file. If non specified take crypto
+        * instance from signature, if that fails: throw fault
+        */
+        String encPropFile = getString(WSHandlerConstants.ENC_PROP_FILE,
+                       reqData.getMsgContext());
+        if (encPropFile != null) {
+            if (cryptoTable.get(encPropFile) == null) {
+                crypto = CryptoFactory.getInstance(encPropFile, this
+                        .getClassLoader(reqData.getMsgContext()));
+                cryptoTable.put(encPropFile, crypto);
+            } else {
+                crypto = cryptoTable.get(encPropFile);
+            }
+        } else if (getString(WSHandlerConstants.ENC_PROP_REF_ID, reqData
+                .getMsgContext()) != null) {
+            /*
+             * If the property file is missing then 
+             * look for the Properties object 
+             */
+            String refId = getString(WSHandlerConstants.ENC_PROP_REF_ID,
+                    reqData.getMsgContext());
+            if (refId != null) {
+                Object propObj = getProperty(reqData.getMsgContext(), refId);
+                if (propObj instanceof Properties) {
+                    if (cryptoTable.get(refId) == null) {
+                        crypto = CryptoFactory.getInstance((Properties)propObj);
+                        cryptoTable.put(refId, crypto);
+                    } else {
+                        crypto = cryptoTable.get(encPropFile);
+                    }
+                } else {
+                    return crypto;
+                }
+            }
+        } else if (reqData.getSigCrypto() == null) {
+            return crypto;
+        }
+        return crypto;
+    }
+
 }

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=743698&r1=743697&r2=743698&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 Thu Feb 12 11:57:25 2009
@@ -61,7 +61,6 @@
 import org.apache.ws.security.WSSecurityEngine;
 import org.apache.ws.security.WSSecurityEngineResult;
 import org.apache.ws.security.WSSecurityException;
-import org.apache.ws.security.components.crypto.Crypto;
 import org.apache.ws.security.handler.RequestData;
 import org.apache.ws.security.handler.WSHandlerConstants;
 import org.apache.ws.security.handler.WSHandlerResult;
@@ -415,22 +414,6 @@
         }
         return cbHandler;
     }
-    public Crypto loadSignatureCrypto(RequestData reqData) 
-        throws WSSecurityException {
-        try {
-            return super.loadSignatureCrypto(reqData);
-        } catch (Exception ex) {
-            return null;
-        }
-    }
-    protected Crypto loadDecryptionCrypto(RequestData reqData) 
-        throws WSSecurityException {
-        try {
-            return super.loadDecryptionCrypto(reqData);
-        } catch (Exception ex) {
-            return null;
-        }
-    }