element specified.");
- }
- for (final XmlNode rule : rules) {
- result.add(getRule(rule));
- }
- return result;
- }
-
-/**
- * @return the Rule element at the specified node.
- * @param node
- * @return
- * @throws ParseException if the Rule eement does not exist
+ * Contains methods to parse an XML document into a DeploymentRuleSetFile.
+ * Implements JNLP specification version 1.0.
*/
-private Rule getRule(final XmlNode node) throws ParseException {
-
- // create rules
- Rule rule=new Rule();
-
- // step through the elements
- //first populate the id tag attribute
- XmlNode child = node.getFirstChild();
- final String name = child.getNodeName();
- if (name.equals(DeploymentRulesSet.ID_ELEMENT)) {
- getRuleIdAttributeValues(rule, child);
- }
- //next populate the action tag attribute.
- child = child.getNextSibling();
- if (child.getNodeName().equals(DeploymentRulesSet.ACTION_ELEMENT)) {
- Action action= new Action();
- rule.setAction(action);
- getActionAttributes(action, child);
- }
- return rule;
- }
-
+class DeploymentRuleSetParser {
+
+ private static final String DEPLOYMENT_RULESET_ROOT_ELEMENT = "deploymentRulesSet";
+ private static final String ID_ELEMENT = "id";
+ private static final String RULE_SET_ELEMENT = "ruleset";
+
+ //From rule starts the actual list of rule and locations stored.
+ private static final String RULE_ELEMENT = "rule";
+ private static final String ACTION_ELEMENT = "action";
+ //id element
+ private static final String LOCATION_ATTRIBUTE = "location";
+ //certificate element
+ private static final String HASH_ATTRIBUTE = "hash";
+ //action element
+ private static final String VERSION_ATTRIBUTE = "version";
+ private static final String PERMISSION_ATTRIBUTE = "permission";
+
+ /**
+ * Create a parser for the Deployment rule set file
+ * Reads the jar and ruleset.xml file is read and parsed. Adds a deploymentRuleSet tag to cover the legalities
+ * If any with using a Oracle ruleset.xml.
+ *
+ *
+ * @param root the root XmlNode
+ * @throws ParseException if the DeploymentRuleSet string is invalid
+ */
+ public List getRules(final XmlNode root) throws ParseException {
+ // ensure it's a DeploymentRuleSet node
+ if (root == null || !root.getNodeName().equals(DEPLOYMENT_RULESET_ROOT_ELEMENT)) {
+ throw new ParseException("Root element is not a DeploymentRuleset element.");
+ }
+ return processXmlParsingOfRuleSet(root);
+ }
+
+ private List processXmlParsingOfRuleSet(final XmlNode parent) throws ParseException {
+ final XmlNode child = parent.getFirstChild();
+ final boolean isRuleSetElement = child.getNodeName().equals(RULE_SET_ELEMENT);
+ if (isRuleSetElement) {
+ return getRulesFromRuleset(child);
+ } else {
+ return new ArrayList<>();
+ }
+ }
+
+ private List getRulesFromRuleset(final XmlNode parent) throws ParseException {
+ final List result = new ArrayList<>();
+ final XmlNode[] rules = getChildNodes(parent, RULE_ELEMENT);
+
+ // ensure that there are at least one information section present
+ if (rules.length == 0) {
+ throw new ParseException("No rule element specified.");
+ }
+ for (final XmlNode rule : rules) {
+ result.add(getRule(rule));
+ }
+ return result;
+ }
+
+ private XmlRule getRule(final XmlNode node) {
+
+ // create rules
+ final XmlRule rule = new XmlRule();
+
+ // step through the elements
+ // first populate the id tag attribute
+ final XmlNode potentialIdPart = node.getFirstChild();
+ if (potentialIdPart.getNodeName().equals(ID_ELEMENT)) {
+ //certificate element
+ final String hash = getAttribute(potentialIdPart, HASH_ATTRIBUTE, null);
+ //id element
+ final XmlCertificate certs = new XmlCertificate();
+ certs.setHash(hash);
+
+ final String location = getAttribute(potentialIdPart, LOCATION_ATTRIBUTE, null);
+ rule.setCertificate(certs);
+ rule.setLocation(location);
+ }
+
+ // next populate the action tag attribute.
+ final XmlNode potentialActionPart = potentialIdPart.getNextSibling();
+ if (potentialActionPart.getNodeName().equals(ACTION_ELEMENT)) {
+ final XmlAction action = new XmlAction();
+ //action element
+ final String permission = getAttribute(potentialActionPart, PERMISSION_ATTRIBUTE, null);
+ final String version = getAttribute(potentialActionPart, VERSION_ATTRIBUTE, null);
+ action.setPermission(permission);
+ action.setVersion(version);
+ rule.setAction(action);
+ }
+
+ return rule;
+ }
}
diff --git a/core/src/main/java/net/sourceforge/jnlp/deploymentrules/DeploymentRulesSet.java b/core/src/main/java/net/sourceforge/jnlp/deploymentrules/DeploymentRulesSet.java
deleted file mode 100644
index 08d533453..000000000
--- a/core/src/main/java/net/sourceforge/jnlp/deploymentrules/DeploymentRulesSet.java
+++ /dev/null
@@ -1,154 +0,0 @@
-package net.sourceforge.jnlp.deploymentrules;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.StringReader;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
-//import javax.xml.bind.JAXBContext;
-//import javax.xml.bind.JAXBException;
-//import javax.xml.bind.Marshaller;
-//import javax.xml.bind.Unmarshaller;
-//import javax.xml.bind.annotation.*;
-
-import net.adoptopenjdk.icedteaweb.xmlparser.ParseException;
-import net.adoptopenjdk.icedteaweb.xmlparser.XMLParser;
-import net.adoptopenjdk.icedteaweb.xmlparser.XmlNode;
-import net.adoptopenjdk.icedteaweb.xmlparser.XmlParserFactory;
-public class DeploymentRulesSet {
- public static final String DEPLOYMENTRULE_SET_ROOT_ELEMENT = "deploymentRulesSet";
- public static final String RULE_SET_ELEMENT="ruleset";
- //From rule starts the actual list of rule and locations stored.
- public static final String RULE_ELEMENT="rule";
- public static final String ID_ELEMENT="id";
- public static final String CERTIFICATE_ELEMENT="certificate";
- public static final String ACTION_ELEMENT="action";
- public static final String MESSAGE_ELEMENT="message";
- //id element
- public static final String LOCATION_ATTRIBUTE = "location";
- //certificate element
- public static final String HASH_ATTRIBUTE = "hash";
- //action element
- public static final String VERSION_ATTRIBUTE = "version";
- public static final String PERMISSION_ATTRIBUTE = "permission";
-
-
- private List list;
- private List vettedUrls = new ArrayList();;
- private ParserSettings parserSettings;
-
- public List getVettedUrls() {
- return vettedUrls;
- }
-
- private ArrayList ruleSet;
- public List getRuleSet() {
- return ruleSet;
- }
- public void setRuleSet(List rules) {
- this.ruleSet = (ArrayList) rules;
- }
-
- private String version;
- public String getVersion() {
- return version;
- }
- public void setVersion(String version) {
- this.version = version;
- }
- private static final String RULESET_XML = "./ruleset-jaxb.xml";
-
-public static void main(String[] args) {
- //For testing
- DeploymentRulesSet ruleSet= new DeploymentRulesSet();
- try {
- ruleSet.parseDeploymentRuleSet("C:\\\\softwares\\\\icedtea-web\\\\DeploymentRuleSet.jar");
- } catch (ParseException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
-}
-
-/**
- * @param jarFilePath
- * @throws ParseException
- */
-public void parseDeploymentRuleSet(String jarFilePath) throws ParseException{
- JarFile file;
- JarEntry entry = null;
- InputStream in=null;
- String appendedXML=null;
- if (new File(jarFilePath).exists()) {
- try {
-
- file = new JarFile(new File(jarFilePath));
- entry = file.getJarEntry("ruleset.xml");
- if (entry!=null) {
- in= file.getInputStream(entry);
-
- StringBuilder textBuilder = new StringBuilder();
- try (Reader reader = new BufferedReader(new InputStreamReader
- (in, Charset.forName(StandardCharsets.UTF_8.name())))) {
- int c = 0;
- while ((c = reader.read()) != -1) {
- textBuilder.append((char) c);
- }
- }
- String content= textBuilder.toString();
- int insertCount=content.indexOf(""+fullXml+"";
- }
- System.out.println(appendedXML);
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- new ParseException("file IO exception accessing the ruleset or some network issues" + e1.getMessage());
- }
-
-
- parserSettings = new ParserSettings(true, false,true);
- final XMLParser xmlParser = XmlParserFactory.getParser(parserSettings.getParserType());
- InputStream is = new ByteArrayInputStream(appendedXML.getBytes(StandardCharsets.UTF_8));
- XmlNode root=null;
- try {
- root = xmlParser.getRootNode(is);
- } catch (ParseException e) {
- new ParseException("Could not parser the root Node" +e.getMessage());
- }
-
- DeploymentRulesSet ruleSetDescriptor = new DeploymentRulesSet();
- try {
- DeploymentRuleSetParser parser= new DeploymentRuleSetParser(ruleSetDescriptor, root, parserSettings);
- } catch (ParseException e) {
- new ParseException("Could not intialize the DeploymentRuleSetParser" +e.getMessage());
-
- }
- list = ruleSetDescriptor.getRuleSet();
- parseDeploymentRuleSet();
- }
-}
-
-private void parseDeploymentRuleSet() {
- for (Rule rules: list) {
- //Questions.. Do we also accept Urls to be vetted if DEFAULT permissions
- if (rules.getAction().getPermission().matches(PermissionsConstant.RUN)) {
- vettedUrls.add(rules.getLocation());
- }
- }
-}
-
-}
diff --git a/core/src/main/java/net/sourceforge/jnlp/deploymentrules/DeploymentRulesSetFile.java b/core/src/main/java/net/sourceforge/jnlp/deploymentrules/DeploymentRulesSetFile.java
new file mode 100644
index 000000000..dc9569c08
--- /dev/null
+++ b/core/src/main/java/net/sourceforge/jnlp/deploymentrules/DeploymentRulesSetFile.java
@@ -0,0 +1,94 @@
+package net.sourceforge.jnlp.deploymentrules;
+
+import net.adoptopenjdk.icedteaweb.io.IOUtils;
+import net.adoptopenjdk.icedteaweb.xmlparser.ParseException;
+import net.adoptopenjdk.icedteaweb.xmlparser.XMLParser;
+import net.adoptopenjdk.icedteaweb.xmlparser.XmlNode;
+import net.adoptopenjdk.icedteaweb.xmlparser.XmlParserFactory;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.stream.Collectors;
+
+import static net.adoptopenjdk.icedteaweb.xmlparser.ParserType.MALFORMED;
+
+class DeploymentRulesSetFile {
+
+ private static final String RULESET_XML = "ruleset.xml";
+ private static final String RUN = "run";
+
+ private final String rulesetPath;
+
+ public DeploymentRulesSetFile(String rulesetPath) {
+ this.rulesetPath = rulesetPath;
+ }
+
+ public List parseDeploymentRuleSet() throws ParseException {
+ final File rulesetJarFile = new File(rulesetPath);
+ if (rulesetJarFile.exists()) {
+ final String rawContent = getRulesetXmlContent(rulesetJarFile);
+ final String content = wrapInArtificialRoot(rawContent);
+ final XmlNode root = parseXml(content);
+ final List rules = extractRules(root);
+
+ return rules.stream()
+ .filter(rule -> Objects.equals(rule.getAction().getPermission(), RUN))
+ .map(XmlRule::getLocation)
+ .collect(Collectors.toList());
+ }
+ return Collections.emptyList();
+ }
+
+ private String getRulesetXmlContent(File rulesetJarFile) throws ParseException {
+ try {
+ final JarFile file = new JarFile(rulesetJarFile);
+ final JarEntry entry = file.getJarEntry(RULESET_XML);
+ if (entry == null) {
+ throw new ParseException("could not find a " + RULESET_XML + " in the jar " + rulesetJarFile);
+ }
+
+ try (final InputStream in = file.getInputStream(entry)) {
+ return IOUtils.readContentAsUtf8String(in);
+ }
+ } catch (IOException e) {
+ throw new ParseException("file IO exception accessing the ruleset or some network issues", e);
+ }
+ }
+
+ private String wrapInArtificialRoot(String content) throws ParseException {
+ final int idx = content.indexOf("");
+ }
+ final String prefix = content.substring(0, idx);
+ final String fullXml = content.substring(idx);
+ return prefix + "" + fullXml + "";
+ }
+
+ private XmlNode parseXml(String content) throws ParseException {
+ try {
+ final InputStream is = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
+ final XMLParser xmlParser = XmlParserFactory.getParser(MALFORMED);
+ return xmlParser.getRootNode(is);
+ } catch (ParseException e) {
+ throw new ParseException("Could not parser the root Node" + e.getMessage());
+ }
+ }
+
+ private List extractRules(XmlNode root) throws ParseException {
+ try {
+ return new DeploymentRuleSetParser().getRules(root);
+ } catch (ParseException e) {
+ throw new ParseException("Could not initialize the DeploymentRuleSetParser" + e.getMessage());
+ }
+ }
+
+}
diff --git a/core/src/main/java/net/sourceforge/jnlp/deploymentrules/ParserSettings.java b/core/src/main/java/net/sourceforge/jnlp/deploymentrules/ParserSettings.java
deleted file mode 100644
index 4bd368be9..000000000
--- a/core/src/main/java/net/sourceforge/jnlp/deploymentrules/ParserSettings.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/* ParserSettings.java
- Copyright (C) 2011 Red Hat, Inc.
-
-This file is part of IcedTea.
-
-IcedTea is free software; you can redistribute it and/or modify it under the
-terms of the GNU General Public License as published by the Free Software
-Foundation, version 2.
-
-IcedTea is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along with
-IcedTea; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is making a
-combined work based on this library. Thus, the terms and conditions of the GNU
-General Public License cover the whole combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent modules, and
-to copy and distribute the resulting executable under terms of your choice,
-provided that you also meet, for each linked independent module, the terms and
-conditions of the license of that module. An independent module is a module
-which is not derived from or based on this library. If you modify this library,
-you may extend this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this exception
-statement from your version.
-*/
-
-package net.sourceforge.jnlp.deploymentrules;
-
-import net.adoptopenjdk.icedteaweb.xmlparser.ParserType;
-
-import static net.adoptopenjdk.icedteaweb.xmlparser.ParserType.MALFORMED;
-import static net.adoptopenjdk.icedteaweb.xmlparser.ParserType.NORMAL;
-
-/**
- * Contains settings to be used by the Parser while parsing files.
- *
- * Immutable and therefore thread-safe.
- */
-public class ParserSettings {
-
- private final boolean isStrict;
- private final boolean extensionAllowed;
- private final boolean malformedXmlAllowed;
-
- /** Create a new ParserSettings with the default parser settings */
- public ParserSettings() {
- this(false, true, true);
- }
-
- /** Create a new ParserSettings object
- * @param strict true if parser should be strict
- * @param extensionAllowed true if extensions are allowed
- * @param malformedXmlAllowed true if xml sanitizer should be used
- */
- public ParserSettings(boolean strict, boolean extensionAllowed, boolean malformedXmlAllowed) {
- this.isStrict = strict;
- this.extensionAllowed = extensionAllowed;
- this.malformedXmlAllowed = malformedXmlAllowed;
- }
-
- /** @return true if extensions to the spec are allowed */
- boolean isExtensionAllowed() {
- return extensionAllowed;
- }
-
- /** @return true if parsing malformed xml is allowed */
- ParserType getParserType() {
- return malformedXmlAllowed ? MALFORMED : NORMAL;
- }
-
- /** @return true if strict parsing mode is to be used */
- boolean isStrict() {
- return isStrict;
- }
-}
diff --git a/core/src/main/java/net/sourceforge/jnlp/deploymentrules/PermissionsConstant.java b/core/src/main/java/net/sourceforge/jnlp/deploymentrules/PermissionsConstant.java
deleted file mode 100644
index 6bdfe563a..000000000
--- a/core/src/main/java/net/sourceforge/jnlp/deploymentrules/PermissionsConstant.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package net.sourceforge.jnlp.deploymentrules;
-
-public interface PermissionsConstant {
- public static final String RUN="run";
- public static final String BLOCK="block";
- public static final String DEFAULT="default";
-}
diff --git a/core/src/main/java/net/sourceforge/jnlp/deploymentrules/Rule.java b/core/src/main/java/net/sourceforge/jnlp/deploymentrules/Rule.java
deleted file mode 100644
index 0c7f30d4c..000000000
--- a/core/src/main/java/net/sourceforge/jnlp/deploymentrules/Rule.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package net.sourceforge.jnlp.deploymentrules;
-
-
-/*
- *
-
-
-
- */
-public class Rule {
- private String location;
-
- private Certificate certificate;
- public Certificate getCertificate() {
- return certificate;
- }
- public void setcertificate(Certificate certificate) {
- this.certificate = certificate;
- }
-
- private Action action;
-
-
-
- public Action getAction() {
- return action;
- }
- public void setAction(Action action) {
- this.action = action;
- }
- public String getLocation() {
- return location;
- }
- public void setLocation(String location) {
- this.location = location;
- }
-
-
-}
diff --git a/core/src/main/java/net/sourceforge/jnlp/deploymentrules/UrlDeploymentRulesSetUtils.java b/core/src/main/java/net/sourceforge/jnlp/deploymentrules/UrlDeploymentRulesSetUtils.java
index 1098697fe..68ebf4020 100644
--- a/core/src/main/java/net/sourceforge/jnlp/deploymentrules/UrlDeploymentRulesSetUtils.java
+++ b/core/src/main/java/net/sourceforge/jnlp/deploymentrules/UrlDeploymentRulesSetUtils.java
@@ -1,133 +1,50 @@
package net.sourceforge.jnlp.deploymentrules;
import net.adoptopenjdk.icedteaweb.Assert;
-import net.adoptopenjdk.icedteaweb.StringUtils;
import net.adoptopenjdk.icedteaweb.logging.Logger;
import net.adoptopenjdk.icedteaweb.logging.LoggerFactory;
import net.adoptopenjdk.icedteaweb.xmlparser.ParseException;
import net.sourceforge.jnlp.runtime.JNLPRuntime;
-import net.sourceforge.jnlp.util.IpUtil;
-import net.sourceforge.jnlp.deploymentrules.DeploymentRule;
-import net.sourceforge.jnlp.deploymentrules.DeploymentRulesSet;
-//import net.sourceforge.jnlp.util.whitelist.UrlWhiteListUtils;
import java.net.URL;
+import java.util.Collections;
import java.util.List;
-import java.util.stream.Collectors;
-/*
- * Added DeploymentRuleSet white listing checks
- * Added method call :isUrlInDeploymentRuleSetUrl
- * This method will do the checks of the DeploymentRuleSet.jar file of ruleset.xml
- * DJ- 3/02/2021
- *
- */
+
import static net.sourceforge.jnlp.config.ConfigurationConstants.KEY_DEPLOYMENT_RULE_SET;
-/*
- * @author DJ
- * @date 03/02/2021
- * This class is implementing the DeplyomentRuleSet checks for the jar
- * Added DeploymentRuleSet white listing checks
- * Added method call :isUrlInDeploymentRuleSetUrl
- * *
- */
-public class UrlDeploymentRulesSetUtils {
- private static List applicationUrlDeploymentRuleSetList;
- private static List applicationDeploymentRuleSetList;
- private final static DeploymentRulesSet rulesSet= new DeploymentRulesSet();
- private static boolean isRuleSetInitialized=false;
+public class UrlDeploymentRulesSetUtils {
+
private static final Logger LOG = LoggerFactory.getLogger(UrlDeploymentRulesSetUtils.class);
+ private static List applicationDeploymentRuleSetList;
- public static List getApplicationUrlDeploymentRuleSetList() {
- if (applicationUrlDeploymentRuleSetList == null) {
- applicationUrlDeploymentRuleSetList = loadDeploymentRuleSetFromConfiguration(KEY_DEPLOYMENT_RULE_SET);
- }
- return applicationUrlDeploymentRuleSetList;
- }
-
- public static List getApplicationLinkDeploymentRuleSetList() {
- if (applicationUrlDeploymentRuleSetList == null) {
- applicationDeploymentRuleSetList = loadDeploymentRuleSetLinksFromConfiguration(KEY_DEPLOYMENT_RULE_SET);
+ private static List getApplicationLinkDeploymentRuleSetList() {
+ if (applicationDeploymentRuleSetList == null) {
+ applicationDeploymentRuleSetList = loadDeploymentRuleSetLinksFromConfiguration();
}
return applicationDeploymentRuleSetList;
}
- /**
- * @author-DJ
- * @date 03/02/21
- * Added for deploymentRuleSet checks
- * @param deploymentRuleSetJarPath
- * @return
- */
- public static List loadDeploymentRuleSetLinksFromConfiguration(final String deploymentRuleSetPropertyName) {
- initRulesSet(deploymentRuleSetPropertyName);
- return rulesSet.getVettedUrls();
- }
-
- private static void initRulesSet(final String deploymentRuleSetPropertyName) {
- try {
- rulesSet.parseDeploymentRuleSet(deploymentRuleSetPropertyName);
- isRuleSetInitialized=true;
- } catch (ParseException e) {
- LOG.error("Please Check property name . This should point to a valid DeploymentRuleSet jar file"+deploymentRuleSetPropertyName);
- //absorb the Error and send error message for trouble shooting.
- e.printStackTrace();
- }
-
- }
-
- public static List loadRuleSetFromConfiguration(final String deploymentRuleSetJarPath) {
- List rulesSetList=null;
- if (!isRuleSetInitialized) {
- initRulesSet(deploymentRuleSetJarPath);
- }else {
- rulesSetList=rulesSet.getRuleSet();
- }
- return rulesSetList;
- }
-
- /**
- * @author-DJ
- * @date 03/02/21
- * Added for deploymentRuleSet checks
- * @param deploymentRuleSetJarPath
- * @return
- */
- public static List loadDeploymentRuleSetFromConfiguration(final String deploymentRuleSetJarPath) {
- //Implement the DeplymentRuleSet parser here. DJ and create the DeploymentRuleSet.
- return loadRuleSetFromConfiguration(deploymentRuleSetJarPath);
- }
- /**
- *
- * Adding by DJ 3/2/2021 to add DeploymentRuleSet functionality
- * @param url
- * @return
- */
- public static boolean isUrlInDeploymentRuleSetlist(final URL url) {
- return isUrlInDeploymentRuleSetUrl(url, getApplicationLinkDeploymentRuleSetList());
+ private static List loadDeploymentRuleSetLinksFromConfiguration() {
+ try {
+ final String rulesetPath = JNLPRuntime.getConfiguration().getProperty(KEY_DEPLOYMENT_RULE_SET);
+ final DeploymentRulesSetFile rulesSetFile = new DeploymentRulesSetFile(rulesetPath);
+ return rulesSetFile.parseDeploymentRuleSet();
+ } catch (ParseException e) {
+ LOG.error("Please Check config property " + KEY_DEPLOYMENT_RULE_SET + ". This should point to a valid DeploymentRuleSet jar file: ", e);
+ return Collections.emptyList();
+ }
}
-
- /**
- * isUrlInDeploymentRuleSetUrl
- * Adding by DJ 3/2/2021 to add DeploymentRuleSet functionality
- * @param url
- * @param whiteList
- * @return
- */
- public static boolean isUrlInDeploymentRuleSetUrl(final URL url, final List deploymentRuleSetList) {
+ public static boolean isUrlInDeploymentRuleSet(final URL url) {
Assert.requireNonNull(url, "url");
- Assert.requireNonNull(deploymentRuleSetList, "whiteList");
+ return isUrlInDeploymentRuleSetUrl(url, getApplicationLinkDeploymentRuleSetList());
+ }
+ private static boolean isUrlInDeploymentRuleSetUrl(final URL url, final List deploymentRuleSetList) {
if (deploymentRuleSetList.isEmpty()) {
return false; // empty deploymentRuleSetList == allow none. Nothing is whitelisted
}
-
-
-
return deploymentRuleSetList.stream().anyMatch(wlEntry -> wlEntry.matches(url.getHost()));
}
-
-
}
diff --git a/core/src/main/java/net/sourceforge/jnlp/deploymentrules/XmlAction.java b/core/src/main/java/net/sourceforge/jnlp/deploymentrules/XmlAction.java
new file mode 100644
index 000000000..01bd81e9f
--- /dev/null
+++ b/core/src/main/java/net/sourceforge/jnlp/deploymentrules/XmlAction.java
@@ -0,0 +1,37 @@
+package net.sourceforge.jnlp.deploymentrules;
+
+/**
+ * Action object of Rule from the ruleset file
+ * Stores the attributes value from id tag permission and version.
+ * If permission is run, then location which is the url whitelisted is permitted to be accessible.
+ */
+class XmlAction {
+
+ private String permission;
+ private String version;
+ private String message;
+
+ public String getPermission() {
+ return permission;
+ }
+
+ public void setPermission(final String permission) {
+ this.permission = permission;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(final String version) {
+ this.version = version;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(final String message) {
+ this.message = message;
+ }
+}
diff --git a/core/src/main/java/net/sourceforge/jnlp/deploymentrules/XmlCertificate.java b/core/src/main/java/net/sourceforge/jnlp/deploymentrules/XmlCertificate.java
new file mode 100644
index 000000000..9609c79ad
--- /dev/null
+++ b/core/src/main/java/net/sourceforge/jnlp/deploymentrules/XmlCertificate.java
@@ -0,0 +1,20 @@
+package net.sourceforge.jnlp.deploymentrules;
+
+/**
+ * Certificate object of Rule from the ruleset file
+ * Stores the attributes value from action tag hash.
+ * This is class is rarely used yet and can be extended when a
+ * UI component to display the entire ruleset.xml file and edit it will be enhanced
+ */
+class XmlCertificate {
+
+ private String hash;
+
+ public String getHash() {
+ return hash;
+ }
+
+ public void setHash(String hash) {
+ this.hash = hash;
+ }
+}
diff --git a/core/src/main/java/net/sourceforge/jnlp/deploymentrules/XmlRule.java b/core/src/main/java/net/sourceforge/jnlp/deploymentrules/XmlRule.java
new file mode 100644
index 000000000..9125bd0c2
--- /dev/null
+++ b/core/src/main/java/net/sourceforge/jnlp/deploymentrules/XmlRule.java
@@ -0,0 +1,31 @@
+package net.sourceforge.jnlp.deploymentrules;
+
+class XmlRule {
+ private String location;
+ private XmlCertificate certificate;
+ private XmlAction action;
+
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(final String location) {
+ this.location = location;
+ }
+
+ public XmlCertificate getCertificate() {
+ return certificate;
+ }
+
+ public void setCertificate(final XmlCertificate certificate) {
+ this.certificate = certificate;
+ }
+
+ public XmlAction getAction() {
+ return action;
+ }
+
+ public void setAction(final XmlAction action) {
+ this.action = action;
+ }
+}
diff --git a/core/src/main/java/net/sourceforge/jnlp/deploymentrules/jaxb.properties b/core/src/main/java/net/sourceforge/jnlp/deploymentrules/jaxb.properties
deleted file mode 100644
index 5837a4c25..000000000
--- a/core/src/main/java/net/sourceforge/jnlp/deploymentrules/jaxb.properties
+++ /dev/null
@@ -1 +0,0 @@
-javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
\ No newline at end of file