You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2019/02/14 10:33:50 UTC
svn commit: r1853571 - in /santuario/xml-security-java/trunk: etc/
src/main/java/org/apache/xml/security/encryption/
src/main/java/org/apache/xml/security/signature/
src/main/java/org/apache/xml/security/stax/config/
src/main/java/org/apache/xml/securi...
Author: coheigea
Date: Thu Feb 14 10:33:50 2019
New Revision: 1853571
URL: http://svn.apache.org/viewvc?rev=1853571&view=rev
Log:
Replace switch statement with if when it has a limited number of branches
Modified:
santuario/xml-security-java/trunk/etc/santuario-pmd-ruleset.xml
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/XMLCipher.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignatureInputDebugger.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/TransformerAlgorithmMapper.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/AbstractOutputProcessor.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractDecryptInputProcessor.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureInputHandler.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLEventReaderInputProcessor.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSecurityInputProcessor.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecAttributeImpl.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecNamespaceImpl.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformBase64Decode.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformEnvelopedSignature.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformIdentity.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformBase64Decode.java
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureTest.java
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/RetrievalMethodTest.java
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/AbstractPerformanceTest.java
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/utils/XMLSecEventAllocator.java
Modified: santuario/xml-security-java/trunk/etc/santuario-pmd-ruleset.xml
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/etc/santuario-pmd-ruleset.xml?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/etc/santuario-pmd-ruleset.xml (original)
+++ santuario/xml-security-java/trunk/etc/santuario-pmd-ruleset.xml Thu Feb 14 10:33:50 2019
@@ -61,6 +61,7 @@
</rule>
<rule ref="category/java/performance.xml">
+ <exclude name="AddEmptyString" />
<exclude name="AvoidInstantiatingObjectsInLoops" />
<exclude name="ConsecutiveAppendsShouldReuse" />
<exclude name="InefficientEmptyStringCheck" />
@@ -69,8 +70,6 @@
<!-- To fix -->
<exclude name="AvoidFileStream" />
- <exclude name="AddEmptyString" />
- <exclude name="TooFewBranchesForASwitchStatement" />
<exclude name="RedundantFieldInitializer" />
</rule>
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/XMLCipher.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/XMLCipher.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/XMLCipher.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/XMLCipher.java Thu Feb 14 10:33:50 2019
@@ -1864,14 +1864,12 @@ public class XMLCipher {
EncryptedData result = null;
CipherData data = null;
- switch (type) {
- case CipherData.REFERENCE_TYPE:
+ if (CipherData.REFERENCE_TYPE == type) {
CipherReference cipherReference = factory.newCipherReference(value);
data = factory.newCipherData(type);
data.setCipherReference(cipherReference);
result = factory.newEncryptedData(data);
- break;
- case CipherData.VALUE_TYPE:
+ } else if (CipherData.VALUE_TYPE == type) {
CipherValue cipherValue = factory.newCipherValue(value);
data = factory.newCipherData(type);
data.setCipherValue(cipherValue);
@@ -1919,14 +1917,12 @@ public class XMLCipher {
EncryptedKey result = null;
CipherData data = null;
- switch (type) {
- case CipherData.REFERENCE_TYPE:
+ if (CipherData.REFERENCE_TYPE == type) {
CipherReference cipherReference = factory.newCipherReference(value);
data = factory.newCipherData(type);
data.setCipherReference(cipherReference);
result = factory.newEncryptedKey(data);
- break;
- case CipherData.VALUE_TYPE:
+ } else if (CipherData.VALUE_TYPE == type) {
CipherValue cipherValue = factory.newCipherValue(value);
data = factory.newCipherData(type);
data.setCipherValue(cipherValue);
@@ -2482,8 +2478,7 @@ public class XMLCipher {
ReferenceList result = new ReferenceListImpl(type);
NodeList list = null;
- switch (type) {
- case ReferenceList.DATA_REFERENCE:
+ if (ReferenceList.DATA_REFERENCE == type) {
list =
element.getElementsByTagNameNS(
EncryptionConstants.EncryptionSpecNS,
@@ -2493,8 +2488,7 @@ public class XMLCipher {
String uri = ((Element) list.item(i)).getAttributeNS(null, "URI");
result.add(result.newDataReference(uri));
}
- break;
- case ReferenceList.KEY_REFERENCE:
+ } else if (ReferenceList.KEY_REFERENCE == type) {
list =
element.getElementsByTagNameNS(
EncryptionConstants.EncryptionSpecNS,
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignatureInputDebugger.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignatureInputDebugger.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignatureInputDebugger.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignatureInputDebugger.java Thu Feb 14 10:33:50 2019
@@ -512,15 +512,10 @@ public class XMLSignatureInputDebugger {
for (int i = 0; i < length; i++) {
char c = data.charAt(i);
- switch (c) {
-
- case 0x0D:
+ if (c == 0x0D) {
this.writer.write("&#xD;");
- break;
-
- default:
+ } else {
this.writer.write(c);
- break;
}
}
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/TransformerAlgorithmMapper.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/TransformerAlgorithmMapper.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/TransformerAlgorithmMapper.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/TransformerAlgorithmMapper.java Thu Feb 14 10:33:50 2019
@@ -68,13 +68,10 @@ public class TransformerAlgorithmMapper
public static Class<?> getTransformerClass(String algoURI, XMLSecurityConstants.DIRECTION direction) throws XMLSecurityException {
Class<?> clazz = null;
- switch (direction) {
- case IN:
- clazz = algorithmsClassMapIn.get(algoURI);
- break;
- case OUT:
- clazz = algorithmsClassMapOut.get(algoURI);
- break;
+ if (XMLSecurityConstants.DIRECTION.IN == direction) {
+ clazz = algorithmsClassMapIn.get(algoURI);
+ } else if (XMLSecurityConstants.DIRECTION.OUT == direction) {
+ clazz = algorithmsClassMapOut.get(algoURI);
}
if (clazz == null) {
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/AbstractOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/AbstractOutputProcessor.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/AbstractOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/AbstractOutputProcessor.java Thu Feb 14 10:33:50 2019
@@ -285,13 +285,10 @@ public abstract class AbstractOutputProc
createStartElementAndOutputAsEvent(outputProcessorChain, elementName, namespaces, attributes);
Node childNode = element.getFirstChild();
while (childNode != null) {
- switch (childNode.getNodeType()) {
- case Node.ELEMENT_NODE:
- outputDOMElement((Element) childNode, outputProcessorChain);
- break;
- case Node.TEXT_NODE:
- createCharactersAndOutputAsEvent(outputProcessorChain, ((Text) childNode).getData());
- break;
+ if (Node.ELEMENT_NODE == childNode.getNodeType()) {
+ outputDOMElement((Element) childNode, outputProcessorChain);
+ } else if (Node.TEXT_NODE == childNode.getNodeType()) {
+ createCharactersAndOutputAsEvent(outputProcessorChain, ((Text) childNode).getData());
}
childNode = childNode.getNextSibling();
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractDecryptInputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractDecryptInputProcessor.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractDecryptInputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractDecryptInputProcessor.java Thu Feb 14 10:33:50 2019
@@ -680,75 +680,72 @@ public abstract class AbstractDecryptInp
XMLSecEvent xmlSecEvent = XMLSecEventFactory.allocate(xmlStreamReader, parentXmlSecStartElement);
//here we request the next XMLEvent from the decryption thread
//instead from the processor-chain as we normally would do
- switch (xmlSecEvent.getEventType()) {
- case XMLStreamConstants.START_ELEMENT:
- currentXMLStructureDepth++;
- if (currentXMLStructureDepth > maximumAllowedXMLStructureDepth) {
- throw new XMLSecurityException(
- "secureProcessing.MaximumAllowedXMLStructureDepth",
- new Object[] {maximumAllowedXMLStructureDepth}
+ if (XMLStreamConstants.START_ELEMENT == xmlSecEvent.getEventType()) {
+ currentXMLStructureDepth++;
+ if (currentXMLStructureDepth > maximumAllowedXMLStructureDepth) {
+ throw new XMLSecurityException(
+ "secureProcessing.MaximumAllowedXMLStructureDepth",
+ new Object[] {maximumAllowedXMLStructureDepth}
);
- }
-
- parentXmlSecStartElement = xmlSecEvent.asStartElement();
- if (!rootElementProcessed) {
- handleEncryptedElement(inputProcessorChain, parentXmlSecStartElement, this.inboundSecurityToken, encryptedDataType);
- rootElementProcessed = true;
- }
- break;
- case XMLStreamConstants.END_ELEMENT:
- currentXMLStructureDepth--;
+ }
- if (parentXmlSecStartElement != null) {
- parentXmlSecStartElement = parentXmlSecStartElement.getParentXMLSecStartElement();
+ parentXmlSecStartElement = xmlSecEvent.asStartElement();
+ if (!rootElementProcessed) {
+ handleEncryptedElement(inputProcessorChain, parentXmlSecStartElement, this.inboundSecurityToken, encryptedDataType);
+ rootElementProcessed = true;
+ }
+ } else if (XMLStreamConstants.END_ELEMENT == xmlSecEvent.getEventType()) {
+ currentXMLStructureDepth--;
+
+ if (parentXmlSecStartElement != null) {
+ parentXmlSecStartElement = parentXmlSecStartElement.getParentXMLSecStartElement();
+ }
+
+ if (xmlSecEvent.asEndElement().getName().equals(wrapperElementName)) {
+ InputProcessorChain subInputProcessorChain = inputProcessorChain.createSubChain(this);
+
+ //skip EncryptedHeader Element when we processed it.
+ QName endElement;
+ if (encryptedHeader) {
+ endElement = XMLSecurityConstants.TAG_wsse11_EncryptedHeader;
+ } else {
+ endElement = XMLSecurityConstants.TAG_xenc_EncryptedData;
}
- if (xmlSecEvent.asEndElement().getName().equals(wrapperElementName)) {
- InputProcessorChain subInputProcessorChain = inputProcessorChain.createSubChain(this);
-
- //skip EncryptedHeader Element when we processed it.
- QName endElement;
- if (encryptedHeader) {
- endElement = XMLSecurityConstants.TAG_wsse11_EncryptedHeader;
+ //read and discard XMLEvents until the EncryptedData structure
+ XMLSecEvent endEvent;
+ do {
+ subInputProcessorChain.reset();
+ if (headerEvent) {
+ endEvent = subInputProcessorChain.processHeaderEvent();
} else {
- endElement = XMLSecurityConstants.TAG_xenc_EncryptedData;
- }
-
- //read and discard XMLEvents until the EncryptedData structure
- XMLSecEvent endEvent;
- do {
- subInputProcessorChain.reset();
- if (headerEvent) {
- endEvent = subInputProcessorChain.processHeaderEvent();
- } else {
- endEvent = subInputProcessorChain.processEvent();
- }
+ endEvent = subInputProcessorChain.processEvent();
}
- while (!(endEvent.getEventType() == XMLStreamConstants.END_ELEMENT
- && endEvent.asEndElement().getName().equals(endElement)));
+ }
+ while (!(endEvent.getEventType() == XMLStreamConstants.END_ELEMENT
+ && endEvent.asEndElement().getName().equals(endElement)));
- inputProcessorChain.getDocumentContext().unsetIsInEncryptedContent(this);
+ inputProcessorChain.getDocumentContext().unsetIsInEncryptedContent(this);
- //...fetch the next (unencrypted) event
- if (headerEvent) {
- xmlSecEvent = inputProcessorChain.processHeaderEvent();
- } else {
- xmlSecEvent = inputProcessorChain.processEvent();
- }
+ //...fetch the next (unencrypted) event
+ if (headerEvent) {
+ xmlSecEvent = inputProcessorChain.processHeaderEvent();
+ } else {
+ xmlSecEvent = inputProcessorChain.processEvent();
+ }
- if (decryptionThread != null) {
- //wait until the decryption thread dies...
- try {
- decryptionThread.join();
- } catch (InterruptedException e) {
- throw new XMLStreamException(e);
- }
- //...and test again for an exception in the decryption thread.
- testAndThrowUncaughtException();
+ if (decryptionThread != null) {
+ //wait until the decryption thread dies...
+ try {
+ decryptionThread.join();
+ } catch (InterruptedException e) {
+ throw new XMLStreamException(e);
}
- inputProcessorChain.removeProcessor(this);
+ //...and test again for an exception in the decryption thread.
+ testAndThrowUncaughtException();
}
- break;
+ inputProcessorChain.removeProcessor(this);
+ }
}
xmlStreamReader.next();
return xmlSecEvent;
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureInputHandler.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureInputHandler.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureInputHandler.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureInputHandler.java Thu Feb 14 10:33:50 2019
@@ -127,25 +127,19 @@ public abstract class AbstractSignatureI
loop:
while (iterator.hasNext()) {
XMLSecEvent xmlSecEvent = iterator.next();
- switch (xmlSecEvent.getEventType()) {
- case XMLStreamConstants.START_ELEMENT:
- if (xmlSecEvent.asStartElement().getName().equals(XMLSecurityConstants.TAG_dsig_SignedInfo)) {
- signatureVerifier.processEvent(xmlSecEvent);
- break loop;
- }
- break;
+ if (XMLStreamConstants.START_ELEMENT == xmlSecEvent.getEventType()
+ && xmlSecEvent.asStartElement().getName().equals(XMLSecurityConstants.TAG_dsig_SignedInfo)) {
+ signatureVerifier.processEvent(xmlSecEvent);
+ break loop;
}
}
loop:
while (iterator.hasNext()) {
XMLSecEvent xmlSecEvent = iterator.next();
signatureVerifier.processEvent(xmlSecEvent);
- switch (xmlSecEvent.getEventType()) {
- case XMLStreamConstants.END_ELEMENT:
- if (xmlSecEvent.asEndElement().getName().equals(XMLSecurityConstants.TAG_dsig_SignedInfo)) {
- break loop;
- }
- break;
+ if (XMLStreamConstants.END_ELEMENT == xmlSecEvent.getEventType()
+ && xmlSecEvent.asEndElement().getName().equals(XMLSecurityConstants.TAG_dsig_SignedInfo)) {
+ break loop;
}
}
} catch (XMLStreamException e) {
@@ -180,13 +174,10 @@ public abstract class AbstractSignatureI
loop:
while (iterator.hasNext()) {
XMLSecEvent xmlSecEvent = iterator.next();
- switch (xmlSecEvent.getEventType()) {
- case XMLStreamConstants.START_ELEMENT:
- if (xmlSecEvent.asStartElement().getName().equals(XMLSecurityConstants.TAG_dsig_SignedInfo)) {
- transformer.transform(xmlSecEvent);
- break loop;
- }
- break;
+ if (XMLStreamConstants.START_ELEMENT == xmlSecEvent.getEventType()
+ && xmlSecEvent.asStartElement().getName().equals(XMLSecurityConstants.TAG_dsig_SignedInfo)) {
+ transformer.transform(xmlSecEvent);
+ break loop;
}
}
@@ -194,12 +185,9 @@ public abstract class AbstractSignatureI
while (iterator.hasNext()) {
XMLSecEvent xmlSecEvent = iterator.next();
transformer.transform(xmlSecEvent);
- switch (xmlSecEvent.getEventType()) {
- case XMLStreamConstants.END_ELEMENT:
- if (xmlSecEvent.asEndElement().getName().equals(XMLSecurityConstants.TAG_dsig_SignedInfo)) {
- break loop;
- }
- break;
+ if (XMLStreamConstants.END_ELEMENT == xmlSecEvent.getEventType()
+ && xmlSecEvent.asEndElement().getName().equals(XMLSecurityConstants.TAG_dsig_SignedInfo)) {
+ break loop;
}
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java Thu Feb 14 10:33:50 2019
@@ -162,35 +162,33 @@ public abstract class AbstractSignatureR
throws XMLStreamException, XMLSecurityException {
XMLSecEvent xmlSecEvent = inputProcessorChain.processEvent();
- switch (xmlSecEvent.getEventType()) {
- case XMLStreamConstants.START_ELEMENT:
- XMLSecStartElement xmlSecStartElement = xmlSecEvent.asStartElement();
- List<ReferenceType> referenceTypes = resolvesResource(xmlSecStartElement);
- if (!referenceTypes.isEmpty()) {
- for (int i = 0; i < referenceTypes.size(); i++) {
- ReferenceType referenceType = referenceTypes.get(i);
-
- if (processedReferences.contains(referenceType)) {
- throw new XMLSecurityException("signature.Verification.MultipleIDs",
- new Object[] {referenceType.getURI()});
- }
- InternalSignatureReferenceVerifier internalSignatureReferenceVerifier =
- getSignatureReferenceVerifier(getSecurityProperties(), inputProcessorChain,
- referenceType, xmlSecStartElement);
- if (!internalSignatureReferenceVerifier.isFinished()) {
- internalSignatureReferenceVerifier.processEvent(xmlSecEvent, inputProcessorChain);
- inputProcessorChain.addProcessor(internalSignatureReferenceVerifier);
- }
- processedReferences.add(referenceType);
- inputProcessorChain.getDocumentContext().setIsInSignedContent(
- inputProcessorChain.getProcessors().indexOf(internalSignatureReferenceVerifier),
- internalSignatureReferenceVerifier);
-
- processElementPath(internalSignatureReferenceVerifier.getStartElementPath(), inputProcessorChain,
- internalSignatureReferenceVerifier.getStartElement(), referenceType);
+ if (XMLStreamConstants.START_ELEMENT == xmlSecEvent.getEventType()) {
+ XMLSecStartElement xmlSecStartElement = xmlSecEvent.asStartElement();
+ List<ReferenceType> referenceTypes = resolvesResource(xmlSecStartElement);
+ if (!referenceTypes.isEmpty()) {
+ for (int i = 0; i < referenceTypes.size(); i++) {
+ ReferenceType referenceType = referenceTypes.get(i);
+
+ if (processedReferences.contains(referenceType)) {
+ throw new XMLSecurityException("signature.Verification.MultipleIDs",
+ new Object[] {referenceType.getURI()});
+ }
+ InternalSignatureReferenceVerifier internalSignatureReferenceVerifier =
+ getSignatureReferenceVerifier(getSecurityProperties(), inputProcessorChain,
+ referenceType, xmlSecStartElement);
+ if (!internalSignatureReferenceVerifier.isFinished()) {
+ internalSignatureReferenceVerifier.processEvent(xmlSecEvent, inputProcessorChain);
+ inputProcessorChain.addProcessor(internalSignatureReferenceVerifier);
}
+ processedReferences.add(referenceType);
+ inputProcessorChain.getDocumentContext().setIsInSignedContent(
+ inputProcessorChain.getProcessors().indexOf(internalSignatureReferenceVerifier),
+ internalSignatureReferenceVerifier);
+
+ processElementPath(internalSignatureReferenceVerifier.getStartElementPath(), inputProcessorChain,
+ internalSignatureReferenceVerifier.getStartElement(), referenceType);
}
- break;
+ }
}
return xmlSecEvent;
}
@@ -454,32 +452,29 @@ public abstract class AbstractSignatureR
}
public void processEvent(XMLSecEvent xmlSecEvent, InputProcessorChain inputProcessorChain)
- throws XMLStreamException, XMLSecurityException {
+ throws XMLStreamException, XMLSecurityException {
getTransformer().transform(xmlSecEvent);
- switch (xmlSecEvent.getEventType()) {
- case XMLStreamConstants.START_ELEMENT:
- this.elementCounter++;
- break;
- case XMLStreamConstants.END_ELEMENT:
- XMLSecEndElement xmlSecEndElement = xmlSecEvent.asEndElement();
- this.elementCounter--;
-
- if (this.elementCounter == 0 && xmlSecEndElement.getName().equals(startElement.getName())) {
- getTransformer().doFinal();
- try {
- getBufferedDigestOutputStream().close();
- } catch (IOException e) {
- throw new XMLSecurityException(e);
- }
-
- compareDigest(this.getDigestOutputStream().getDigestValue(), getReferenceType());
-
- inputProcessorChain.removeProcessor(this);
- inputProcessorChain.getDocumentContext().unsetIsInSignedContent(this);
- setFinished(true);
+ if (XMLStreamConstants.START_ELEMENT == xmlSecEvent.getEventType()) {
+ this.elementCounter++;
+ } else if (XMLStreamConstants.END_ELEMENT == xmlSecEvent.getEventType()) {
+ XMLSecEndElement xmlSecEndElement = xmlSecEvent.asEndElement();
+ this.elementCounter--;
+
+ if (this.elementCounter == 0 && xmlSecEndElement.getName().equals(startElement.getName())) {
+ getTransformer().doFinal();
+ try {
+ getBufferedDigestOutputStream().close();
+ } catch (IOException e) {
+ throw new XMLSecurityException(e);
}
- break;
+
+ compareDigest(this.getDigestOutputStream().getDigestValue(), getReferenceType());
+
+ inputProcessorChain.removeProcessor(this);
+ inputProcessorChain.getDocumentContext().unsetIsInSignedContent(this);
+ setFinished(true);
+ }
}
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLEventReaderInputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLEventReaderInputProcessor.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLEventReaderInputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLEventReaderInputProcessor.java Thu Feb 14 10:33:50 2019
@@ -68,26 +68,23 @@ public class XMLEventReaderInputProcesso
private XMLSecEvent processNextEventInternal() throws XMLStreamException {
XMLSecEvent xmlSecEvent = XMLSecEventFactory.allocate(xmlStreamReader, parentXmlSecStartElement);
- switch (xmlSecEvent.getEventType()) {
- case XMLStreamConstants.START_ELEMENT:
- currentXMLStructureDepth++;
- if (currentXMLStructureDepth > maximumAllowedXMLStructureDepth) {
- XMLSecurityException xmlSecurityException = new XMLSecurityException(
- "secureProcessing.MaximumAllowedXMLStructureDepth",
- new Object[] {maximumAllowedXMLStructureDepth}
+ if (XMLStreamConstants.START_ELEMENT == xmlSecEvent.getEventType()) {
+ currentXMLStructureDepth++;
+ if (currentXMLStructureDepth > maximumAllowedXMLStructureDepth) {
+ XMLSecurityException xmlSecurityException = new XMLSecurityException(
+ "secureProcessing.MaximumAllowedXMLStructureDepth",
+ new Object[] {maximumAllowedXMLStructureDepth}
);
- throw new XMLStreamException(xmlSecurityException);
- }
+ throw new XMLStreamException(xmlSecurityException);
+ }
- parentXmlSecStartElement = (XMLSecStartElement) xmlSecEvent;
- break;
- case XMLStreamConstants.END_ELEMENT:
- currentXMLStructureDepth--;
+ parentXmlSecStartElement = (XMLSecStartElement) xmlSecEvent;
+ } else if (XMLStreamConstants.END_ELEMENT == xmlSecEvent.getEventType()) {
+ currentXMLStructureDepth--;
- if (parentXmlSecStartElement != null) {
- parentXmlSecStartElement = parentXmlSecStartElement.getParentXMLSecStartElement();
- }
- break;
+ if (parentXmlSecStartElement != null) {
+ parentXmlSecStartElement = parentXmlSecStartElement.getParentXMLSecStartElement();
+ }
}
if (xmlStreamReader.hasNext()) {
xmlStreamReader.next();
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSecurityInputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSecurityInputProcessor.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSecurityInputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/XMLSecurityInputProcessor.java Thu Feb 14 10:33:50 2019
@@ -74,98 +74,95 @@ public class XMLSecurityInputProcessor e
}
XMLSecEvent xmlSecEvent = inputProcessorChain.processEvent();
- switch (xmlSecEvent.getEventType()) {
- case XMLStreamConstants.START_ELEMENT:
- final XMLSecStartElement xmlSecStartElement = xmlSecEvent.asStartElement();
-
- if (!decryptOnly && xmlSecStartElement.getName().equals(XMLSecurityConstants.TAG_dsig_Signature)) {
- if (signatureElementFound) {
- throw new XMLSecurityException("stax.multipleSignaturesNotSupported");
- }
- signatureElementFound = true;
- startIndexForProcessor = internalBufferProcessor.getXmlSecEventList().size() - 1;
- } else if (xmlSecStartElement.getName().equals(XMLSecurityConstants.TAG_xenc_EncryptedData)) {
- encryptedDataElementFound = true;
-
- XMLDecryptInputProcessor decryptInputProcessor = new XMLDecryptInputProcessor(getSecurityProperties());
- decryptInputProcessor.setPhase(XMLSecurityConstants.Phase.PREPROCESSING);
- decryptInputProcessor.addAfterProcessor(XMLEventReaderInputProcessor.class.getName());
- decryptInputProcessor.addBeforeProcessor(XMLSecurityInputProcessor.class.getName());
- decryptInputProcessor.addBeforeProcessor(XMLSecurityInputProcessor.InternalBufferProcessor.class.getName());
- inputProcessorChain.addProcessor(decryptInputProcessor);
-
- if (!decryptOnly) {
- final ArrayDeque<XMLSecEvent> xmlSecEventList = internalBufferProcessor.getXmlSecEventList();
- //remove the last event (EncryptedData)
- xmlSecEventList.pollFirst();
- }
+ if (XMLStreamConstants.START_ELEMENT == xmlSecEvent.getEventType()) {
+ final XMLSecStartElement xmlSecStartElement = xmlSecEvent.asStartElement();
- // temporary processor to return the EncryptedData element for the DecryptionProcessor
- AbstractInputProcessor abstractInputProcessor = new AbstractInputProcessor(getSecurityProperties()) {
- @Override
- public XMLSecEvent processNextHeaderEvent(InputProcessorChain inputProcessorChain)
- throws XMLStreamException, XMLSecurityException {
- return processNextEvent(inputProcessorChain);
- }
-
- @Override
- public XMLSecEvent processNextEvent(InputProcessorChain inputProcessorChain)
- throws XMLStreamException, XMLSecurityException {
- inputProcessorChain.removeProcessor(this);
- return xmlSecStartElement;
- }
- };
- abstractInputProcessor.setPhase(XMLSecurityConstants.Phase.PREPROCESSING);
- abstractInputProcessor.addBeforeProcessor(decryptInputProcessor);
- inputProcessorChain.addProcessor(abstractInputProcessor);
-
- //fetch the next event from the original chain
- inputProcessorChain.reset();
- xmlSecEvent = inputProcessorChain.processEvent();
-
- // no need to catch a possible signature element here because the decrypt processor
- // is installed before this processor and therefore the decrypted signature element will
- // flow as normal through this processor.
- // for safety we do a check if this really true
- //check if the decrypted element is a Signature element
- if (!decryptOnly && xmlSecEvent.isStartElement() &&
- xmlSecEvent.asStartElement().getName().equals(XMLSecurityConstants.TAG_dsig_Signature) &&
- !signatureElementFound) {
- throw new XMLSecurityException("Internal error");
- }
+ if (!decryptOnly && xmlSecStartElement.getName().equals(XMLSecurityConstants.TAG_dsig_Signature)) {
+ if (signatureElementFound) {
+ throw new XMLSecurityException("stax.multipleSignaturesNotSupported");
}
- break;
- case XMLStreamConstants.END_ELEMENT:
- XMLSecEndElement xmlSecEndElement = xmlSecEvent.asEndElement();
- // Handle the signature
- if (signatureElementFound
- && xmlSecEndElement.getName().equals(XMLSecurityConstants.TAG_dsig_Signature)) {
- XMLSignatureInputHandler inputHandler = new XMLSignatureInputHandler();
+ signatureElementFound = true;
+ startIndexForProcessor = internalBufferProcessor.getXmlSecEventList().size() - 1;
+ } else if (xmlSecStartElement.getName().equals(XMLSecurityConstants.TAG_xenc_EncryptedData)) {
+ encryptedDataElementFound = true;
+
+ XMLDecryptInputProcessor decryptInputProcessor = new XMLDecryptInputProcessor(getSecurityProperties());
+ decryptInputProcessor.setPhase(XMLSecurityConstants.Phase.PREPROCESSING);
+ decryptInputProcessor.addAfterProcessor(XMLEventReaderInputProcessor.class.getName());
+ decryptInputProcessor.addBeforeProcessor(XMLSecurityInputProcessor.class.getName());
+ decryptInputProcessor.addBeforeProcessor(XMLSecurityInputProcessor.InternalBufferProcessor.class.getName());
+ inputProcessorChain.addProcessor(decryptInputProcessor);
+ if (!decryptOnly) {
final ArrayDeque<XMLSecEvent> xmlSecEventList = internalBufferProcessor.getXmlSecEventList();
- inputHandler.handle(inputProcessorChain, getSecurityProperties(),
- xmlSecEventList, startIndexForProcessor);
-
- inputProcessorChain.removeProcessor(internalBufferProcessor);
+ //remove the last event (EncryptedData)
+ xmlSecEventList.pollFirst();
+ }
- //add the replay processor to the chain...
- InternalReplayProcessor internalReplayProcessor =
- new InternalReplayProcessor(getSecurityProperties(), xmlSecEventList);
- internalReplayProcessor.addBeforeProcessor(XMLSignatureReferenceVerifyInputProcessor.class.getName());
- inputProcessorChain.addProcessor(internalReplayProcessor);
-
- //...and let the SignatureVerificationProcessor process the buffered events (enveloped signature).
- InputProcessorChain subInputProcessorChain = inputProcessorChain.createSubChain(this, false);
- while (!xmlSecEventList.isEmpty()) {
- subInputProcessorChain.reset();
- subInputProcessorChain.processEvent();
+ // temporary processor to return the EncryptedData element for the DecryptionProcessor
+ AbstractInputProcessor abstractInputProcessor = new AbstractInputProcessor(getSecurityProperties()) {
+ @Override
+ public XMLSecEvent processNextHeaderEvent(InputProcessorChain inputProcessorChain)
+ throws XMLStreamException, XMLSecurityException {
+ return processNextEvent(inputProcessorChain);
}
- // copy all processor back to main chain for finalization
- inputProcessorChain.getProcessors().clear();
- inputProcessorChain.getProcessors().addAll(subInputProcessorChain.getProcessors());
+ @Override
+ public XMLSecEvent processNextEvent(InputProcessorChain inputProcessorChain)
+ throws XMLStreamException, XMLSecurityException {
+ inputProcessorChain.removeProcessor(this);
+ return xmlSecStartElement;
+ }
+ };
+ abstractInputProcessor.setPhase(XMLSecurityConstants.Phase.PREPROCESSING);
+ abstractInputProcessor.addBeforeProcessor(decryptInputProcessor);
+ inputProcessorChain.addProcessor(abstractInputProcessor);
+
+ //fetch the next event from the original chain
+ inputProcessorChain.reset();
+ xmlSecEvent = inputProcessorChain.processEvent();
+
+ // no need to catch a possible signature element here because the decrypt processor
+ // is installed before this processor and therefore the decrypted signature element will
+ // flow as normal through this processor.
+ // for safety we do a check if this really true
+ //check if the decrypted element is a Signature element
+ if (!decryptOnly && xmlSecEvent.isStartElement() &&
+ xmlSecEvent.asStartElement().getName().equals(XMLSecurityConstants.TAG_dsig_Signature) &&
+ !signatureElementFound) {
+ throw new XMLSecurityException("Internal error");
}
- break;
+ }
+ } else if (XMLStreamConstants.END_ELEMENT == xmlSecEvent.getEventType()) {
+ XMLSecEndElement xmlSecEndElement = xmlSecEvent.asEndElement();
+ // Handle the signature
+ if (signatureElementFound
+ && xmlSecEndElement.getName().equals(XMLSecurityConstants.TAG_dsig_Signature)) {
+ XMLSignatureInputHandler inputHandler = new XMLSignatureInputHandler();
+
+ final ArrayDeque<XMLSecEvent> xmlSecEventList = internalBufferProcessor.getXmlSecEventList();
+ inputHandler.handle(inputProcessorChain, getSecurityProperties(),
+ xmlSecEventList, startIndexForProcessor);
+
+ inputProcessorChain.removeProcessor(internalBufferProcessor);
+
+ //add the replay processor to the chain...
+ InternalReplayProcessor internalReplayProcessor =
+ new InternalReplayProcessor(getSecurityProperties(), xmlSecEventList);
+ internalReplayProcessor.addBeforeProcessor(XMLSignatureReferenceVerifyInputProcessor.class.getName());
+ inputProcessorChain.addProcessor(internalReplayProcessor);
+
+ //...and let the SignatureVerificationProcessor process the buffered events (enveloped signature).
+ InputProcessorChain subInputProcessorChain = inputProcessorChain.createSubChain(this, false);
+ while (!xmlSecEventList.isEmpty()) {
+ subInputProcessorChain.reset();
+ subInputProcessorChain.processEvent();
+ }
+
+ // copy all processor back to main chain for finalization
+ inputProcessorChain.getProcessors().clear();
+ inputProcessorChain.getProcessors().addAll(subInputProcessorChain.getProcessors());
+ }
}
return xmlSecEvent;
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java Thu Feb 14 10:33:50 2019
@@ -224,18 +224,16 @@ public abstract class AbstractEncryptOut
if (this.elementCounter == 0 && xmlSecStartElement.getName().equals(this.getXmlSecStartElement().getName())) {
//if the user selected element encryption we have to encrypt the current element-event...
- switch (getEncryptionPartDef().getModifier()) {
- case Element:
- OutputProcessorChain subOutputProcessorChain = outputProcessorChain.createSubChain(this);
- processEventInternal(xmlSecStartElement, subOutputProcessorChain);
- //encrypt the current element event
- encryptEvent(xmlSecEvent);
- break;
- case Content:
- outputProcessorChain.processEvent(xmlSecEvent);
- subOutputProcessorChain = outputProcessorChain.createSubChain(this);
- processEventInternal(xmlSecStartElement, subOutputProcessorChain);
- break;
+ if (SecurePart.Modifier.Element == getEncryptionPartDef().getModifier()) {
+ OutputProcessorChain subOutputProcessorChain = outputProcessorChain.createSubChain(this);
+ processEventInternal(xmlSecStartElement, subOutputProcessorChain);
+ //encrypt the current element event
+ encryptEvent(xmlSecEvent);
+ } else if (SecurePart.Modifier.Content == getEncryptionPartDef().getModifier()) {
+ OutputProcessorChain subOutputProcessorChain = outputProcessorChain.createSubChain(this);
+ outputProcessorChain.processEvent(xmlSecEvent);
+ subOutputProcessorChain = outputProcessorChain.createSubChain(this);
+ processEventInternal(xmlSecStartElement, subOutputProcessorChain);
}
} else {
encryptEvent(xmlSecEvent);
@@ -248,15 +246,12 @@ public abstract class AbstractEncryptOut
if (this.elementCounter == 0 && xmlSecEvent.asEndElement().getName().equals(this.getXmlSecStartElement().getName())) {
OutputProcessorChain subOutputProcessorChain = outputProcessorChain.createSubChain(this);
- switch (getEncryptionPartDef().getModifier()) {
- case Element:
- encryptEvent(xmlSecEvent);
- doFinalInternal(subOutputProcessorChain);
- break;
- case Content:
- doFinalInternal(subOutputProcessorChain);
- outputAsEvent(subOutputProcessorChain, xmlSecEvent);
- break;
+ if (SecurePart.Modifier.Element == getEncryptionPartDef().getModifier()) {
+ encryptEvent(xmlSecEvent);
+ doFinalInternal(subOutputProcessorChain);
+ } else if (SecurePart.Modifier.Content == getEncryptionPartDef().getModifier()) {
+ doFinalInternal(subOutputProcessorChain);
+ outputAsEvent(subOutputProcessorChain, xmlSecEvent);
}
subOutputProcessorChain.removeProcessor(this);
//from now on encryption is possible again
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java Thu Feb 14 10:33:50 2019
@@ -287,32 +287,29 @@ public abstract class AbstractSignatureO
transformer.transform(xmlSecEvent);
- switch (xmlSecEvent.getEventType()) {
- case XMLStreamConstants.START_ELEMENT:
- elementCounter++;
- break;
- case XMLStreamConstants.END_ELEMENT:
- elementCounter--;
+ if (XMLStreamConstants.START_ELEMENT == xmlSecEvent.getEventType()) {
+ elementCounter++;
+ } else if (XMLStreamConstants.END_ELEMENT == xmlSecEvent.getEventType()) {
+ elementCounter--;
- if (elementCounter == 0 &&
- xmlSecEvent.asEndElement().getName().equals(this.xmlSecStartElement.getName())) {
+ if (elementCounter == 0 &&
+ xmlSecEvent.asEndElement().getName().equals(this.xmlSecStartElement.getName())) {
- transformer.doFinal();
- try {
- bufferedDigestOutputStream.close();
- } catch (IOException e) {
- throw new XMLSecurityException(e);
- }
- String calculatedDigest =
- XMLUtils.encodeToString(this.digestOutputStream.getDigestValue());
- LOG.debug("Calculated Digest: {}", calculatedDigest);
- signaturePartDef.setDigestValue(calculatedDigest);
-
- outputProcessorChain.removeProcessor(this);
- //from now on signature is possible again
- setActiveInternalSignatureOutputProcessor(null);
+ transformer.doFinal();
+ try {
+ bufferedDigestOutputStream.close();
+ } catch (IOException e) {
+ throw new XMLSecurityException(e);
}
- break;
+ String calculatedDigest =
+ XMLUtils.encodeToString(this.digestOutputStream.getDigestValue());
+ LOG.debug("Calculated Digest: {}", calculatedDigest);
+ signaturePartDef.setDigestValue(calculatedDigest);
+
+ outputProcessorChain.removeProcessor(this);
+ //from now on signature is possible again
+ setActiveInternalSignatureOutputProcessor(null);
+ }
}
outputProcessorChain.processEvent(xmlSecEvent);
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecAttributeImpl.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecAttributeImpl.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecAttributeImpl.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecAttributeImpl.java Thu Feb 14 10:33:50 2019
@@ -134,17 +134,14 @@ public class XMLSecAttributeImpl extends
int idx = 0;
while (i < length) {
char c = text.charAt(i);
- switch (c) {
- case '&':
- writer.write(text, idx, i - idx);
- writer.write("&");
- idx = i + 1;
- break;
- case '"':
- writer.write(text, idx, i - idx);
- writer.write(""");
- idx = i + 1;
- break;
+ if (c == '&') {
+ writer.write(text, idx, i - idx);
+ writer.write("&");
+ idx = i + 1;
+ } else if (c == '"') {
+ writer.write(text, idx, i - idx);
+ writer.write(""");
+ idx = i + 1;
}
i++;
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecNamespaceImpl.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecNamespaceImpl.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecNamespaceImpl.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecNamespaceImpl.java Thu Feb 14 10:33:50 2019
@@ -174,17 +174,14 @@ public class XMLSecNamespaceImpl extends
int idx = 0;
while (i < length) {
char c = text.charAt(i);
- switch (c) {
- case '&':
- writer.write(text, idx, i - idx);
- writer.write("&");
- idx = i + 1;
- break;
- case '"':
- writer.write(text, idx, i - idx);
- writer.write(""");
- idx = i + 1;
- break;
+ if (c == '&') {
+ writer.write(text, idx, i - idx);
+ writer.write("&");
+ idx = i + 1;
+ } else if (c == '"') {
+ writer.write(text, idx, i - idx);
+ writer.write(""");
+ idx = i + 1;
}
i++;
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformBase64Decode.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformBase64Decode.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformBase64Decode.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformBase64Decode.java Thu Feb 14 10:33:50 2019
@@ -66,110 +66,103 @@ public class TransformBase64Decode exten
@Override
public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
int eventType = xmlSecEvent.getEventType();
- switch (eventType) {
- case XMLStreamConstants.CHARACTERS:
- if (getOutputStream() != null) {
- //we have an output stream
- //encoding shouldn't matter here, because the data is Base64 encoded and is therefore in the ASCII range.
- try {
- getOutputStream().write(xmlSecEvent.asCharacters().getData().getBytes());
- } catch (IOException e) {
- throw new XMLStreamException(e);
- }
- } else {
- //we have a child transformer
- if (childOutputMethod == null) {
-
- final XMLSecurityConstants.TransformMethod preferredChildTransformMethod =
- getTransformer().getPreferredTransformMethod(XMLSecurityConstants.TransformMethod.XMLSecEvent);
-
- switch (preferredChildTransformMethod) {
- case XMLSecEvent: {
- childOutputMethod = new ChildOutputMethod() {
-
- private UnsyncByteArrayOutputStream byteArrayOutputStream;
- private Base64OutputStream base64OutputStream;
-
- @Override
- public void transform(Object object) throws XMLStreamException {
- if (base64OutputStream == null) {
- byteArrayOutputStream = new UnsyncByteArrayOutputStream();
- base64OutputStream = new Base64OutputStream(byteArrayOutputStream, false);
- }
- try {
- base64OutputStream.write((byte[]) object);
- } catch (IOException e) {
- throw new XMLStreamException(e);
- }
- }
-
- @Override
- public void doFinal() throws XMLStreamException {
- try {
- base64OutputStream.close();
- } catch (IOException e) {
- throw new XMLStreamException(e);
- }
-
- try (InputStream is = new UnsyncByteArrayInputStream(byteArrayOutputStream.toByteArray())) {
- XMLEventReaderInputProcessor xmlEventReaderInputProcessor
- = new XMLEventReaderInputProcessor(null,
- getXmlInputFactory().createXMLStreamReader(is)
- );
- XMLSecEvent xmlSecEvent;
- do {
- xmlSecEvent = xmlEventReaderInputProcessor.processNextEvent(null);
- getTransformer().transform(xmlSecEvent);
- } while (xmlSecEvent.getEventType() != XMLStreamConstants.END_DOCUMENT);
- } catch (XMLSecurityException | IOException e) {
- throw new XMLStreamException(e);
- }
- getTransformer().doFinal();
- }
- };
- break;
+ if (XMLStreamConstants.CHARACTERS == eventType) {
+ if (getOutputStream() != null) {
+ //we have an output stream
+ //encoding shouldn't matter here, because the data is Base64 encoded and is therefore in the ASCII range.
+ try {
+ getOutputStream().write(xmlSecEvent.asCharacters().getData().getBytes());
+ } catch (IOException e) {
+ throw new XMLStreamException(e);
+ }
+ } else {
+ //we have a child transformer
+ if (childOutputMethod == null) {
+
+ final XMLSecurityConstants.TransformMethod preferredChildTransformMethod =
+ getTransformer().getPreferredTransformMethod(XMLSecurityConstants.TransformMethod.XMLSecEvent);
+
+ if (preferredChildTransformMethod == XMLSecurityConstants.TransformMethod.XMLSecEvent) {
+ childOutputMethod = new ChildOutputMethod() {
+
+ private UnsyncByteArrayOutputStream byteArrayOutputStream;
+ private Base64OutputStream base64OutputStream;
+
+ @Override
+ public void transform(Object object) throws XMLStreamException {
+ if (base64OutputStream == null) {
+ byteArrayOutputStream = new UnsyncByteArrayOutputStream();
+ base64OutputStream = new Base64OutputStream(byteArrayOutputStream, false);
+ }
+ try {
+ base64OutputStream.write((byte[]) object);
+ } catch (IOException e) {
+ throw new XMLStreamException(e);
+ }
}
- case InputStream: {
- childOutputMethod = new ChildOutputMethod() {
- private UnsyncByteArrayOutputStream byteArrayOutputStream;
- private Base64OutputStream base64OutputStream;
+ @Override
+ public void doFinal() throws XMLStreamException {
+ try {
+ base64OutputStream.close();
+ } catch (IOException e) {
+ throw new XMLStreamException(e);
+ }
+
+ try (InputStream is = new UnsyncByteArrayInputStream(byteArrayOutputStream.toByteArray())) {
+ XMLEventReaderInputProcessor xmlEventReaderInputProcessor
+ = new XMLEventReaderInputProcessor(null,
+ getXmlInputFactory().createXMLStreamReader(is)
+ );
+ XMLSecEvent xmlSecEvent;
+ do {
+ xmlSecEvent = xmlEventReaderInputProcessor.processNextEvent(null);
+ getTransformer().transform(xmlSecEvent);
+ } while (xmlSecEvent.getEventType() != XMLStreamConstants.END_DOCUMENT);
+ } catch (XMLSecurityException | IOException e) {
+ throw new XMLStreamException(e);
+ }
+ getTransformer().doFinal();
+ }
+ };
+ } else if (preferredChildTransformMethod == XMLSecurityConstants.TransformMethod.InputStream) {
+ childOutputMethod = new ChildOutputMethod() {
+
+ private UnsyncByteArrayOutputStream byteArrayOutputStream;
+ private Base64OutputStream base64OutputStream;
+
+ @Override
+ public void transform(Object object) throws XMLStreamException {
+ if (base64OutputStream == null) {
+ byteArrayOutputStream = new UnsyncByteArrayOutputStream();
+ base64OutputStream = new Base64OutputStream(byteArrayOutputStream, false);
+ }
+ try {
+ base64OutputStream.write((byte[]) object);
+ } catch (IOException e) {
+ throw new XMLStreamException(e);
+ }
+ }
- @Override
- public void transform(Object object) throws XMLStreamException {
- if (base64OutputStream == null) {
- byteArrayOutputStream = new UnsyncByteArrayOutputStream();
- base64OutputStream = new Base64OutputStream(byteArrayOutputStream, false);
- }
- try {
- base64OutputStream.write((byte[]) object);
- } catch (IOException e) {
- throw new XMLStreamException(e);
- }
- }
-
- @Override
- public void doFinal() throws XMLStreamException {
- try {
- base64OutputStream.close();
- } catch (IOException e) {
- throw new XMLStreamException(e);
- }
- try (InputStream is = new UnsyncByteArrayInputStream(byteArrayOutputStream.toByteArray())) {
- getTransformer().transform(is);
- getTransformer().doFinal();
- } catch (IOException ex) {
- throw new XMLStreamException(ex);
- }
- }
- };
- break;
+ @Override
+ public void doFinal() throws XMLStreamException {
+ try {
+ base64OutputStream.close();
+ } catch (IOException e) {
+ throw new XMLStreamException(e);
+ }
+ try (InputStream is = new UnsyncByteArrayInputStream(byteArrayOutputStream.toByteArray())) {
+ getTransformer().transform(is);
+ getTransformer().doFinal();
+ } catch (IOException ex) {
+ throw new XMLStreamException(ex);
+ }
}
- }
+ };
}
childOutputMethod.transform(xmlSecEvent.asCharacters().getData().getBytes());
}
- break;
+ }
}
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformEnvelopedSignature.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformEnvelopedSignature.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformEnvelopedSignature.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformEnvelopedSignature.java Thu Feb 14 10:33:50 2019
@@ -48,22 +48,20 @@ public class TransformEnvelopedSignature
@Override
public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
- switch (xmlSecEvent.getEventType()) {
- case XMLStreamConstants.START_ELEMENT:
- curLevel++;
- XMLSecStartElement xmlSecStartElement = xmlSecEvent.asStartElement();
- if (XMLSecurityConstants.TAG_dsig_Signature.equals(xmlSecStartElement.getName())) {
- sigElementLevel = curLevel;
- return;
- }
- break;
- case XMLStreamConstants.END_ELEMENT:
- XMLSecEndElement xmlSecEndElement = xmlSecEvent.asEndElement();
- if (sigElementLevel == curLevel && XMLSecurityConstants.TAG_dsig_Signature.equals(xmlSecEndElement.getName())) {
- sigElementLevel = -1;
- return;
- }
- curLevel--;
+ if (XMLStreamConstants.START_ELEMENT == xmlSecEvent.getEventType()) {
+ curLevel++;
+ XMLSecStartElement xmlSecStartElement = xmlSecEvent.asStartElement();
+ if (XMLSecurityConstants.TAG_dsig_Signature.equals(xmlSecStartElement.getName())) {
+ sigElementLevel = curLevel;
+ return;
+ }
+ } else if (XMLStreamConstants.END_ELEMENT == xmlSecEvent.getEventType()) {
+ XMLSecEndElement xmlSecEndElement = xmlSecEvent.asEndElement();
+ if (sigElementLevel == curLevel && XMLSecurityConstants.TAG_dsig_Signature.equals(xmlSecEndElement.getName())) {
+ sigElementLevel = -1;
+ return;
+ }
+ curLevel--;
}
if (sigElementLevel == -1) {
super.transform(xmlSecEvent);
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformIdentity.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformIdentity.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformIdentity.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformIdentity.java Thu Feb 14 10:33:50 2019
@@ -123,51 +123,46 @@ public class TransformIdentity implement
final XMLSecurityConstants.TransformMethod preferredChildTransformMethod =
getTransformer().getPreferredTransformMethod(XMLSecurityConstants.TransformMethod.XMLSecEvent);
- switch (preferredChildTransformMethod) {
- case XMLSecEvent: {
- childOutputMethod = new ChildOutputMethod() {
-
- @Override
- public void transform(Object object) throws XMLStreamException {
- getTransformer().transform((XMLSecEvent) object);
- }
+ if (preferredChildTransformMethod == XMLSecurityConstants.TransformMethod.XMLSecEvent) {
+ childOutputMethod = new ChildOutputMethod() {
- @Override
- public void doFinal() throws XMLStreamException {
+ @Override
+ public void transform(Object object) throws XMLStreamException {
+ getTransformer().transform((XMLSecEvent) object);
+ }
+
+ @Override
+ public void doFinal() throws XMLStreamException {
+ getTransformer().doFinal();
+ }
+ };
+ } else if (preferredChildTransformMethod == XMLSecurityConstants.TransformMethod.InputStream) {
+ childOutputMethod = new ChildOutputMethod() {
+
+ private UnsyncByteArrayOutputStream baos;
+ private XMLEventWriter xmlEventWriter;
+
+ @Override
+ public void transform(Object object) throws XMLStreamException {
+ if (xmlEventWriter == null) {
+ baos = new UnsyncByteArrayOutputStream();
+ xmlEventWriter = getXmlOutputFactory().createXMLEventWriter(baos);
+ }
+
+ xmlEventWriter.add((XMLSecEvent) object);
+ }
+
+ @Override
+ public void doFinal() throws XMLStreamException {
+ xmlEventWriter.close();
+ try (InputStream is = new UnsyncByteArrayInputStream(baos.toByteArray())) {
+ getTransformer().transform(is);
getTransformer().doFinal();
+ } catch (IOException ex) {
+ throw new XMLStreamException(ex);
}
- };
- break;
- }
- case InputStream: {
- childOutputMethod = new ChildOutputMethod() {
-
- private UnsyncByteArrayOutputStream baos;
- private XMLEventWriter xmlEventWriter;
-
- @Override
- public void transform(Object object) throws XMLStreamException {
- if (xmlEventWriter == null) {
- baos = new UnsyncByteArrayOutputStream();
- xmlEventWriter = getXmlOutputFactory().createXMLEventWriter(baos);
- }
-
- xmlEventWriter.add((XMLSecEvent) object);
- }
-
- @Override
- public void doFinal() throws XMLStreamException {
- xmlEventWriter.close();
- try (InputStream is = new UnsyncByteArrayInputStream(baos.toByteArray())) {
- getTransformer().transform(is);
- getTransformer().doFinal();
- } catch (IOException ex) {
- throw new XMLStreamException(ex);
- }
- }
- };
- break;
- }
+ }
+ };
}
}
if (childOutputMethod != null) {
@@ -192,54 +187,49 @@ public class TransformIdentity implement
final XMLSecurityConstants.TransformMethod preferredChildTransformMethod =
getTransformer().getPreferredTransformMethod(XMLSecurityConstants.TransformMethod.InputStream);
- switch (preferredChildTransformMethod) {
- case XMLSecEvent: {
- childOutputMethod = new ChildOutputMethod() {
-
- private XMLEventReaderInputProcessor xmlEventReaderInputProcessor;
-
- @Override
- public void transform(Object object) throws XMLStreamException {
- if (xmlEventReaderInputProcessor == null) {
- xmlEventReaderInputProcessor = new XMLEventReaderInputProcessor(
- null,
- getXmlInputFactory().createXMLStreamReader(inputStream)
- );
- }
- try {
- XMLSecEvent xmlSecEvent;
- do {
- xmlSecEvent = xmlEventReaderInputProcessor.processNextEvent(null);
- getTransformer().transform(xmlSecEvent);
- } while (xmlSecEvent.getEventType() != XMLStreamConstants.END_DOCUMENT);
- } catch (XMLSecurityException e) {
- throw new XMLStreamException(e);
- }
- }
+ if (preferredChildTransformMethod == XMLSecurityConstants.TransformMethod.XMLSecEvent) {
+ childOutputMethod = new ChildOutputMethod() {
- @Override
- public void doFinal() throws XMLStreamException {
- getTransformer().doFinal();
- }
- };
- break;
- }
- case InputStream: {
- childOutputMethod = new ChildOutputMethod() {
-
- @Override
- public void transform(Object object) throws XMLStreamException {
- getTransformer().transform(inputStream);
- }
+ private XMLEventReaderInputProcessor xmlEventReaderInputProcessor;
- @Override
- public void doFinal() throws XMLStreamException {
- getTransformer().doFinal();
- }
+ @Override
+ public void transform(Object object) throws XMLStreamException {
+ if (xmlEventReaderInputProcessor == null) {
+ xmlEventReaderInputProcessor = new XMLEventReaderInputProcessor(
+ null,
+ getXmlInputFactory().createXMLStreamReader(inputStream)
+ );
+ }
+ try {
+ XMLSecEvent xmlSecEvent;
+ do {
+ xmlSecEvent = xmlEventReaderInputProcessor.processNextEvent(null);
+ getTransformer().transform(xmlSecEvent);
+ } while (xmlSecEvent.getEventType() != XMLStreamConstants.END_DOCUMENT);
+ } catch (XMLSecurityException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ @Override
+ public void doFinal() throws XMLStreamException {
+ getTransformer().doFinal();
+ }
+ };
+ } else if (preferredChildTransformMethod == XMLSecurityConstants.TransformMethod.InputStream) {
+ childOutputMethod = new ChildOutputMethod() {
+
+ @Override
+ public void transform(Object object) throws XMLStreamException {
+ getTransformer().transform(inputStream);
+ }
+
+ @Override
+ public void doFinal() throws XMLStreamException {
+ getTransformer().doFinal();
+ }
- };
- break;
- }
+ };
}
}
if (childOutputMethod != null) {
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformBase64Decode.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformBase64Decode.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformBase64Decode.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformBase64Decode.java Thu Feb 14 10:33:50 2019
@@ -162,11 +162,9 @@ public class TransformBase64Decode exten
void traverseElement(Element node, StringBuilder sb) {
Node sibling = node.getFirstChild();
while (sibling != null) {
- switch (sibling.getNodeType()) {
- case Node.ELEMENT_NODE:
+ if (Node.ELEMENT_NODE == sibling.getNodeType()) {
traverseElement((Element)sibling, sb);
- break;
- case Node.TEXT_NODE:
+ } else if (Node.TEXT_NODE == sibling.getNodeType()) {
sb.append(((Text)sibling).getData());
}
sibling = sibling.getNextSibling();
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureTest.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureTest.java Thu Feb 14 10:33:50 2019
@@ -109,13 +109,10 @@ public class XMLSignatureTest {
// for generating XMLSignature objects
for (int i = 0; i < 2; i++) {
try {
- switch (i) {
- case 0:
+ if (i == 0) {
sig = fac.newXMLSignature(null, defKi);
- break;
- case 1:
+ } else if (i == 1) {
sig = fac.newXMLSignature(null, defKi, objs, id, sigValueId);
- break;
}
fail("Should throw a NPE for null references");
} catch (NullPointerException npe) {
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/RetrievalMethodTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/RetrievalMethodTest.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/RetrievalMethodTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/RetrievalMethodTest.java Thu Feb 14 10:33:50 2019
@@ -92,13 +92,10 @@ public class RetrievalMethodTest {
String type = "http://www.w3.org/2000/09/xmldsig#X509Data";
RetrievalMethod rm = null;
for (int i = 0; i < 2; i++) {
- switch (i) {
- case 0:
+ if (i == 0) {
rm = fac.newRetrievalMethod(uri);
- break;
- case 1:
+ } else if (i == 1) {
rm = fac.newRetrievalMethod(uri, type, null);
- break;
}
try {
rm.isFeatureSupported(null);
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/AbstractPerformanceTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/AbstractPerformanceTest.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/AbstractPerformanceTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/AbstractPerformanceTest.java Thu Feb 14 10:33:50 2019
@@ -136,10 +136,8 @@ public abstract class AbstractPerformanc
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(fileInputStream);
while (xmlStreamReader.hasNext()) {
xmlStreamReader.next();
- switch (xmlStreamReader.getEventType()) {
- case XMLStreamConstants.START_ELEMENT:
- i++;
- break;
+ if (XMLStreamConstants.START_ELEMENT == xmlStreamReader.getEventType()) {
+ i++;
}
}
xmlStreamReader.close();
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/utils/XMLSecEventAllocator.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/utils/XMLSecEventAllocator.java?rev=1853571&r1=1853570&r2=1853571&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/utils/XMLSecEventAllocator.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/utils/XMLSecEventAllocator.java Thu Feb 14 10:33:50 2019
@@ -53,15 +53,10 @@ public class XMLSecEventAllocator implem
@Override
public XMLEvent allocate(XMLStreamReader xmlStreamReader) throws XMLStreamException {
XMLSecEvent xmlSecEvent = XMLSecEventFactory.allocate(xmlStreamReader, parentXmlSecStartElement);
- switch (xmlSecEvent.getEventType()) {
- case XMLStreamConstants.START_ELEMENT:
- parentXmlSecStartElement = (XMLSecStartElement) xmlSecEvent;
- break;
- case XMLStreamConstants.END_ELEMENT:
- if (parentXmlSecStartElement != null) {
- parentXmlSecStartElement = parentXmlSecStartElement.getParentXMLSecStartElement();
- }
- break;
+ if (XMLStreamConstants.START_ELEMENT == xmlSecEvent.getEventType()) {
+ parentXmlSecStartElement = (XMLSecStartElement) xmlSecEvent;
+ } else if (XMLStreamConstants.START_ELEMENT == xmlSecEvent.getEventType() && parentXmlSecStartElement != null) {
+ parentXmlSecStartElement = parentXmlSecStartElement.getParentXMLSecStartElement();
}
return xmlSecEvent;
}