Author: dkulp
Date: Mon Mar 23 18:34:41 2009
New Revision: 757489
URL: http://svn.apache.org/viewvc?rev=757489&view=rev
Log:
Some thread safety fixes. Don't use hashCode to store documents.
Modified:
webservices/wss4j/trunk/src/org/apache/ws/security/WSDocInfo.java
webservices/wss4j/trunk/src/org/apache/ws/security/WSDocInfoStore.java
webservices/wss4j/trunk/src/org/apache/ws/security/WSSecurityEngine.java
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDKSign.java
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecSignature.java
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSignEnvelope.java
webservices/wss4j/trunk/src/org/apache/ws/security/processor/SignatureProcessor.java
webservices/wss4j/trunk/src/org/apache/ws/security/saml/WSSecSignatureSAML.java
webservices/wss4j/trunk/src/org/apache/ws/security/saml/WSSignSAMLEnvelope.java
webservices/wss4j/trunk/src/org/apache/ws/security/transform/STRTransform.java
Modified: webservices/wss4j/trunk/src/org/apache/ws/security/WSDocInfo.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/WSDocInfo.java?rev=757489&r1=757488&r2=757489&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/WSDocInfo.java (original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/WSDocInfo.java Mon Mar
23 18:34:41 2009
@@ -33,20 +33,22 @@
import org.apache.ws.security.components.crypto.Crypto;
import org.apache.ws.security.processor.Processor;
+
+import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.util.Enumeration;
import java.util.Vector;
public class WSDocInfo {
- int hash;
+ Document doc = null;
Crypto crypto = null;
Vector bst = null;
Element assertion = null;
Vector processors = null;
- public WSDocInfo(int hash) {
- this.hash = hash;
+ public WSDocInfo(Document doc) {
+ this.doc = doc;
}
/**
@@ -134,10 +136,10 @@
}
/**
- * @return the hash value of the document
+ * @return the document
*/
- public int getHash() {
- return hash;
+ public Document getDocument() {
+ return doc;
}
/**
Modified: webservices/wss4j/trunk/src/org/apache/ws/security/WSDocInfoStore.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/WSDocInfoStore.java?rev=757489&r1=757488&r2=757489&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/WSDocInfoStore.java
(original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/WSDocInfoStore.java Mon
Mar 23 18:34:41 2009
@@ -30,32 +30,21 @@
import java.util.Hashtable;
+import org.w3c.dom.Document;
+
public class WSDocInfoStore {
static Hashtable storage = new Hashtable(10);
- public static WSDocInfo lookup(int hash) {
- Integer intObj = new Integer(hash);
- return (WSDocInfo) storage.get(intObj);
- }
-
- public static void store(WSDocInfo info) {
- Integer intObj = new Integer(info.getHash());
- if (storage.containsKey(intObj)) {
- return;
- }
- storage.put(intObj, info);
+ public static WSDocInfo lookup(Document doc) {
+ return (WSDocInfo) storage.get(doc);
}
- public static void delete(int hash) {
- Integer intObj = new Integer(hash);
- WSDocInfo wsInfo = (WSDocInfo) storage.get(intObj);
- if (wsInfo != null) {
- storage.remove(intObj);
- }
+ public static boolean store(WSDocInfo info) {
+ return storage.put(info.getDocument(), info) == null;
}
public static void delete(WSDocInfo info) {
- delete(info.getHash());
+ storage.remove(info.getDocument());
}
}
Modified:
webservices/wss4j/trunk/src/org/apache/ws/security/WSSecurityEngine.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/WSSecurityEngine.java?rev=757489&r1=757488&r2=757489&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/WSSecurityEngine.java
(original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/WSSecurityEngine.java
Mon Mar 23 18:34:41 2009
@@ -298,7 +298,7 @@
* it for retrieval. Store the implementation of signature crypto
* (no need for encryption --- yet)
*/
- WSDocInfo wsDocInfo = new
WSDocInfo(securityHeader.getOwnerDocument().hashCode());
+ WSDocInfo wsDocInfo = new WSDocInfo(securityHeader.getOwnerDocument());
wsDocInfo.setCrypto(sigCrypto);
NodeList list = securityHeader.getChildNodes();
Modified:
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDKSign.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDKSign.java?rev=757489&r1=757488&r2=757489&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDKSign.java
(original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecDKSign.java
Mon Mar 23 18:34:41 2009
@@ -112,7 +112,7 @@
public void prepare(Document doc, WSSecHeader secHeader)
throws WSSecurityException, ConversationException {
super.prepare(doc);
- wsDocInfo = new WSDocInfo(doc.hashCode());
+ wsDocInfo = new WSDocInfo(doc);
//
// Get and initialize a XMLSignature element.
@@ -411,7 +411,7 @@
* @throws WSSecurityException
*/
public void computeSignature() throws WSSecurityException {
- WSDocInfoStore.store(wsDocInfo);
+ boolean remove = WSDocInfoStore.store(wsDocInfo);
try {
sig.sign(sig.createSecretKey(derivedKeyBytes));
signatureValue = sig.getSignatureValue();
@@ -424,7 +424,9 @@
WSSecurityException.FAILED_SIGNATURE, null, null, e1
);
} finally {
- WSDocInfoStore.delete(wsDocInfo);
+ if (remove) {
+ WSDocInfoStore.delete(wsDocInfo);
+ }
}
}
Modified:
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecSignature.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecSignature.java?rev=757489&r1=757488&r2=757489&view=diff
==============================================================================
---
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecSignature.java
(original)
+++
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecSignature.java
Mon Mar 23 18:34:41 2009
@@ -289,7 +289,7 @@
//
crypto = cr;
document = doc;
- wsDocInfo = new WSDocInfo(doc.hashCode());
+ wsDocInfo = new WSDocInfo(doc);
wsDocInfo.setCrypto(cr);
//
@@ -691,7 +691,7 @@
* @throws WSSecurityException
*/
public void computeSignature() throws WSSecurityException {
- WSDocInfoStore.store(wsDocInfo);
+ boolean remove = WSDocInfoStore.store(wsDocInfo);
try {
if (keyIdentifierType == WSConstants.UT_SIGNING ||
keyIdentifierType == WSConstants.CUSTOM_SYMM_SIGNING ||
@@ -716,7 +716,9 @@
WSSecurityException.FAILED_SIGNATURE, null, null, e1
);
} finally {
- WSDocInfoStore.delete(wsDocInfo);
+ if (remove) {
+ WSDocInfoStore.delete(wsDocInfo);
+ }
}
}
Modified:
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSignEnvelope.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSignEnvelope.java?rev=757489&r1=757488&r2=757489&view=diff
==============================================================================
---
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSignEnvelope.java
(original)
+++
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSignEnvelope.java
Mon Mar 23 18:34:41 2009
@@ -240,7 +240,7 @@
* Gather some info about the document to process and store it for
* retrieval
*/
- WSDocInfo wsDocInfo = new WSDocInfo(doc.hashCode());
+ WSDocInfo wsDocInfo = new WSDocInfo(doc);
wsDocInfo.setCrypto(crypto);
Element envelope = doc.getDocumentElement();
@@ -542,7 +542,7 @@
}
info.addUnknownElement(secRef.getElement());
- WSDocInfoStore.store(wsDocInfo);
+ boolean remove = WSDocInfoStore.store(wsDocInfo);
try {
if (keyIdentifierType == WSConstants.UT_SIGNING) {
sig.sign(sig.createSecretKey(secretKey));
@@ -557,7 +557,9 @@
throw new WSSecurityException(WSSecurityException.FAILED_SIGNATURE,
null, null, e1);
} finally {
- WSDocInfoStore.delete(wsDocInfo);
+ if (remove) {
+ WSDocInfoStore.delete(wsDocInfo);
+ }
}
if (tlog.isDebugEnabled()) {
t4 = System.currentTimeMillis();
Modified:
webservices/wss4j/trunk/src/org/apache/ws/security/processor/SignatureProcessor.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/processor/SignatureProcessor.java?rev=757489&r1=757488&r2=757489&view=diff
==============================================================================
---
webservices/wss4j/trunk/src/org/apache/ws/security/processor/SignatureProcessor.java
(original)
+++
webservices/wss4j/trunk/src/org/apache/ws/security/processor/SignatureProcessor.java
Mon Mar 23 18:34:41 2009
@@ -86,7 +86,7 @@
if (log.isDebugEnabled()) {
log.debug("Found signature element");
}
- WSDocInfoStore.store(wsDocInfo);
+ boolean remove = WSDocInfoStore.store(wsDocInfo);
X509Certificate[] returnCert = new X509Certificate[1];
Set returnElements = new HashSet();
List protectedElements = new java.util.ArrayList();
@@ -97,12 +97,15 @@
lastPrincipalFound =
verifyXMLSignature(
elem, crypto, returnCert, returnElements,
- protectedElements, signatureValue, cb
+ protectedElements, signatureValue, cb,
+ wsDocInfo
);
} catch (WSSecurityException ex) {
throw ex;
} finally {
- WSDocInfoStore.delete(wsDocInfo);
+ if (remove) {
+ WSDocInfoStore.delete(wsDocInfo);
+ }
}
if (lastPrincipalFound instanceof WSUsernameTokenPrincipal) {
returnResults.add(
@@ -178,7 +181,8 @@
Set returnElements,
List protectedElements,
byte[][] signatureValue,
- CallbackHandler cb
+ CallbackHandler cb,
+ WSDocInfo wsDocInfo
) throws WSSecurityException {
if (log.isDebugEnabled()) {
log.debug("Verify XML Signature");
@@ -227,13 +231,10 @@
);
}
SecurityTokenReference secRef = new
SecurityTokenReference((Element) node);
- int docHash = elem.getOwnerDocument().hashCode();
- //
// Here we get some information about the document that is being
// processed, in particular the crypto implementation, and already
// detected BST that may be used later during dereferencing.
//
- WSDocInfo wsDocInfo = WSDocInfoStore.lookup(docHash);
if (secRef.containsReference()) {
Element token =
secRef.getTokenElement(elem.getOwnerDocument(), wsDocInfo, cb);
Modified:
webservices/wss4j/trunk/src/org/apache/ws/security/saml/WSSecSignatureSAML.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/saml/WSSecSignatureSAML.java?rev=757489&r1=757488&r2=757489&view=diff
==============================================================================
---
webservices/wss4j/trunk/src/org/apache/ws/security/saml/WSSecSignatureSAML.java
(original)
+++
webservices/wss4j/trunk/src/org/apache/ws/security/saml/WSSecSignatureSAML.java
Mon Mar 23 18:34:41 2009
@@ -233,7 +233,7 @@
* Gather some info about the document to process and store it for
* retrieval
*/
- wsDocInfo = new WSDocInfo(doc.hashCode());
+ wsDocInfo = new WSDocInfo(doc);
X509Certificate[] certs = null;
@@ -594,7 +594,7 @@
*/
public void computeSignature() throws WSSecurityException {
- WSDocInfoStore.store(wsDocInfo);
+ boolean remove = WSDocInfoStore.store(wsDocInfo);
try {
if (senderVouches) {
@@ -612,7 +612,9 @@
throw new WSSecurityException(WSSecurityException.FAILED_SIGNATURE,
null, null, e1);
} finally {
- WSDocInfoStore.delete(wsDocInfo);
+ if (remove) {
+ WSDocInfoStore.delete(wsDocInfo);
+ }
}
}
}
Modified:
webservices/wss4j/trunk/src/org/apache/ws/security/saml/WSSignSAMLEnvelope.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/saml/WSSignSAMLEnvelope.java?rev=757489&r1=757488&r2=757489&view=diff
==============================================================================
---
webservices/wss4j/trunk/src/org/apache/ws/security/saml/WSSignSAMLEnvelope.java
(original)
+++
webservices/wss4j/trunk/src/org/apache/ws/security/saml/WSSignSAMLEnvelope.java
Mon Mar 23 18:34:41 2009
@@ -157,7 +157,7 @@
* Gather some info about the document to process and store it for
* retrieval
*/
- WSDocInfo wsDocInfo = new WSDocInfo(doc.hashCode());
+ WSDocInfo wsDocInfo = new WSDocInfo(doc);
Element envelope = doc.getDocumentElement();
SOAPConstants soapConstants =
WSSecurityUtil.getSOAPConstants(envelope);
@@ -418,7 +418,7 @@
wsDocInfo.setAssertion(samlToken);
WSSecurityUtil.prependChildElement(securityHeader, samlToken);
- WSDocInfoStore.store(wsDocInfo);
+ boolean remove = WSDocInfoStore.store(wsDocInfo);
try {
if (senderVouches) {
sig
@@ -435,7 +435,9 @@
throw new WSSecurityException(WSSecurityException.FAILED_SIGNATURE,
null, null, e1);
} finally {
- WSDocInfoStore.delete(wsDocInfo);
+ if (remove) {
+ WSDocInfoStore.delete(wsDocInfo);
+ }
}
if (tlog.isDebugEnabled()) {
t4 = System.currentTimeMillis();
Modified:
webservices/wss4j/trunk/src/org/apache/ws/security/transform/STRTransform.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/transform/STRTransform.java?rev=757489&r1=757488&r2=757489&view=diff
==============================================================================
---
webservices/wss4j/trunk/src/org/apache/ws/security/transform/STRTransform.java
(original)
+++
webservices/wss4j/trunk/src/org/apache/ws/security/transform/STRTransform.java
Mon Mar 23 18:34:41 2009
@@ -30,6 +30,7 @@
import org.apache.xml.security.c14n.Canonicalizer;
import org.apache.xml.security.c14n.InvalidCanonicalizerException;
import org.apache.xml.security.signature.XMLSignatureInput;
+import org.apache.xml.security.transforms.Transform;
import org.apache.xml.security.transforms.TransformSpi;
import org.apache.ws.security.util.Base64;
import org.apache.xml.security.utils.XMLUtils;
@@ -63,7 +64,7 @@
private static String XMLNS = "xmlns=";
private WSDocInfo wsDocInfo = null;
-
+
public boolean wantsOctetStream() {
return false;
}
@@ -94,7 +95,8 @@
* @throws CanonicalizationException
* @throws InvalidCanonicalizerException
*/
- protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input)
+ protected XMLSignatureInput enginePerformTransform(XMLSignatureInput
input,
+ Transform
transformObject)
throws IOException, CanonicalizationException,
InvalidCanonicalizerException {
doDebug = log.isDebugEnabled();
@@ -106,17 +108,14 @@
//
// Get the main document, that is the complete SOAP request
document
//
- Document thisDoc = this._transformObject.getDocument();
- int docHash = thisDoc.hashCode();
- if (doDebug) {
- log.debug("doc: " + thisDoc.toString() + ", " + docHash);
- }
+ Document thisDoc = transformObject.getDocument();
+
//
// Here we get some information about the document that is being
// processed, in particular the crypto implementation, and already
// detected BST that may be used later during dereferencing.
//
- wsDocInfo = WSDocInfoStore.lookup(docHash);
+ wsDocInfo = WSDocInfoStore.lookup(thisDoc);
if (wsDocInfo == null) {
throw (new CanonicalizationException("no WSDocInfo found"));
}
@@ -131,11 +130,11 @@
// Canonicalizer
//
String canonAlgo = null;
- if (this._transformObject.length(
+ if (transformObject.length(
WSConstants.WSSE_NS, "TransformationParameters") == 1) {
Element tmpE =
XMLUtils.selectNode(
- this._transformObject.getElement().getFirstChild(),
+ transformObject.getElement().getFirstChild(),
WSConstants.WSSE_NS,
"TransformationParameters",
0
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]