Skip to content

Commit

Permalink
Refactor the JXPathFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
kyakdan committed Oct 19, 2022
1 parent 771b5fc commit fa9fb1e
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/main/java/org/apache/commons/jxpath/ri/JXPathFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,18 @@

/**
* A filter to be used by JXPath, to evaluate the xpath string values to impose any restrictions.
* This class implements specific filter interfaces, and implements methods in those.
* This class implements specific filter interfaces, and implements methods in those.
* For instance, it JXPathClassFilter interface, which is used to check if any restricted java classes are passed via xpath
* JXPath uses this filter instance when an extension function instance is created.
*/
public class JXPathFilter implements JXPathClassFilter {
private Set<String> allowedClassesList = null;
private final Set<String> allowedClasses;

public JXPathFilter() {
init();
}

public void init() {
this.allowedClasses = new HashSet<>();
final String allowedClasses = System.getProperty("jxpath.class.allow");
if (allowedClasses != null && !allowedClasses.isEmpty()) {
allowedClassesList = new HashSet<>();
allowedClassesList.addAll(Arrays.asList(allowedClasses.split(",")));
this.allowedClasses.addAll(Arrays.asList(allowedClasses.split(",")));
}
}

Expand All @@ -50,10 +46,10 @@ public void init() {
*/
@Override
public boolean exposeToXPath(String className) {
if (allowedClassesList == null || allowedClassesList.size() < 1) {
if (allowedClasses.isEmpty()) {
return false;
}

return allowedClassesList.contains(className) || allowedClassesList.contains("*");
return allowedClasses.contains(className) || allowedClasses.contains("*");
}
}

0 comments on commit fa9fb1e

Please sign in to comment.