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 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SANTUARIO-532 Introduced ElementSelector + SecurePartFactory
- Loading branch information
1 parent
83ea8fa
commit 61de37c
Showing
56 changed files
with
1,566 additions
and
372 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
48 changes: 48 additions & 0 deletions
48
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,48 @@ | ||
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 an element to secure based on a given value of a supplied attribute name. | ||
*/ | ||
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) { | ||
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 + "']"; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
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,30 @@ | ||
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; | ||
|
||
/** | ||
* This class selects XML elements by name. | ||
*/ | ||
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) { | ||
return element != null && element.getName().equals(name); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "//" + name; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
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,32 @@ | ||
package org.apache.xml.security.stax.ext; | ||
|
||
import org.apache.xml.security.stax.ext.stax.XMLSecStartElement; | ||
|
||
/** | ||
* This singleton selects the document element. | ||
*/ | ||
public class DocumentElementSelector implements ElementSelector { | ||
|
||
private static class LazilyLoaded { | ||
|
||
@SuppressWarnings("PMD.AccessorClassGeneration") | ||
private static final DocumentElementSelector INSTANCE = new DocumentElementSelector(); | ||
} | ||
|
||
private DocumentElementSelector() { | ||
} | ||
|
||
@Override | ||
public boolean select(XMLSecStartElement element) { | ||
return element == null; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "/"; | ||
} | ||
|
||
public static DocumentElementSelector getInstance() { | ||
return LazilyLoaded.INSTANCE; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
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,38 @@ | ||
/** | ||
* 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; | ||
|
||
/** | ||
* This interface allows implementors to select <i>which</i> elements to secure, based on an element's qualified name | ||
* and skeleton DOM element. | ||
*/ | ||
public interface ElementSelector { | ||
|
||
/** | ||
* 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}. | ||
* @return {@code true} to select the given element for securing, {@code false} otherwise. | ||
*/ | ||
boolean select(XMLSecStartElement element); | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/org/apache/xml/security/stax/ext/ElementSelectorFactory.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,6 @@ | ||
package org.apache.xml.security.stax.ext; | ||
|
||
public interface ElementSelectorFactory { | ||
|
||
ElementSelector createElementSelector(); | ||
} |
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
29 changes: 29 additions & 0 deletions
29
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,29 @@ | ||
package org.apache.xml.security.stax.ext; | ||
|
||
import org.apache.xml.security.stax.ext.stax.XMLSecStartElement; | ||
|
||
public class NoElementSelector implements ElementSelector { | ||
|
||
private static class LazilyLoaded { | ||
|
||
@SuppressWarnings("PMD.AccessorClassGeneration") | ||
private static final NoElementSelector INSTANCE = new NoElementSelector(); | ||
} | ||
|
||
private NoElementSelector() { | ||
} | ||
|
||
@Override | ||
public boolean select(XMLSecStartElement element) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ""; | ||
} | ||
|
||
public static NoElementSelector getInstance() { | ||
return LazilyLoaded.INSTANCE; | ||
} | ||
} |
Oops, something went wrong.