This repository has been archived by the owner on May 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SANTUARIO-532 Refactored "which", "how" and "how many" elements to se…
…cure in ElementSelector, SecurePartFactory/SecurePart and requiredNumOccurrences
- Loading branch information
1 parent
83ea8fa
commit 7212e12
Showing
57 changed files
with
1,488 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/org/apache/xml/security/stax/ext/ByAttributeElementSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.apache.xml.security.stax.ext; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import javax.xml.namespace.QName; | ||
import javax.xml.stream.events.Attribute; | ||
|
||
import org.apache.xml.security.stax.ext.stax.XMLSecStartElement; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* Selects elements to secure based on a given attribute name and value. | ||
* This is equivalent to {@link SecurePart#setIdToSecure(String)} + | ||
* {@link XMLSecurityProperties#setIdAttributeNS(QName)}. | ||
*/ | ||
public class ByAttributeElementSelector implements ElementSelector { | ||
|
||
private final Supplier<QName> nameSupplier; | ||
private final String value; | ||
|
||
ByAttributeElementSelector(Supplier<QName> nameSupplier, String value) { | ||
requireNonNull(value, "value is null"); | ||
this.nameSupplier = nameSupplier; | ||
this.value = value; | ||
} | ||
|
||
public ByAttributeElementSelector(QName name, String value) { | ||
this(() -> name, value); | ||
} | ||
|
||
@Override | ||
public boolean select(XMLSecStartElement element, OutputProcessorChain outputProcessorChain) { | ||
if (element != null) { | ||
QName name = nameSupplier.get(); | ||
if (name != null) { | ||
Attribute attribute = element.getAttributeByName(name); | ||
if (attribute != null && value.equals(attribute.getValue())) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "//*[@" + nameSupplier.get() + "='" + value + "']"; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/org/apache/xml/security/stax/ext/ByNameElementSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.apache.xml.security.stax.ext; | ||
|
||
import javax.xml.namespace.QName; | ||
|
||
import org.apache.xml.security.stax.ext.stax.XMLSecStartElement; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* Selects elements to secure by element name. | ||
* This is equivalent to {@link SecurePart#setName(QName)}. | ||
*/ | ||
public class ByNameElementSelector implements ElementSelector { | ||
|
||
private final QName name; | ||
|
||
public ByNameElementSelector(QName name) { | ||
requireNonNull(name, "name is null"); | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public boolean select(XMLSecStartElement element, OutputProcessorChain outputProcessorChain) { | ||
return element != null && element.getName().equals(name); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "//" + name; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/org/apache/xml/security/stax/ext/DocumentElementSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.apache.xml.security.stax.ext; | ||
|
||
import org.apache.xml.security.stax.ext.stax.XMLSecStartElement; | ||
|
||
/** | ||
* Selects the document element (the {@code null} element). | ||
* Use this selector to secure parts that are not specific to a certain element, but rather apply to the document as a | ||
* whole, such as a secure part that has an external reference. | ||
* This is equivalent to {@link SecurePart#setExternalReference(String)}. | ||
*/ | ||
public class DocumentElementSelector implements ElementSelector { | ||
|
||
private static class LazilyInitialized { | ||
|
||
@SuppressWarnings("PMD.AccessorClassGeneration") | ||
private static final DocumentElementSelector INSTANCE = new DocumentElementSelector(); | ||
} | ||
|
||
private DocumentElementSelector() { | ||
} | ||
|
||
@Override | ||
public boolean select(XMLSecStartElement element, OutputProcessorChain outputProcessorChain) { | ||
return element == null; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "/"; | ||
} | ||
|
||
public static DocumentElementSelector getInstance() { | ||
return LazilyInitialized.INSTANCE; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/org/apache/xml/security/stax/ext/ElementSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.xml.security.stax.ext; | ||
|
||
import org.apache.xml.security.stax.ext.stax.XMLSecStartElement; | ||
|
||
/** | ||
* An element selector defines <i>which</i> elements to secure, based on a given element and in the context provided by | ||
* the output processor chain. | ||
* An implementation may cooperate with a specific output processor implementation, which can be installed on the output | ||
* processor chain using {@link #init(OutputProcessorChain)}. | ||
* Implementations must be stateless, operating solely based on constructor parameters and parameters in the context | ||
* provided by the output processor chain. | ||
* If at all, parameters are typically passed from the cooperating output processor to the element selector (and further | ||
* on the secure part factory) in the security context on the output processor chain, which can be accessed with | ||
* {@link OutputProcessorChain#getSecurityContext()}. | ||
*/ | ||
public interface ElementSelector { | ||
|
||
/** | ||
* Initializes an output processor chain with an output processor, allowing implementations to install a cooperating | ||
* output processor. | ||
* Such an output processor may populate the context with additional parameters to be used upon | ||
* Implementations that don't need extra parameters beyond what's provided by {@link XMLSecStartElement} don't need | ||
* a cooperating output processor, and can leave this method unimplemented. | ||
* This method will be called upon initialization of document processing. | ||
* | ||
* @param outputProcessorChain The output processor chain to initialize, never {@code null}. | ||
*/ | ||
default void init(OutputProcessorChain outputProcessorChain) {} | ||
|
||
/** | ||
* Selects a given element for securing, or {@code null} to indicate the document element (the document as a whole). | ||
* In practice, the element {@code null} is used to select secure parts that define external references to be | ||
* digested. | ||
* | ||
* @param element The element to select, possibly {@code null}. | ||
* @param outputProcessorChain The output processor chain providing security context and document context, | ||
* never {@code null}. | ||
* @return {@code true} to select the given element for securing, {@code false} otherwise. | ||
*/ | ||
boolean select(XMLSecStartElement element, OutputProcessorChain outputProcessorChain); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/org/apache/xml/security/stax/ext/NoElementSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.apache.xml.security.stax.ext; | ||
|
||
import org.apache.xml.security.stax.ext.stax.XMLSecStartElement; | ||
|
||
/** | ||
* An element selector that selects no elements. | ||
*/ | ||
public class NoElementSelector implements ElementSelector { | ||
|
||
private static class LazilyInitialized { | ||
|
||
@SuppressWarnings("PMD.AccessorClassGeneration") | ||
private static final NoElementSelector INSTANCE = new NoElementSelector(); | ||
} | ||
|
||
private NoElementSelector() { | ||
} | ||
|
||
@Override | ||
public boolean select(XMLSecStartElement element, OutputProcessorChain outputProcessorChain) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ""; | ||
} | ||
|
||
public static NoElementSelector getInstance() { | ||
return LazilyInitialized.INSTANCE; | ||
} | ||
} |
Oops, something went wrong.