ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gi...@apache.org
Subject svn commit: r1337945 [4/5] - in /webservices/wss4j/branches/swssf: ./ cxf-integration/src/main/java/org/swssf/cxfIntegration/interceptor/ cxf-integration/src/test/java/org/swssf/cxfIntegration/test/integration/ cxf-integration/src/test/resources/ cxf-i...
Date Sun, 13 May 2012 17:27:13 GMT
Modified: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/ext/XMLSecurityUtils.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/ext/XMLSecurityUtils.java?rev=1337945&r1=1337944&r2=1337945&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/ext/XMLSecurityUtils.java (original)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/ext/XMLSecurityUtils.java Sun May 13 17:27:10 2012
@@ -57,10 +57,6 @@ public class XMLSecurityUtils {
         return reference;
     }
 
-    public static Attribute getReferenceIDAttribute(StartElement startElement) {
-        return startElement.getAttributeByName(XMLSecurityConstants.ATT_NULL_Id);
-    }
-
     /**
      * Returns the XMLEvent type in String form
      *
@@ -140,60 +136,68 @@ public class XMLSecurityUtils {
     }
 
     @SuppressWarnings("unchecked")
-    public static XMLEvent createXMLEventNS(XMLEvent xmlEvent, Deque<List<ComparableNamespace>> nsStack, Deque<List<ComparableAttribute>> attrStack) {
+    public static final XMLEvent createXMLEventNS(final XMLEvent xmlEvent, final Deque<List<ComparableNamespace>> nsStack, final Deque<List<ComparableAttribute>> attrStack) {
         if (xmlEvent.isStartElement()) {
-            StartElement startElement = xmlEvent.asStartElement();
-            QName startElementName = startElement.getName();
+            final StartElement startElement = xmlEvent.asStartElement();
+            final QName startElementName = startElement.getName();
+            final String startElementNamePrefix = startElementName.getPrefix();
 
-            List<String> prefixList = new LinkedList<String>();
-            prefixList.add(startElementName.getPrefix());
+            Set<String> prefixSet = new HashSet<String>();
+            prefixSet.add(startElementNamePrefix);
 
-            List<ComparableNamespace> comparableNamespaceList = new LinkedList<ComparableNamespace>();
+            List<ComparableNamespace> comparableNamespaceList = new ArrayList<ComparableNamespace>();
 
-            ComparableNamespace curElementNamespace = new ComparableNamespace(startElementName.getPrefix(), startElementName.getNamespaceURI());
+            ComparableNamespace curElementNamespace = new ComparableNamespace(startElementNamePrefix, startElementName.getNamespaceURI());
             comparableNamespaceList.add(curElementNamespace);
 
             @SuppressWarnings("unchecked")
             Iterator<Namespace> namespaceIterator = startElement.getNamespaces();
             while (namespaceIterator.hasNext()) {
-                Namespace namespace = namespaceIterator.next();
-                String prefix = namespace.getPrefix();
+                final Namespace namespace = namespaceIterator.next();
+                final String prefix = namespace.getPrefix();
+                final String namespaceURI = namespace.getNamespaceURI();
 
-                if ((prefix == null || prefix.length() == 0) && (namespace.getNamespaceURI() == null || namespace.getNamespaceURI().length() == 0)) {
+                if ((prefix == null || prefix.isEmpty())
+                        && (namespaceURI == null || namespaceURI.isEmpty())) {
                     continue;
                 }
 
-                if (!prefixList.contains(prefix)) {
-                    prefixList.add(prefix);
-                    ComparableNamespace tmpNameSpace = new ComparableNamespace(prefix, namespace.getNamespaceURI());
-                    comparableNamespaceList.add(tmpNameSpace);
+                if (!prefixSet.contains(prefix)) {
+                    prefixSet.add(prefix);
+                    comparableNamespaceList.add(new ComparableNamespace(prefix, namespaceURI));
                 }
             }
 
-            List<ComparableAttribute> comparableAttributeList = new LinkedList<ComparableAttribute>();
+            List<ComparableAttribute> comparableAttributeList;
 
             @SuppressWarnings("unchecked")
             Iterator<Attribute> attributeIterator = startElement.getAttributes();
+            if (attributeIterator.hasNext()) {
+                comparableAttributeList = new ArrayList<ComparableAttribute>();
+            } else {
+                comparableAttributeList = Collections.emptyList();
+            }
+
             while (attributeIterator.hasNext()) {
-                Attribute attribute = attributeIterator.next();
-                String prefix = attribute.getName().getPrefix();
+                final Attribute attribute = attributeIterator.next();
+                final QName attributeName = attribute.getName();
+                final String prefix = attributeName.getPrefix();
+                final String attributeNameNamespaceURI = attributeName.getNamespaceURI();
 
-                if (prefix != null && prefix.length() == 0 && attribute.getName().getNamespaceURI().length() == 0) {
+                if (prefix != null && prefix.isEmpty() && attributeNameNamespaceURI.isEmpty()) {
                     continue;
                 }
                 if (!"xml".equals(prefix)) {
-                    if (!"".equals(prefix)) {
-                        //does an attribute have an namespace?
-                        if (!prefixList.contains(prefix)) {
-                            prefixList.add(prefix);
-                            ComparableNamespace tmpNameSpace = new ComparableNamespace(prefix, attribute.getName().getNamespaceURI());
-                            comparableNamespaceList.add(tmpNameSpace);
+                    if (prefix != null && !prefix.isEmpty()) {
+                        if (!prefixSet.contains(prefix)) {
+                            prefixSet.add(prefix);
+                            comparableNamespaceList.add(new ComparableNamespace(prefix, attributeNameNamespaceURI));
                         }
                         continue;
                     }
                 }
                 //add all attrs with xml - prefix (eg. xml:lang) to attr list:
-                comparableAttributeList.add(new ComparableAttribute(attribute.getName(), attribute.getValue()));
+                comparableAttributeList.add(new ComparableAttribute(attributeName, attribute.getValue()));
             }
 
             nsStack.push(comparableNamespaceList);
@@ -201,10 +205,8 @@ public class XMLSecurityUtils {
 
             return new XMLEventNS(xmlEvent, nsStack.toArray(new List[nsStack.size()]), attrStack.toArray(new List[attrStack.size()]));
         } else if (xmlEvent.isEndElement()) {
-            XMLEventNS xmlEventNS = new XMLEventNS(xmlEvent, nsStack.toArray(new List[nsStack.size()]), attrStack.toArray(new List[attrStack.size()]));
             nsStack.pop();
             attrStack.pop();
-            return xmlEventNS;
         }
         return xmlEvent;
     }
@@ -212,6 +214,9 @@ public class XMLSecurityUtils {
     //todo optimize?
     public static Transformer getTransformer(Object methodParameter1, Object methodParameter2, String algorithm) throws XMLSecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
         Class<Transformer> transformerClass = (Class<Transformer>) TransformerAlgorithmMapper.getTransformerClass(algorithm, null);
+        if (transformerClass == null) {
+            return null;
+        }
         Transformer childTransformer;
         try {
             Constructor<Transformer> constructor = transformerClass.getConstructor(Transformer.class);
@@ -250,13 +255,6 @@ public class XMLSecurityUtils {
     }
 
     public static String getQNameAttribute(Map<QName, String> attributes, QName qName) {
-        Iterator<Map.Entry<QName, String>> attributeIterator = attributes.entrySet().iterator();
-        while (attributeIterator.hasNext()) {
-            Map.Entry<QName, String> entry = attributeIterator.next();
-            if (entry.getKey().equals(qName)) {
-                return entry.getValue();
-            }
-        }
-        return null;
+        return attributes.get(qName);
     }
 }

Modified: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/DocumentContextImpl.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/DocumentContextImpl.java?rev=1337945&r1=1337944&r2=1337945&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/DocumentContextImpl.java (original)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/DocumentContextImpl.java Sun May 13 17:27:10 2012
@@ -32,7 +32,7 @@ import java.util.*;
  */
 public class DocumentContextImpl implements DocumentContext, Cloneable {
 
-    private List<QName> path = new LinkedList<QName>();
+    private List<QName> path = new ArrayList<QName>(20);//the default of 10 is not enough
     private String encoding;
     private Map<Integer, XMLSecurityConstants.ContentType> contentTypeMap = new TreeMap<Integer, XMLSecurityConstants.ContentType>();
     private Map<Object, Integer> processorToIndexMap = new HashMap<Object, Integer>();
@@ -62,7 +62,7 @@ public class DocumentContextImpl impleme
     }
 
     public List<QName> getParentElementPath(int eventType) {
-        List<QName> parentPath = new LinkedList<QName>();
+        List<QName> parentPath = new ArrayList<QName>(this.path.size());
         if (this.path.size() >= 1) {
             parentPath.addAll(this.path.subList(0, this.path.size() - 1));
         }
@@ -103,7 +103,7 @@ public class DocumentContextImpl impleme
 
     @Override
     public List<XMLSecurityConstants.ContentType> getProtectionOrder() {
-        return new LinkedList<XMLSecurityConstants.ContentType>(contentTypeMap.values());
+        return new ArrayList<XMLSecurityConstants.ContentType>(contentTypeMap.values());
     }
 
     public Map<Integer, XMLSecurityConstants.ContentType> getContentTypeMap() {
@@ -117,9 +117,8 @@ public class DocumentContextImpl impleme
     @Override
     protected DocumentContextImpl clone() throws CloneNotSupportedException {
         DocumentContextImpl documentContext = new DocumentContextImpl();
-        List<QName> subPath = new LinkedList<QName>();
-        subPath.addAll(this.path);
         documentContext.setEncoding(this.encoding);
+        List<QName> subPath = new ArrayList<QName>(this.path);
         documentContext.setPath(subPath);
         documentContext.setContentTypeMap(getContentTypeMap());
         return documentContext;

Modified: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/InputProcessorChainImpl.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/InputProcessorChainImpl.java?rev=1337945&r1=1337944&r2=1337945&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/InputProcessorChainImpl.java (original)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/InputProcessorChainImpl.java Sun May 13 17:27:10 2012
@@ -37,8 +37,9 @@ import java.util.List;
 public class InputProcessorChainImpl implements InputProcessorChain {
 
     protected static final transient Log log = LogFactory.getLog(InputProcessorChainImpl.class);
+    protected static final transient boolean isDebugEnabled = log.isDebugEnabled();
 
-    private List<InputProcessor> inputProcessors = Collections.synchronizedList(new ArrayList<InputProcessor>());
+    private List<InputProcessor> inputProcessors = Collections.synchronizedList(new ArrayList<InputProcessor>(20));//the default of ten entries is not enough
     private int startPos = 0;
     private int curPos = 0;
 
@@ -63,20 +64,8 @@ public class InputProcessorChainImpl imp
         documentContext = documentContextImpl;
     }
 
-    public int getCurPos() {
-        return curPos;
-    }
-
-    public void setCurPos(int curPos) {
-        this.curPos = curPos;
-    }
-
-    public int getPosAndIncrement() {
-        return this.curPos++;
-    }
-
     public void reset() {
-        setCurPos(startPos);
+        this.curPos = startPos;
     }
 
     public SecurityContext getSecurityContext() {
@@ -167,7 +156,7 @@ public class InputProcessorChainImpl imp
                 inputProcessors.add(idxToInsert, newInputProcessor);
             }
         }
-        if (log.isDebugEnabled()) {
+        if (isDebugEnabled) {
             log.debug("Added " + newInputProcessor.getClass().getName() + " to input chain: ");
             for (int i = 0; i < inputProcessors.size(); i++) {
                 InputProcessor inputProcessor = inputProcessors.get(i);
@@ -177,8 +166,10 @@ public class InputProcessorChainImpl imp
     }
 
     public void removeProcessor(InputProcessor inputProcessor) {
-        log.debug("Removing processor " + inputProcessor.getClass().getName() + " from input chain");
-        if (this.inputProcessors.indexOf(inputProcessor) <= getCurPos()) {
+        if (isDebugEnabled) {
+            log.debug("Removing processor " + inputProcessor.getClass().getName() + " from input chain");
+        }
+        if (this.inputProcessors.indexOf(inputProcessor) <= curPos) {
             this.curPos--;
         }
         this.inputProcessors.remove(inputProcessor);
@@ -189,15 +180,15 @@ public class InputProcessorChainImpl imp
     }
 
     public XMLEvent processHeaderEvent() throws XMLStreamException, XMLSecurityException {
-        return inputProcessors.get(getPosAndIncrement()).processNextHeaderEvent(this);
+        return inputProcessors.get(this.curPos++).processNextHeaderEvent(this);
     }
 
     public XMLEvent processEvent() throws XMLStreamException, XMLSecurityException {
-        return inputProcessors.get(getPosAndIncrement()).processNextEvent(this);
+        return inputProcessors.get(this.curPos++).processNextEvent(this);
     }
 
     public void doFinal() throws XMLStreamException, XMLSecurityException {
-        inputProcessors.get(getPosAndIncrement()).doFinal(this);
+        inputProcessors.get(this.curPos++).doFinal(this);
     }
 
     public InputProcessorChain createSubChain(InputProcessor inputProcessor) throws XMLStreamException, XMLSecurityException {

Modified: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/OutputProcessorChainImpl.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/OutputProcessorChainImpl.java?rev=1337945&r1=1337944&r2=1337945&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/OutputProcessorChainImpl.java (original)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/OutputProcessorChainImpl.java Sun May 13 17:27:10 2012
@@ -26,7 +26,6 @@ import javax.xml.stream.XMLStreamExcepti
 import javax.xml.stream.events.XMLEvent;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 
 /**
@@ -38,13 +37,14 @@ import java.util.List;
 public class OutputProcessorChainImpl implements OutputProcessorChain {
 
     protected static final transient Log log = LogFactory.getLog(OutputProcessorChainImpl.class);
+    protected static final transient boolean isDebugEnabled = log.isDebugEnabled();
 
-    private List<OutputProcessor> outputProcessors = Collections.synchronizedList(new ArrayList<OutputProcessor>());
+    private List<OutputProcessor> outputProcessors = new ArrayList<OutputProcessor>(20); //the default of ten entries is not enough
     private int startPos = 0;
     private int curPos = 0;
 
-    private ArrayDeque<List<ComparableNamespace>> nsStack = new ArrayDeque<List<ComparableNamespace>>(10);
-    private ArrayDeque<List<ComparableAttribute>> attrStack = new ArrayDeque<List<ComparableAttribute>>(10);
+    private ArrayDeque<List<ComparableNamespace>> nsStack = new ArrayDeque<List<ComparableNamespace>>();
+    private ArrayDeque<List<ComparableAttribute>> attrStack = new ArrayDeque<List<ComparableAttribute>>();
 
     private SecurityContext securityContext;
     private DocumentContextImpl documentContext;
@@ -67,20 +67,8 @@ public class OutputProcessorChainImpl im
         documentContext = documentContextImpl;
     }
 
-    public int getCurPos() {
-        return curPos;
-    }
-
-    public void setCurPos(int curPos) {
-        this.curPos = curPos;
-    }
-
-    public int getPosAndIncrement() {
-        return this.curPos++;
-    }
-
     public void reset() {
-        setCurPos(startPos);
+        this.curPos = startPos;
     }
 
     public SecurityContext getSecurityContext() {
@@ -96,11 +84,11 @@ public class OutputProcessorChainImpl im
     }
 
     private ArrayDeque<List<ComparableNamespace>> getNsStack() {
-        return nsStack.clone();
+        return nsStack;
     }
 
     private void setNsStack(ArrayDeque<List<ComparableNamespace>> nsStack) {
-        this.nsStack = nsStack;
+        this.nsStack = nsStack.clone();
     }
 
     private ArrayDeque<List<ComparableAttribute>> getAttrStack() {
@@ -190,7 +178,7 @@ public class OutputProcessorChainImpl im
         if (idxToInsert < this.curPos) {
             this.curPos++;
         }
-        if (log.isDebugEnabled()) {
+        if (isDebugEnabled) {
             log.debug("Added " + newOutputProcessor.getClass().getName() + " to output chain: ");
             for (int i = 0; i < outputProcessors.size(); i++) {
                 OutputProcessor outputProcessor = outputProcessors.get(i);
@@ -200,8 +188,10 @@ public class OutputProcessorChainImpl im
     }
 
     public void removeProcessor(OutputProcessor outputProcessor) {
-        log.debug("Removing processor " + outputProcessor.getClass().getName() + " from output chain");
-        if (this.outputProcessors.indexOf(outputProcessor) <= getCurPos()) {
+        if (isDebugEnabled) {
+            log.debug("Removing processor " + outputProcessor.getClass().getName() + " from output chain");
+        }
+        if (this.outputProcessors.indexOf(outputProcessor) <= this.curPos) {
             this.curPos--;
         }
         this.outputProcessors.remove(outputProcessor);
@@ -213,18 +203,19 @@ public class OutputProcessorChainImpl im
 
     public void processEvent(XMLEvent xmlEvent) throws XMLStreamException, XMLSecurityException {
         if (this.curPos == this.startPos) {
-            xmlEvent = XMLSecurityUtils.createXMLEventNS(xmlEvent, nsStack, attrStack);
             if (xmlEvent.isStartElement()) {
+                xmlEvent = XMLSecurityUtils.createXMLEventNS(xmlEvent, nsStack, attrStack);
                 getDocumentContext().addPathElement(xmlEvent.asStartElement().getName());
             } else if (xmlEvent.isEndElement()) {
+                xmlEvent = XMLSecurityUtils.createXMLEventNS(xmlEvent, nsStack, attrStack);
                 getDocumentContext().removePathElement();
             }
         }
-        outputProcessors.get(getPosAndIncrement()).processNextEvent(xmlEvent, this);
+        outputProcessors.get(this.curPos++).processNextEvent(xmlEvent, this);
     }
 
     public void doFinal() throws XMLStreamException, XMLSecurityException {
-        outputProcessors.get(getPosAndIncrement()).doFinal(this);
+        outputProcessors.get(this.curPos++).doFinal(this);
     }
 
     public OutputProcessorChain createSubChain(OutputProcessor outputProcessor) throws XMLStreamException, XMLSecurityException {

Modified: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/SecurityContextImpl.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/SecurityContextImpl.java?rev=1337945&r1=1337944&r2=1337945&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/SecurityContextImpl.java (original)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/SecurityContextImpl.java Sun May 13 17:27:10 2012
@@ -79,6 +79,11 @@ public class SecurityContextImpl impleme
         return (List<T>) content.get(key);
     }
 
+    @SuppressWarnings("unchecked")
+    public <T> Set<T> getAsSet(Class key) {
+        return (Set<T>) content.get(key);
+    }
+
     public void registerSecurityTokenProvider(String id, SecurityTokenProvider securityTokenProvider) {
         if (id == null) {
             throw new IllegalArgumentException("Id must not be null");

Modified: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityEventReader.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityEventReader.java?rev=1337945&r1=1337944&r2=1337945&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityEventReader.java (original)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityEventReader.java Sun May 13 17:27:10 2012
@@ -33,7 +33,6 @@ import java.util.NoSuchElementException;
 public class XMLSecurityEventReader implements XMLEventReader {
 
     private Iterator<XMLEvent> xmlEventIterator;
-    private XMLEvent currentXMLEvent;
     private XMLEvent nextXMLEvent;
 
     public XMLSecurityEventReader(Deque<XMLEvent> xmlEvents, int fromIndex) {
@@ -47,16 +46,17 @@ public class XMLSecurityEventReader impl
     @Override
     public XMLEvent nextEvent() throws XMLStreamException {
         if (this.nextXMLEvent != null) {
-            this.currentXMLEvent = this.nextXMLEvent;
+            final XMLEvent currentXMLEvent = this.nextXMLEvent;
             this.nextXMLEvent = null;
-            return this.currentXMLEvent;
+            return currentXMLEvent;
         }
+        final XMLEvent currentXMLEvent;
         try {
-            this.currentXMLEvent = xmlEventIterator.next();
+            currentXMLEvent = xmlEventIterator.next();
         } catch (NoSuchElementException e) {
             throw new XMLStreamException(e);
         }
-        return this.currentXMLEvent;
+        return currentXMLEvent;
     }
 
     @Override

Modified: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityEventWriter.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityEventWriter.java?rev=1337945&r1=1337944&r2=1337945&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityEventWriter.java (original)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityEventWriter.java Sun May 13 17:27:10 2012
@@ -67,11 +67,10 @@ public class XMLSecurityEventWriter impl
 
             case XMLStreamConstants.CHARACTERS:
                 Characters characters = event.asCharacters();
-                String text = characters.getData();
                 if (characters.isCData()) {
-                    this.xmlStreamWriter.writeCData(text);
+                    this.xmlStreamWriter.writeCData(characters.getData());
                 } else {
-                    this.xmlStreamWriter.writeCharacters(text);
+                    this.xmlStreamWriter.writeCharacters(characters.getData());
                 }
                 break;
 

Modified: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityStreamReader.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityStreamReader.java?rev=1337945&r1=1337944&r2=1337945&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityStreamReader.java (original)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityStreamReader.java Sun May 13 17:27:10 2012
@@ -37,9 +37,9 @@ import java.util.Iterator;
  */
 public class XMLSecurityStreamReader implements XMLStreamReader {
 
-    private XMLSecurityProperties securityProperties;
     private InputProcessorChain inputProcessorChain;
     private XMLEvent currentEvent;
+    private boolean skipDocumentEvents = false;
 
     private static final String ERR_STATE_NOT_ELEM = "Current state not START_ELEMENT or END_ELEMENT";
     private static final String ERR_STATE_NOT_STELEM = "Current state not START_ELEMENT";
@@ -47,7 +47,7 @@ public class XMLSecurityStreamReader imp
 
     public XMLSecurityStreamReader(InputProcessorChain inputProcessorChain, XMLSecurityProperties securityProperties) {
         this.inputProcessorChain = inputProcessorChain;
-        this.securityProperties = securityProperties;
+        this.skipDocumentEvents = securityProperties.isSkipDocumentEvents();
     }
 
     public Object getProperty(String name) throws IllegalArgumentException {
@@ -58,20 +58,23 @@ public class XMLSecurityStreamReader imp
     }
 
     public int next() throws XMLStreamException {
+        int eventType;
         try {
             inputProcessorChain.reset();
             currentEvent = inputProcessorChain.processEvent();
-            if ((currentEvent.getEventType() == START_DOCUMENT)
-                    && securityProperties.isSkipDocumentEvents()) {
+            eventType = currentEvent.getEventType();
+            if (eventType == START_DOCUMENT && this.skipDocumentEvents) {
                 currentEvent = inputProcessorChain.processEvent();
+                eventType = currentEvent.getEventType();
             }
         } catch (XMLSecurityException e) {
             throw new XMLStreamException(e);
         }
-        if (currentEvent.isCharacters() && currentEvent.asCharacters().isIgnorableWhiteSpace()) {
+        /*todo why was this needed? Because of the Sun Stax impl?
+         if (currentEvent.isCharacters() && currentEvent.asCharacters().isIgnorableWhiteSpace()) {
             return XMLStreamConstants.SPACE;
-        }
-        return currentEvent.getEventType();
+        }*/
+        return eventType;
     }
 
     private XMLEvent getCurrentEvent() {
@@ -186,31 +189,26 @@ public class XMLSecurityStreamReader imp
     public String getNamespaceURI(String prefix) {
         XMLEvent xmlEvent = getCurrentEvent();
 
-        if (xmlEvent.getEventType() != START_ELEMENT && xmlEvent.getEventType() != END_ELEMENT) {
-            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
-        }
-
-        if (xmlEvent.isStartElement()) {
+        if (xmlEvent.getEventType() == START_ELEMENT) {
             return xmlEvent.asStartElement().getNamespaceURI(prefix);
-        } else {
+        } else if (xmlEvent.getEventType() == END_ELEMENT) {
             //todo somehow...
             return null;
+        } else {
+            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
         }
     }
 
     public boolean isStartElement() {
-        XMLEvent xmlEvent = getCurrentEvent();
-        return xmlEvent.isStartElement();
+        return getCurrentEvent().isStartElement();
     }
 
     public boolean isEndElement() {
-        XMLEvent xmlEvent = getCurrentEvent();
-        return xmlEvent.isEndElement();
+        return getCurrentEvent().isEndElement();
     }
 
     public boolean isCharacters() {
-        XMLEvent xmlEvent = getCurrentEvent();
-        return xmlEvent.isCharacters();
+        return getCurrentEvent().isCharacters();
     }
 
     public boolean isWhiteSpace() {
@@ -374,15 +372,15 @@ public class XMLSecurityStreamReader imp
     @SuppressWarnings("unchecked")
     public int getNamespaceCount() {
         XMLEvent xmlEvent = getCurrentEvent();
-        if (xmlEvent.getEventType() != START_ELEMENT && xmlEvent.getEventType() != END_ELEMENT) {
-            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
-        }
+
         int count = 0;
         Iterator<Namespace> namespaceIterator;
         if (xmlEvent.getEventType() == START_ELEMENT) {
             namespaceIterator = xmlEvent.asStartElement().getNamespaces();
-        } else {
+        } else if (xmlEvent.getEventType() == END_ELEMENT) {
             namespaceIterator = xmlEvent.asEndElement().getNamespaces();
+        } else {
+            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
         }
         while (namespaceIterator.hasNext()) {
             namespaceIterator.next();
@@ -394,15 +392,15 @@ public class XMLSecurityStreamReader imp
     @SuppressWarnings("unchecked")
     public String getNamespacePrefix(int index) {
         XMLEvent xmlEvent = getCurrentEvent();
-        if (xmlEvent.getEventType() != START_ELEMENT && xmlEvent.getEventType() != END_ELEMENT) {
-            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
-        }
+
         int count = 0;
         Iterator<Namespace> namespaceIterator;
         if (xmlEvent.getEventType() == START_ELEMENT) {
             namespaceIterator = xmlEvent.asStartElement().getNamespaces();
-        } else {
+        } else if (xmlEvent.getEventType() == END_ELEMENT) {
             namespaceIterator = xmlEvent.asEndElement().getNamespaces();
+        } else {
+            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
         }
         while (namespaceIterator.hasNext()) {
             Namespace namespace = namespaceIterator.next();
@@ -577,25 +575,25 @@ public class XMLSecurityStreamReader imp
 
     public QName getName() {
         XMLEvent xmlEvent = getCurrentEvent();
-        if (xmlEvent.getEventType() != START_ELEMENT && xmlEvent.getEventType() != END_ELEMENT) {
-            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
-        }
-        if (xmlEvent.isStartElement()) {
+
+        if (xmlEvent.getEventType() == START_ELEMENT) {
             return xmlEvent.asStartElement().getName();
-        } else {
+        } else if (xmlEvent.getEventType() == END_ELEMENT) {
             return xmlEvent.asEndElement().getName();
+        } else {
+            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
         }
     }
 
     public String getLocalName() {
         XMLEvent xmlEvent = getCurrentEvent();
-        if (xmlEvent.getEventType() != START_ELEMENT && xmlEvent.getEventType() != END_ELEMENT) {
-            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
-        }
-        if (xmlEvent.isStartElement()) {
+
+        if (xmlEvent.getEventType() == START_ELEMENT) {
             return xmlEvent.asStartElement().getName().getLocalPart();
-        } else {
+        } else if (xmlEvent.getEventType() == END_ELEMENT) {
             return xmlEvent.asEndElement().getName().getLocalPart();
+        } else {
+            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
         }
     }
 
@@ -609,25 +607,25 @@ public class XMLSecurityStreamReader imp
 
     public String getNamespaceURI() {
         XMLEvent xmlEvent = getCurrentEvent();
-        if (xmlEvent.getEventType() != START_ELEMENT && xmlEvent.getEventType() != END_ELEMENT) {
-            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
-        }
-        if (xmlEvent.isStartElement()) {
+
+        if (xmlEvent.getEventType() == START_ELEMENT) {
             return xmlEvent.asStartElement().getName().getNamespaceURI();
-        } else {
+        } else if (xmlEvent.getEventType() == END_ELEMENT) {
             return xmlEvent.asEndElement().getName().getNamespaceURI();
+        } else {
+            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
         }
     }
 
     public String getPrefix() {
         XMLEvent xmlEvent = getCurrentEvent();
-        if (xmlEvent.getEventType() != START_ELEMENT && xmlEvent.getEventType() != END_ELEMENT) {
-            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
-        }
-        if (xmlEvent.isStartElement()) {
+
+        if (xmlEvent.getEventType() == START_ELEMENT) {
             return xmlEvent.asStartElement().getName().getPrefix();
-        } else {
+        } else if (xmlEvent.getEventType() == END_ELEMENT) {
             return xmlEvent.asEndElement().getName().getPrefix();
+        } else {
+            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
         }
     }
 

Modified: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityStreamWriter.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityStreamWriter.java?rev=1337945&r1=1337944&r2=1337945&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityStreamWriter.java (original)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/XMLSecurityStreamWriter.java Sun May 13 17:27:10 2012
@@ -19,11 +19,15 @@
 package org.swssf.xmlsec.impl;
 
 import org.swssf.xmlsec.ext.OutputProcessorChain;
+import org.swssf.xmlsec.ext.XMLSecurityConstants;
 import org.swssf.xmlsec.ext.XMLSecurityException;
 
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
-import javax.xml.stream.*;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
 import javax.xml.stream.events.*;
 import java.io.Writer;
 import java.util.*;
@@ -36,11 +40,10 @@ import java.util.*;
  */
 public class XMLSecurityStreamWriter implements XMLStreamWriter {
 
-    private XMLEventFactory xmlEventFactory = XMLEventFactory.newInstance();
     private OutputProcessorChain outputProcessorChain;
     private Deque<QName> startElementStack = new ArrayDeque<QName>();
     private QName openStartElement = null;
-    private List<Attribute> currentAttributes = new LinkedList<Attribute>();
+    private List<Attribute> currentAttributes = new ArrayList<Attribute>();
     private Deque<Map<String, Namespace>> nsStack;
     private NamespaceContext namespaceContext;
     private final NamespaceContext defaultNamespaceContext;
@@ -48,8 +51,8 @@ public class XMLSecurityStreamWriter imp
 
     public XMLSecurityStreamWriter(OutputProcessorChain outputProcessorChain) {
         this.outputProcessorChain = outputProcessorChain;
-        nsStack = new LinkedList<Map<String, Namespace>>();
-        nsStack.push(new LinkedHashMap<String, Namespace>());
+        nsStack = new ArrayDeque<Map<String, Namespace>>();
+        nsStack.push(Collections.<String, Namespace>emptyMap());
 
         defaultNamespaceContext = new NamespaceContext() {
             @Override
@@ -57,12 +60,9 @@ public class XMLSecurityStreamWriter imp
                 Iterator<Map<String, Namespace>> stackIterator = nsStack.iterator();
                 while (stackIterator.hasNext()) {
                     Map<String, Namespace> next = stackIterator.next();
-                    Iterator<Map.Entry<String, Namespace>> mapIterator = next.entrySet().iterator();
-                    while (mapIterator.hasNext()) {
-                        Map.Entry<String, Namespace> entry = mapIterator.next();
-                        if (prefix.equals(entry.getKey())) {
-                            return entry.getValue().getNamespaceURI();
-                        }
+                    Namespace ns = next.get(prefix);
+                    if (ns != null) {
+                        return ns.getNamespaceURI();
                     }
                 }
                 if (namespaceContext != null) {
@@ -92,7 +92,7 @@ public class XMLSecurityStreamWriter imp
 
             @Override
             public Iterator getPrefixes(String namespaceURI) {
-                List<String> prefixList = new ArrayList<String>();
+                List<String> prefixList = new ArrayList<String>(1);
                 if (namespaceContext != null) {
                     Iterator<String> iterator = namespaceContext.getPrefixes(namespaceURI);
                     while (iterator.hasNext()) {
@@ -119,6 +119,16 @@ public class XMLSecurityStreamWriter imp
         };
     }
 
+    private void putNamespaceOntoStack(String prefix, Namespace namespace) {
+        Map<String, Namespace> namespaceMap = nsStack.peek();
+        if (Collections.<String, Namespace>emptyMap() == namespaceMap) {
+            nsStack.pop();
+            namespaceMap = new HashMap<String, Namespace>();
+            nsStack.push(namespaceMap);
+        }
+        namespaceMap.put(prefix, namespace);
+    }
+
     private void chainProcessEvent(XMLEvent xmlEvent) throws XMLStreamException {
         try {
             outputProcessorChain.reset();
@@ -141,7 +151,7 @@ public class XMLSecurityStreamWriter imp
 
     private void outputOpenStartElement() throws XMLStreamException {
         if (openStartElement != null) {
-            chainProcessEvent(xmlEventFactory.createStartElement(openStartElement, currentAttributes.iterator(), nsStack.peek().values().iterator()));
+            chainProcessEvent(XMLSecurityConstants.XMLEVENTFACTORY.createStartElement(openStartElement, currentAttributes.iterator(), nsStack.peek().values().iterator()));
             currentAttributes.clear();
             openStartElement = null;
         }
@@ -149,7 +159,7 @@ public class XMLSecurityStreamWriter imp
             haveToWriteEndElement = false;
             writeEndElement();
         }
-        nsStack.push(new LinkedHashMap<String, Namespace>());
+        nsStack.push(Collections.<String, Namespace>emptyMap());
     }
 
     public void writeStartElement(String localName) throws XMLStreamException {
@@ -194,10 +204,10 @@ public class XMLSecurityStreamWriter imp
 
     public void writeEndElement() throws XMLStreamException {
         outputOpenStartElement();
-        List<Namespace> namespaceList = new LinkedList<Namespace>();
+        List<Namespace> namespaceList = new ArrayList<Namespace>(1);
         QName element = startElementStack.pop();
-        namespaceList.add(xmlEventFactory.createNamespace(element.getPrefix(), element.getNamespaceURI()));
-        EndElement endElement = xmlEventFactory.createEndElement(element, namespaceList.iterator());
+        namespaceList.add(XMLSecurityConstants.XMLEVENTFACTORY.createNamespace(element.getPrefix(), element.getNamespaceURI()));
+        EndElement endElement = XMLSecurityConstants.XMLEVENTFACTORY.createEndElement(element, namespaceList.iterator());
         chainProcessEvent(endElement);
         nsStack.pop();
     }
@@ -206,9 +216,9 @@ public class XMLSecurityStreamWriter imp
         outputOpenStartElement();
         Iterator<QName> startElements = startElementStack.iterator();
         while (startElements.hasNext()) {
-            chainProcessEvent(xmlEventFactory.createEndElement(startElements.next(), null));
+            chainProcessEvent(XMLSecurityConstants.XMLEVENTFACTORY.createEndElement(startElements.next(), null));
         }
-        chainProcessEvent(xmlEventFactory.createEndDocument());
+        chainProcessEvent(XMLSecurityConstants.XMLEVENTFACTORY.createEndDocument());
     }
 
     public void close() throws XMLStreamException {
@@ -225,53 +235,53 @@ public class XMLSecurityStreamWriter imp
     }
 
     public void writeAttribute(String localName, String value) throws XMLStreamException {
-        currentAttributes.add(xmlEventFactory.createAttribute(localName, value));
+        currentAttributes.add(XMLSecurityConstants.XMLEVENTFACTORY.createAttribute(localName, value));
     }
 
     public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException {
-        currentAttributes.add(xmlEventFactory.createAttribute(prefix, namespaceURI, localName, value));
+        currentAttributes.add(XMLSecurityConstants.XMLEVENTFACTORY.createAttribute(prefix, namespaceURI, localName, value));
     }
 
     public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException {
-        currentAttributes.add(xmlEventFactory.createAttribute(getNamespaceContext().getPrefix(namespaceURI), namespaceURI, localName, value));
+        currentAttributes.add(XMLSecurityConstants.XMLEVENTFACTORY.createAttribute(getNamespaceContext().getPrefix(namespaceURI), namespaceURI, localName, value));
     }
 
     public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
-        nsStack.peek().put(prefix, xmlEventFactory.createNamespace(prefix, namespaceURI));
+        putNamespaceOntoStack(prefix, XMLSecurityConstants.XMLEVENTFACTORY.createNamespace(prefix, namespaceURI));
     }
 
     public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
-        nsStack.peek().put("", xmlEventFactory.createNamespace(namespaceURI));
+        putNamespaceOntoStack("", XMLSecurityConstants.XMLEVENTFACTORY.createNamespace(namespaceURI));
     }
 
     public void writeComment(String data) throws XMLStreamException {
         outputOpenStartElement();
-        chainProcessEvent(xmlEventFactory.createComment(data));
+        chainProcessEvent(XMLSecurityConstants.XMLEVENTFACTORY.createComment(data));
     }
 
     public void writeProcessingInstruction(String target) throws XMLStreamException {
         outputOpenStartElement();
-        chainProcessEvent(xmlEventFactory.createProcessingInstruction(target, null));
+        chainProcessEvent(XMLSecurityConstants.XMLEVENTFACTORY.createProcessingInstruction(target, null));
     }
 
     public void writeProcessingInstruction(String target, String data) throws XMLStreamException {
         outputOpenStartElement();
-        chainProcessEvent(xmlEventFactory.createProcessingInstruction(target, data));
+        chainProcessEvent(XMLSecurityConstants.XMLEVENTFACTORY.createProcessingInstruction(target, data));
     }
 
     public void writeCData(String data) throws XMLStreamException {
         outputOpenStartElement();
-        chainProcessEvent(xmlEventFactory.createCData(data));
+        chainProcessEvent(XMLSecurityConstants.XMLEVENTFACTORY.createCData(data));
     }
 
     public void writeDTD(String dtd) throws XMLStreamException {
         outputOpenStartElement();
-        chainProcessEvent(xmlEventFactory.createDTD(dtd));
+        chainProcessEvent(XMLSecurityConstants.XMLEVENTFACTORY.createDTD(dtd));
     }
 
     public void writeEntityRef(final String name) throws XMLStreamException {
         outputOpenStartElement();
-        chainProcessEvent(xmlEventFactory.createEntityReference(name, new EntityDeclaration() {
+        chainProcessEvent(XMLSecurityConstants.XMLEVENTFACTORY.createEntityReference(name, new EntityDeclaration() {
             @Override
             public String getPublicId() {
                 return null;
@@ -384,25 +394,25 @@ public class XMLSecurityStreamWriter imp
     }
 
     public void writeStartDocument() throws XMLStreamException {
-        chainProcessEvent(xmlEventFactory.createStartDocument());
+        chainProcessEvent(XMLSecurityConstants.XMLEVENTFACTORY.createStartDocument());
     }
 
     public void writeStartDocument(String version) throws XMLStreamException {
-        chainProcessEvent(xmlEventFactory.createStartDocument("utf-8", version));
+        chainProcessEvent(XMLSecurityConstants.XMLEVENTFACTORY.createStartDocument("utf-8", version));
     }
 
     public void writeStartDocument(String encoding, String version) throws XMLStreamException {
-        chainProcessEvent(xmlEventFactory.createStartDocument(encoding, version));
+        chainProcessEvent(XMLSecurityConstants.XMLEVENTFACTORY.createStartDocument(encoding, version));
     }
 
     public void writeCharacters(String text) throws XMLStreamException {
         outputOpenStartElement();
-        chainProcessEvent(xmlEventFactory.createCharacters(text));
+        chainProcessEvent(XMLSecurityConstants.XMLEVENTFACTORY.createCharacters(text));
     }
 
     public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {
         outputOpenStartElement();
-        chainProcessEvent(xmlEventFactory.createCharacters(new String(text, start, len)));
+        chainProcessEvent(XMLSecurityConstants.XMLEVENTFACTORY.createCharacters(new String(text, start, len)));
     }
 
     public String getPrefix(String uri) throws XMLStreamException {
@@ -410,7 +420,7 @@ public class XMLSecurityStreamWriter imp
     }
 
     public void setPrefix(String prefix, String uri) throws XMLStreamException {
-        nsStack.peek().put(prefix, xmlEventFactory.createNamespace(prefix, uri));
+        putNamespaceOntoStack(prefix, XMLSecurityConstants.XMLEVENTFACTORY.createNamespace(prefix, uri));
         if (openStartElement != null) {
             if (openStartElement.getNamespaceURI().equals(uri)) {
                 openStartElement = new QName(openStartElement.getNamespaceURI(), openStartElement.getLocalPart(), prefix);
@@ -419,7 +429,7 @@ public class XMLSecurityStreamWriter imp
     }
 
     public void setDefaultNamespace(String uri) throws XMLStreamException {
-        nsStack.peek().put("", xmlEventFactory.createNamespace("", uri));
+        putNamespaceOntoStack("", XMLSecurityConstants.XMLEVENTFACTORY.createNamespace("", uri));
     }
 
     public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {

Modified: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/algorithms/ECDSAUtils.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/algorithms/ECDSAUtils.java?rev=1337945&r1=1337944&r2=1337945&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/algorithms/ECDSAUtils.java (original)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/algorithms/ECDSAUtils.java Sun May 13 17:27:10 2012
@@ -22,8 +22,8 @@ import java.io.IOException;
 import java.math.BigInteger;
 import java.security.interfaces.ECPublicKey;
 import java.security.spec.*;
+import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.List;
 
 /**
@@ -158,7 +158,7 @@ public final class ECDSAUtils {
         return asn1Bytes;
     }
 
-    private static List<ECCurveDefinition> ecCurveDefinitions = new LinkedList<ECCurveDefinition>();
+    private static List<ECCurveDefinition> ecCurveDefinitions = new ArrayList<ECCurveDefinition>();
 
     static {
         ecCurveDefinitions.add(

Modified: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/algorithms/HMACSignatureAlgorithm.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/algorithms/HMACSignatureAlgorithm.java?rev=1337945&r1=1337944&r2=1337945&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/algorithms/HMACSignatureAlgorithm.java (original)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/algorithms/HMACSignatureAlgorithm.java Sun May 13 17:27:10 2012
@@ -31,12 +31,14 @@ import java.security.spec.AlgorithmParam
  */
 public class HMACSignatureAlgorithm implements SignatureAlgorithm {
 
-    private AlgorithmType algorithmType;
     private Mac mac;
 
     public HMACSignatureAlgorithm(AlgorithmType algorithmType) throws NoSuchProviderException, NoSuchAlgorithmException {
-        this.algorithmType = algorithmType;
-        mac = Mac.getInstance(algorithmType.getJCEName(), algorithmType.getJCEProvider());
+        if (algorithmType.getJCEProvider() != null) {
+            mac = Mac.getInstance(algorithmType.getJCEName(), algorithmType.getJCEProvider());
+        } else {
+            mac = Mac.getInstance(algorithmType.getJCEName());
+        }
     }
 
     public void engineUpdate(byte[] input) throws XMLSecurityException {

Modified: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/algorithms/PKISignatureAlgorithm.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/algorithms/PKISignatureAlgorithm.java?rev=1337945&r1=1337944&r2=1337945&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/algorithms/PKISignatureAlgorithm.java (original)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/algorithms/PKISignatureAlgorithm.java Sun May 13 17:27:10 2012
@@ -31,12 +31,16 @@ import java.security.spec.AlgorithmParam
  */
 public class PKISignatureAlgorithm implements SignatureAlgorithm {
 
-    private AlgorithmType algorithmType;
+    private String jceName;
     private Signature signature;
 
     public PKISignatureAlgorithm(AlgorithmType algorithmType) throws NoSuchProviderException, NoSuchAlgorithmException {
-        this.algorithmType = algorithmType;
-        signature = Signature.getInstance(algorithmType.getJCEName(), algorithmType.getJCEProvider());
+        this.jceName = algorithmType.getJCEName();
+        if (algorithmType.getJCEProvider() != null) {
+            signature = Signature.getInstance(this.jceName, algorithmType.getJCEProvider());
+        } else {
+            signature = Signature.getInstance(this.jceName);
+        }
     }
 
     public void engineUpdate(byte[] input) throws XMLSecurityException {
@@ -90,9 +94,9 @@ public class PKISignatureAlgorithm imple
     public byte[] engineSign() throws XMLSecurityException {
         try {
             byte[] jcebytes = signature.sign();
-            if (algorithmType.getJCEName().contains("ECDSA")) {
+            if (this.jceName.contains("ECDSA")) {
                 return ECDSAUtils.convertASN1toXMLDSIG(jcebytes);
-            } else if (algorithmType.getJCEName().contains("DSA")) {
+            } else if (this.jceName.contains("DSA")) {
                 return DSAUtils.convertASN1toXMLDSIG(jcebytes);
             }
             return jcebytes;
@@ -114,9 +118,9 @@ public class PKISignatureAlgorithm imple
     public boolean engineVerify(byte[] signature) throws XMLSecurityException {
         try {
             byte[] jcebytes = signature;
-            if (algorithmType.getJCEName().contains("ECDSA")) {
+            if (this.jceName.contains("ECDSA")) {
                 jcebytes = ECDSAUtils.convertXMLDSIGtoASN1(jcebytes);
-            } else if (algorithmType.getJCEName().contains("DSA")) {
+            } else if (this.jceName.contains("DSA")) {
                 jcebytes = DSAUtils.convertXMLDSIGtoASN1(jcebytes);
             }
             return this.signature.verify(jcebytes);

Modified: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/algorithms/SignatureAlgorithm.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/algorithms/SignatureAlgorithm.java?rev=1337945&r1=1337944&r2=1337945&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/algorithms/SignatureAlgorithm.java (original)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/algorithms/SignatureAlgorithm.java Sun May 13 17:27:10 2012
@@ -30,23 +30,23 @@ import java.security.spec.AlgorithmParam
  */
 public interface SignatureAlgorithm {
 
-    public void engineUpdate(byte[] input) throws XMLSecurityException;
+    void engineUpdate(byte[] input) throws XMLSecurityException;
 
-    public void engineUpdate(byte input) throws XMLSecurityException;
+    void engineUpdate(byte input) throws XMLSecurityException;
 
-    public void engineUpdate(byte buf[], int offset, int len) throws XMLSecurityException;
+    void engineUpdate(byte buf[], int offset, int len) throws XMLSecurityException;
 
-    public void engineInitSign(Key signingKey) throws XMLSecurityException;
+    void engineInitSign(Key signingKey) throws XMLSecurityException;
 
-    public void engineInitSign(Key signingKey, SecureRandom secureRandom) throws XMLSecurityException;
+    void engineInitSign(Key signingKey, SecureRandom secureRandom) throws XMLSecurityException;
 
-    public void engineInitSign(Key signingKey, AlgorithmParameterSpec algorithmParameterSpec) throws XMLSecurityException;
+    void engineInitSign(Key signingKey, AlgorithmParameterSpec algorithmParameterSpec) throws XMLSecurityException;
 
-    public byte[] engineSign() throws XMLSecurityException;
+    byte[] engineSign() throws XMLSecurityException;
 
-    public void engineInitVerify(Key verificationKey) throws XMLSecurityException;
+    void engineInitVerify(Key verificationKey) throws XMLSecurityException;
 
-    public boolean engineVerify(byte[] signature) throws XMLSecurityException;
+    boolean engineVerify(byte[] signature) throws XMLSecurityException;
 
-    public void engineSetParameter(AlgorithmParameterSpec params) throws XMLSecurityException;
+    void engineSetParameter(AlgorithmParameterSpec params) throws XMLSecurityException;
 }

Modified: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/processor/input/AbstractDecryptInputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/processor/input/AbstractDecryptInputProcessor.java?rev=1337945&r1=1337944&r2=1337945&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/processor/input/AbstractDecryptInputProcessor.java (original)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/processor/input/AbstractDecryptInputProcessor.java Sun May 13 17:27:10 2012
@@ -19,6 +19,8 @@
 package org.swssf.xmlsec.impl.processor.input;
 
 import org.apache.commons.codec.binary.Base64OutputStream;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.swssf.binding.xmldsig.KeyInfoType;
 import org.swssf.binding.xmldsig.TransformType;
 import org.swssf.binding.xmldsig.TransformsType;
@@ -66,9 +68,11 @@ import java.util.*;
  */
 public abstract class AbstractDecryptInputProcessor extends AbstractInputProcessor {
 
-    private ReferenceList referenceList;
+    private static final transient Log logger = LogFactory.getLog(AbstractDecryptInputProcessor.class);
+
     private KeyInfoType keyInfoType;
-    private List<ReferenceType> processedReferences = new ArrayList<ReferenceType>();
+    private Map<String, ReferenceType> references;
+    private List<ReferenceType> processedReferences;
 
     private final String uuid = IDGenerator.generateID(null);
     private final QName wrapperElementName = new QName("http://dummy", "dummy", uuid);
@@ -80,35 +84,36 @@ public abstract class AbstractDecryptInp
                                          XMLSecurityProperties securityProperties) throws XMLSecurityException {
         super(securityProperties);
         this.keyInfoType = keyInfoType;
-        this.referenceList = referenceList;
 
-        if (referenceList != null) {
-            List<JAXBElement<ReferenceType>> references = referenceList.getDataReferenceOrKeyReference();
-            Iterator<JAXBElement<ReferenceType>> referenceTypeIterator = references.iterator();
-            while (referenceTypeIterator.hasNext()) {
-                ReferenceType referenceType = referenceTypeIterator.next().getValue();
-                if (referenceType.getURI() == null) {
-                    throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK);
-                }
+        final List<JAXBElement<ReferenceType>> dataReferenceOrKeyReference = referenceList.getDataReferenceOrKeyReference();
+        references = new HashMap<String, ReferenceType>(dataReferenceOrKeyReference.size() + 1); //+1 because the HashMap will resize otherwise
+        processedReferences = new ArrayList<ReferenceType>(dataReferenceOrKeyReference.size());
+
+        Iterator<JAXBElement<ReferenceType>> referenceTypeIterator = dataReferenceOrKeyReference.iterator();
+        while (referenceTypeIterator.hasNext()) {
+            ReferenceType referenceType = referenceTypeIterator.next().getValue();
+            if (referenceType.getURI() == null) {
+                throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK);
             }
+            references.put(XMLSecurityUtils.dropReferenceMarker(referenceType.getURI()), referenceType);
         }
     }
 
     /*
-    <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="EncDataId-1612925417" Type="http://www.w3.org/2001/04/xmlenc#Content">
-        <xenc:EncryptionMethod xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" />
-        <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
-            <wsse:SecurityTokenReference xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
-                <wsse:Reference xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" URI="#EncKeyId-1483925398" />
-            </wsse:SecurityTokenReference>
-        </ds:KeyInfo>
-        <xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
-            <xenc:CipherValue xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
-            ...
-            </xenc:CipherValue>
-        </xenc:CipherData>
-    </xenc:EncryptedData>
-     */
+   <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="EncDataId-1612925417" Type="http://www.w3.org/2001/04/xmlenc#Content">
+       <xenc:EncryptionMethod xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" />
+       <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
+           <wsse:SecurityTokenReference xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
+               <wsse:Reference xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" URI="#EncKeyId-1483925398" />
+           </wsse:SecurityTokenReference>
+       </ds:KeyInfo>
+       <xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
+           <xenc:CipherValue xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
+           ...
+           </xenc:CipherValue>
+       </xenc:CipherData>
+   </xenc:EncryptedData>
+    */
 
     @Override
     public XMLEvent processNextHeaderEvent(InputProcessorChain inputProcessorChain) throws XMLStreamException, XMLSecurityException {
@@ -286,7 +291,7 @@ public abstract class AbstractDecryptInp
         writer.write('\"');
 
         //apply all namespaces from current scope to get a valid documentfragment:
-        List<ComparableNamespace> comparableNamespacesToApply = new LinkedList<ComparableNamespace>();
+        List<ComparableNamespace> comparableNamespacesToApply = new ArrayList<ComparableNamespace>();
         List<ComparableNamespace>[] comparableNamespaceList = startXMLElement.getNamespaceList();
         for (int i = 0; i < comparableNamespaceList.length; i++) {
             List<ComparableNamespace> comparableNamespaces = comparableNamespaceList[i];
@@ -338,7 +343,11 @@ public abstract class AbstractDecryptInp
         Cipher symCipher;
         try {
             AlgorithmType symEncAlgo = JCEAlgorithmMapper.getAlgorithmMapping(algorithmURI);
-            symCipher = Cipher.getInstance(symEncAlgo.getJCEName(), symEncAlgo.getJCEProvider());
+            if (symEncAlgo.getJCEProvider() != null) {
+                symCipher = Cipher.getInstance(symEncAlgo.getJCEName(), symEncAlgo.getJCEProvider());
+            } else {
+                symCipher = Cipher.getInstance(symEncAlgo.getJCEName());
+            }
             //we have to defer the initialization of the cipher until we can extract the IV...
         } catch (NoSuchAlgorithmException e) {
             throw new XMLSecurityException(
@@ -370,8 +379,11 @@ public abstract class AbstractDecryptInp
                 getSecurityProperties().getCallbackHandler(), inputProcessorChain.getSecurityContext());
     }
 
-    private EncryptedDataType parseEncryptedDataStructure(boolean isSecurityHeaderEvent, XMLEvent xmlEvent, InputProcessorChain subInputProcessorChain) throws XMLStreamException, XMLSecurityException {
-        Deque<XMLEvent> xmlEvents = new LinkedList<XMLEvent>();
+    private EncryptedDataType parseEncryptedDataStructure(
+            boolean isSecurityHeaderEvent, XMLEvent xmlEvent, InputProcessorChain subInputProcessorChain)
+            throws XMLStreamException, XMLSecurityException {
+
+        Deque<XMLEvent> xmlEvents = new ArrayDeque<XMLEvent>();
         xmlEvents.push(xmlEvent);
         XMLEvent encryptedDataXMLEvent;
         int count = 0;
@@ -419,7 +431,8 @@ public abstract class AbstractDecryptInp
         return xmlEvent;
     }
 
-    private XMLEvent readAndBufferEncryptedHeader(InputProcessorChain inputProcessorChain, boolean isSecurityHeaderEvent, XMLEvent xmlEvent) throws XMLStreamException, XMLSecurityException {
+    private XMLEvent readAndBufferEncryptedHeader(InputProcessorChain inputProcessorChain, boolean isSecurityHeaderEvent,
+                                                  XMLEvent xmlEvent) throws XMLStreamException, XMLSecurityException {
         InputProcessorChain subInputProcessorChain = inputProcessorChain.createSubChain(this);
         do {
             tmpXmlEventList.push(xmlEvent);
@@ -470,16 +483,8 @@ public abstract class AbstractDecryptInp
 
         Attribute refId = getReferenceIDAttribute(startElement);
         if (refId != null) {
-            //exists the id in the referenceList?
-            List<JAXBElement<ReferenceType>> references = referenceList.getDataReferenceOrKeyReference();
-            Iterator<JAXBElement<ReferenceType>> referenceTypeIterator = references.iterator();
-            while (referenceTypeIterator.hasNext()) {
-                ReferenceType referenceType = referenceTypeIterator.next().getValue();
-                if (refId.getValue().equals(XMLSecurityUtils.dropReferenceMarker(referenceType.getURI()))) {
-                    logger.debug("Found encryption reference: " + refId.getValue() + " on element" + startElement.getName());
-                    return referenceType;
-                }
-            }
+            //does the id exist in the referenceList?
+            return this.references.get(refId.getValue());
         }
         return null;
     }
@@ -487,11 +492,10 @@ public abstract class AbstractDecryptInp
     @Override
     public void doFinal(InputProcessorChain inputProcessorChain) throws XMLStreamException, XMLSecurityException {
         //here we check if all references where processed.
-        List<JAXBElement<ReferenceType>> references = referenceList.getDataReferenceOrKeyReference();
-        Iterator<JAXBElement<ReferenceType>> referenceTypeIterator = references.iterator();
-        while (referenceTypeIterator.hasNext()) {
-            ReferenceType referenceType = referenceTypeIterator.next().getValue();
-            if (!processedReferences.contains(referenceType)) {
+        Iterator<Map.Entry<String, ReferenceType>> refEntryIterator = this.references.entrySet().iterator();
+        while (refEntryIterator.hasNext()) {
+            Map.Entry<String, ReferenceType> referenceTypeEntry = refEntryIterator.next();
+            if (!processedReferences.contains(referenceTypeEntry.getValue())) {
                 throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, "unprocessedEncryptionReferences");
             }
         }
@@ -505,8 +509,8 @@ public abstract class AbstractDecryptInp
     public abstract class AbstractDecryptedEventReaderInputProcessor extends AbstractInputProcessor implements Thread.UncaughtExceptionHandler {
 
         private XMLEventReader xmlEventReader;
-        private Deque<List<ComparableNamespace>> nsStack = new ArrayDeque<List<ComparableNamespace>>(10);
-        private Deque<List<ComparableAttribute>> attrStack = new ArrayDeque<List<ComparableAttribute>>(10);
+        private Deque<List<ComparableNamespace>> nsStack = new ArrayDeque<List<ComparableNamespace>>();
+        private Deque<List<ComparableAttribute>> attrStack = new ArrayDeque<List<ComparableAttribute>>();
         private SecurePart.Modifier encryptionModifier;
         private boolean encryptedHeader = false;
         private int documentLevel = 0;
@@ -522,7 +526,7 @@ public abstract class AbstractDecryptInp
                 SecurityToken securityToken
         ) {
             super(securityProperties);
-            getAfterProcessors().add(abstractDecryptInputProcessor);
+            addAfterProcessor(abstractDecryptInputProcessor);
             this.encryptionModifier = encryptionModifier;
             this.rootElementProcessed = encryptionModifier != SecurePart.Modifier.Element;
             this.encryptedHeader = encryptedHeader;
@@ -567,10 +571,13 @@ public abstract class AbstractDecryptInp
                     handleEncryptedElement(inputProcessorChain, xmlEvent, this.securityToken);
                     rootElementProcessed = true;
                 }
+                if (!(xmlEvent instanceof XMLEventNS)) {
+                    xmlEvent = XMLSecurityUtils.createXMLEventNS(xmlEvent, nsStack, attrStack);
+                }
 
             } else if (xmlEvent.isEndElement()) {
 
-                if (xmlEvent.isEndElement() && xmlEvent.asEndElement().getName().equals(wrapperElementName)) {
+                if (xmlEvent.asEndElement().getName().equals(wrapperElementName)) {
                     //correct path and skip EndElements:
                     InputProcessorChain subInputProcessorChain = inputProcessorChain.createSubChain(this);
 
@@ -614,17 +621,15 @@ public abstract class AbstractDecryptInp
                 }
 
                 documentLevel--;
-            }
-
-            if (!(xmlEvent instanceof XMLEventNS)) {
-                xmlEvent = XMLSecurityUtils.createXMLEventNS(xmlEvent, nsStack, attrStack);
+                nsStack.pop();
+                attrStack.pop();
             }
             return xmlEvent;
         }
 
         protected abstract void handleEncryptedElement(InputProcessorChain inputProcessorChain, XMLEvent xmlEvent, SecurityToken securityToken) throws XMLSecurityException;
 
-        private Throwable thrownException;
+        private volatile Throwable thrownException;
 
         public void uncaughtException(Thread t, Throwable e) {
             this.thrownException = e;
@@ -663,8 +668,7 @@ public abstract class AbstractDecryptInp
             this.startXMLElement = startXMLElement;
 
             //prepare the piped streams and connect them:
-            //5 * 8192 seems to be a fine value
-            this.pipedInputStream = new PipedInputStream(40960);
+            this.pipedInputStream = new PipedInputStream(8192);
             try {
                 this.pipedOutputStream = new PipedOutputStream(pipedInputStream);
             } catch (IOException e) {
@@ -694,22 +698,23 @@ public abstract class AbstractDecryptInp
                 //buffering seems not to help
                 //bufferedOutputStream = new BufferedOutputStream(new Base64OutputStream(ivSplittingOutputStream, false), 8192 * 5);
                 ReplaceableOuputStream replaceableOuputStream = new ReplaceableOuputStream(ivSplittingOutputStream);
-                OutputStream decryptOutputStream = new Base64OutputStream(replaceableOuputStream, false);
+                OutputStream base64OutputStream = new Base64OutputStream(replaceableOuputStream, false);
                 ivSplittingOutputStream.setParentOutputStream(replaceableOuputStream);
+                OutputStreamWriter outputStreamWriter = new OutputStreamWriter(base64OutputStream, inputProcessorChain.getDocumentContext().getEncoding());
 
                 //read the encrypted data from the stream until an end-element occurs and write then
                 //to the decrypter-stream
-                boolean finished = false;
-                while (!finished) {
+                exitLoop:
+                while (true) {
                     XMLEvent xmlEvent = processNextEvent();
 
                     switch (xmlEvent.getEventType()) {
                         case XMLStreamConstants.END_ELEMENT:
-                            //this must be the CipherValue EndElement.
-                            finished = true;
-                            break;
+                            //this must be the CipherValue EndElement.                            
+                            break exitLoop;
                         case XMLStreamConstants.CHARACTERS:
-                            decryptOutputStream.write(xmlEvent.asCharacters().getData().getBytes(inputProcessorChain.getDocumentContext().getEncoding()));
+                            final String data = xmlEvent.asCharacters().getData();
+                            outputStreamWriter.write(data, 0, data.length());
                             break;
                         default:
                             throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, "unexpectedXMLEvent", XMLSecurityUtils.getXMLEventAsString(xmlEvent));
@@ -717,10 +722,17 @@ public abstract class AbstractDecryptInp
                 }
 
                 //close to get Cipher.doFinal() called
-                decryptOutputStream.close();
+                outputStreamWriter.close();
                 logger.debug("Decryption thread finished");
 
             } catch (Exception e) {
+                try {
+                    //we have to close the pipe when an exception occurs. Otherwise we can run into a deadlock when an exception occurs
+                    //before we have written any byte to the pipe.
+                    this.pipedOutputStream.close();
+                } catch (IOException e1) {
+                    //ignore since we will throw the original exception below
+                }
                 throw new UncheckedXMLSecurityException(e);
             }
         }

Modified: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java?rev=1337945&r1=1337944&r2=1337945&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java (original)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java Sun May 13 17:27:10 2012
@@ -19,6 +19,8 @@
 package org.swssf.xmlsec.impl.processor.input;
 
 import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.swssf.binding.excc14n.InclusiveNamespaces;
 import org.swssf.binding.xmldsig.ReferenceType;
 import org.swssf.binding.xmldsig.SignatureType;
@@ -41,8 +43,7 @@ import java.lang.reflect.InvocationTarge
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.security.NoSuchProviderException;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
 
 /**
  * @author $Author$
@@ -50,14 +51,33 @@ import java.util.List;
  */
 public abstract class AbstractSignatureReferenceVerifyInputProcessor extends AbstractInputProcessor {
 
+    private static final transient Log logger = LogFactory.getLog(AbstractSignatureReferenceVerifyInputProcessor.class);
+
     private SignatureType signatureType;
     private SecurityToken securityToken;
-    private List<ReferenceType> processedReferences = new ArrayList<ReferenceType>();
+    private Map<String, ReferenceType> references;
+    private List<ReferenceType> processedReferences;
 
-    public AbstractSignatureReferenceVerifyInputProcessor(SignatureType signatureType, SecurityToken securityToken, XMLSecurityProperties securityProperties) {
+    public AbstractSignatureReferenceVerifyInputProcessor(SignatureType signatureType, SecurityToken securityToken,
+                                                          XMLSecurityProperties securityProperties) throws XMLSecurityException {
         super(securityProperties);
         this.signatureType = signatureType;
         this.securityToken = securityToken;
+
+        List<ReferenceType> referencesTypeList = signatureType.getSignedInfo().getReference();
+        references = new HashMap<String, ReferenceType>(referencesTypeList.size() + 1);
+        processedReferences = new ArrayList<ReferenceType>(referencesTypeList.size());
+
+        //if (referenceList != null) {
+        Iterator<ReferenceType> referenceTypeIterator = referencesTypeList.iterator();
+        while (referenceTypeIterator.hasNext()) {
+            ReferenceType referenceType = referenceTypeIterator.next();
+            if (referenceType.getURI() == null) {
+                throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK);
+            }
+            references.put(XMLSecurityUtils.dropReferenceMarker(referenceType.getURI()), referenceType);
+        }
+        //}
     }
 
     public SignatureType getSignatureType() {
@@ -107,25 +127,18 @@ public abstract class AbstractSignatureR
     protected ReferenceType matchesReferenceId(StartElement startElement) {
         Attribute refId = getReferenceIDAttribute(startElement);
         if (refId != null) {
-            List<ReferenceType> references = getSignatureType().getSignedInfo().getReference();
-            for (int i = 0; i < references.size(); i++) {
-                ReferenceType referenceType = references.get(i);
-                if (refId.getValue().equals(XMLSecurityUtils.dropReferenceMarker(referenceType.getURI()))) {
-                    logger.debug("Found signature reference: " + refId.getValue() + " on element" + startElement.getName());
-                    return referenceType;
-                }
-            }
+            return references.get(refId.getValue());
         }
         return null;
     }
 
     @Override
     public void doFinal(InputProcessorChain inputProcessorChain) throws XMLStreamException, XMLSecurityException {
-        List<ReferenceType> references = getSignatureType().getSignedInfo().getReference();
-        for (int i = 0; i < references.size(); i++) {
-            ReferenceType referenceType = references.get(i);
-            if (!processedReferences.contains(referenceType)) {
-                throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, "unprocessedSignatureReferences");
+        Iterator<Map.Entry<String, ReferenceType>> refEntryIterator = this.references.entrySet().iterator();
+        while (refEntryIterator.hasNext()) {
+            Map.Entry<String, ReferenceType> referenceTypeEntry = refEntryIterator.next();
+            if (!processedReferences.contains(referenceTypeEntry.getValue())) {
+                throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILED_CHECK, "unprocessedEncryptionReferences");
             }
         }
         inputProcessorChain.doFinal();
@@ -158,7 +171,12 @@ public abstract class AbstractSignatureR
         protected AlgorithmType createMessageDigest(SecurityContext securityContext) throws XMLSecurityException, NoSuchAlgorithmException, NoSuchProviderException {
             AlgorithmType digestAlgorithm = JCEAlgorithmMapper.getAlgorithmMapping(getReferenceType().getDigestMethod().getAlgorithm());
 
-            MessageDigest messageDigest = MessageDigest.getInstance(digestAlgorithm.getJCEName(), digestAlgorithm.getJCEProvider());
+            MessageDigest messageDigest;
+            if (digestAlgorithm.getJCEProvider() != null) {
+                messageDigest = MessageDigest.getInstance(digestAlgorithm.getJCEName(), digestAlgorithm.getJCEProvider());
+            } else {
+                messageDigest = MessageDigest.getInstance(digestAlgorithm.getJCEName());
+            }
             this.setDigestOutputStream(new DigestOutputStream(messageDigest));
             this.setBufferedDigestOutputStream(new BufferedOutputStream(this.getDigestOutputStream()));
             return digestAlgorithm;
@@ -200,12 +218,12 @@ public abstract class AbstractSignatureR
             getTransformer().transform(xmlEvent);
 
             if (xmlEvent.isStartElement()) {
-                setElementCounter(getElementCounter() + 1);
+                this.elementCounter++;
             } else if (xmlEvent.isEndElement()) {
                 EndElement endElement = xmlEvent.asEndElement();
-                setElementCounter(getElementCounter() - 1);
+                this.elementCounter--;
 
-                if (endElement.getName().equals(getStartElement()) && getElementCounter() == 0) {
+                if (this.elementCounter == 0 && endElement.getName().equals(getStartElement())) {
                     try {
                         getBufferedDigestOutputStream().close();
                     } catch (IOException e) {
@@ -234,6 +252,10 @@ public abstract class AbstractSignatureR
             return finished;
         }
 
+        protected void setFinished(boolean finished) {
+            this.finished = finished;
+        }
+
         protected ReferenceType getReferenceType() {
             return referenceType;
         }
@@ -273,17 +295,5 @@ public abstract class AbstractSignatureR
         protected void setStartElement(QName startElement) {
             this.startElement = startElement;
         }
-
-        protected int getElementCounter() {
-            return elementCounter;
-        }
-
-        protected void setElementCounter(int elementCounter) {
-            this.elementCounter = elementCounter;
-        }
-
-        protected void setFinished(boolean finished) {
-            this.finished = finished;
-        }
     }
 }

Modified: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/processor/input/LogInputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/processor/input/LogInputProcessor.java?rev=1337945&r1=1337944&r2=1337945&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/processor/input/LogInputProcessor.java (original)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/processor/input/LogInputProcessor.java Sun May 13 17:27:10 2012
@@ -18,6 +18,8 @@
  */
 package org.swssf.xmlsec.impl.processor.input;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.swssf.xmlsec.ext.*;
 
 import javax.xml.stream.XMLStreamException;
@@ -30,6 +32,8 @@ import java.io.StringWriter;
  */
 public class LogInputProcessor extends AbstractInputProcessor {
 
+    private static final transient Log logger = LogFactory.getLog(LogInputProcessor.class);
+
     public LogInputProcessor(XMLSecurityProperties securityProperties) {
         super(securityProperties);
         setPhase(XMLSecurityConstants.Phase.POSTPROCESSING);

Modified: webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/processor/input/XMLEventReaderInputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/processor/input/XMLEventReaderInputProcessor.java?rev=1337945&r1=1337944&r2=1337945&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/processor/input/XMLEventReaderInputProcessor.java (original)
+++ webservices/wss4j/branches/swssf/streaming-xml-security/src/main/java/org/swssf/xmlsec/impl/processor/input/XMLEventReaderInputProcessor.java Sun May 13 17:27:10 2012
@@ -37,8 +37,8 @@ import java.util.List;
 public class XMLEventReaderInputProcessor extends AbstractInputProcessor {
 
     private XMLEventReader xmlEventReader;
-    private Deque<List<ComparableNamespace>> nsStack = new ArrayDeque<List<ComparableNamespace>>(10);
-    private Deque<List<ComparableAttribute>> attrStack = new ArrayDeque<List<ComparableAttribute>>(10);
+    private Deque<List<ComparableNamespace>> nsStack = new ArrayDeque<List<ComparableNamespace>>();
+    private Deque<List<ComparableAttribute>> attrStack = new ArrayDeque<List<ComparableAttribute>>();
 
     public XMLEventReaderInputProcessor(XMLSecurityProperties securityProperties, XMLEventReader xmlEventReader) {
         super(securityProperties);
@@ -57,10 +57,13 @@ public class XMLEventReaderInputProcesso
     }
 
     private XMLEvent processNextEventInternal(InputProcessorChain inputProcessorChain) throws XMLStreamException {
-        XMLEvent xmlEvent = XMLSecurityUtils.createXMLEventNS(xmlEventReader.nextEvent(), nsStack, attrStack);
+        XMLEvent xmlEvent = xmlEventReader.nextEvent();
         if (xmlEvent.isStartElement()) {
+            xmlEvent = XMLSecurityUtils.createXMLEventNS(xmlEvent, nsStack, attrStack);
             inputProcessorChain.getDocumentContext().addPathElement(xmlEvent.asStartElement().getName());
         } else if (xmlEvent.isEndElement()) {
+            nsStack.pop();
+            attrStack.pop();
             inputProcessorChain.getDocumentContext().removePathElement();
         }
         return xmlEvent;



Mime
View raw message