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 14:37:40 UTC
svn commit: r743736 - in
/cxf/branches/2.0.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j:
AbstractWSS4JInterceptor.java WSS4JInInterceptor.java
Author: ffang
Date: Thu Feb 12 13:37:39 2009
New Revision: 743736
URL: http://svn.apache.org/viewvc?rev=743736&view=rev
Log:
[CXF-2038]changes for signaturePropFile and decryptionPropFile of WSS4JInteceptor can't be reloaded if we use cxf in container
Modified:
cxf/branches/2.0.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JInterceptor.java
cxf/branches/2.0.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java
Modified: cxf/branches/2.0.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JInterceptor.java?rev=743736&r1=743735&r2=743736&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JInterceptor.java (original)
+++ cxf/branches/2.0.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JInterceptor.java Thu Feb 12 13:37:39 2009
@@ -21,7 +21,9 @@
import java.net.URI;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Hashtable;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
import javax.xml.namespace.QName;
@@ -32,7 +34,12 @@
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.PhaseInterceptor;
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;
public abstract class AbstractWSS4JInterceptor extends WSHandler implements SoapInterceptor,
PhaseInterceptor<SoapMessage> {
@@ -49,6 +56,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();
@@ -136,4 +144,129 @@
public void setBefore(Set<String> before) {
this.before = before;
}
+
+ 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/branches/2.0.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java?rev=743736&r1=743735&r2=743736&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java (original)
+++ cxf/branches/2.0.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java Thu Feb 12 13:37:39 2009
@@ -51,7 +51,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;
@@ -332,23 +331,7 @@
}
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;
- }
- }
-
+
/**