Skip to content

Commit dd72603

Browse files
M026875M026875
authored andcommitted
pushing changes to dhirenjoshi/IcedTea-Web/deploymentruleset-add branch.
Removed reference to jaxb . Only plain XML parsing is being done now.
1 parent 840856e commit dd72603

File tree

9 files changed

+454
-185
lines changed

9 files changed

+454
-185
lines changed

core/src/main/java/net/sourceforge/jnlp/deploymentrules/Action.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
package net.sourceforge.jnlp.deploymentrules;
2-
3-
import javax.xml.bind.annotation.XmlAccessType;
4-
import javax.xml.bind.annotation.XmlAccessorType;
5-
import javax.xml.bind.annotation.XmlAttribute;
6-
import javax.xml.bind.annotation.XmlElement;
7-
import javax.xml.bind.annotation.XmlRootElement;
8-
9-
@XmlRootElement(name = "action")
10-
@XmlAccessorType(XmlAccessType.FIELD)
2+
/**
3+
* Action object of Rule from the rulset file
4+
* Stores the attributes value from id tag
5+
* permission and version.
6+
* If permission is run, then location which is the url whitelisted is permitted to be accessible.
7+
*/
118
public class Action {
12-
@XmlAttribute
9+
1310
private String permission;
11+
private String version;
12+
public String getVersion() {
13+
return version;
14+
}
15+
public void setVersion(String version) {
16+
this.version = version;
17+
}
1418
public String getPermission() {
1519
return permission;
1620
}
1721
public void setPermission(String permission) {
1822
this.permission = permission;
1923
}
20-
@XmlElement
24+
2125
private String message;
2226
public String getMessage() {
2327
return message;

core/src/main/java/net/sourceforge/jnlp/deploymentrules/Certificate.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
package net.sourceforge.jnlp.deploymentrules;
2-
3-
import javax.xml.bind.annotation.XmlAccessType;
4-
import javax.xml.bind.annotation.XmlAccessorType;
5-
import javax.xml.bind.annotation.XmlAttribute;
6-
import javax.xml.bind.annotation.XmlRootElement;
7-
8-
//import org.eclipse.persistence.oxm.annotations.XmlPath;
9-
10-
@XmlRootElement(name = "certificate")
11-
//If you want you can define the order in which the fields are written
12-
//Optional
13-
//@XmlType(propOrder = { "id", "action","message"})
14-
15-
@XmlAccessorType(XmlAccessType.FIELD)
16-
2+
/**
3+
* Certificate object of Rule from the rulset file
4+
* Stores the attributes value from action tag
5+
* hash.
6+
* This is class is rarely used yet and can be extended when a
7+
* UI component to display the entire rulset.xml file and edit it will be enhanced
8+
*/
179
public class Certificate {
18-
@XmlAttribute(name="hash")
10+
1911
private String hash;
2012

2113

core/src/main/java/net/sourceforge/jnlp/deploymentrules/DeploymentRule.java

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package net.sourceforge.jnlp.deploymentrules;
2-
import javax.xml.bind.annotation.*;
3-
import org.eclipse.persistence.oxm.annotations.XmlPath;
2+
3+
44
/*
55
* This class copies all the deployment Rule set to a class.
66
* <ruleset version="1.0+">
77
<rule> <!-- allow anything signed with company's public cert -->
88
<id>
9-
<certificate hash="794F53C746E2AA77D84B843BE942CAB4309F258FD946D62A6C4CCEAB8E1DB2C6" />
9+
<certificate hash="84B843BE942CAB4309F258FD946D62A6C4CCEAB8E1DB2C6" />
1010
</id>
1111
<action permission="run" version="SECURE" />
1212
</rule>
@@ -28,48 +28,33 @@
2828
</rule>
2929
</ruleset>
3030
* */
31-
@XmlRootElement(name = "rule")
32-
//If you want you can define the order in which the fields are written
33-
//Optional
34-
//@XmlType(propOrder = { "id", "action","message"})
3531

36-
@XmlAccessorType(XmlAccessType.FIELD)
32+
3733
public class DeploymentRule {
3834

39-
@XmlElement(name="id")
40-
private RuleInfo ruleInfo;
35+
private Rule rule;
4136

42-
public RuleInfo getRuleInfo() {
43-
return ruleInfo;
37+
public Rule getRule() {
38+
return rule;
4439
}
45-
public void setRuleInfo(RuleInfo ruleInfo) {
46-
this.ruleInfo = ruleInfo;
47-
}
48-
4940

50-
private String name;
51-
public String getName() {
52-
return name;
53-
}
54-
public void setName(String name) {
55-
this.name = name;
56-
}
5741
public String getTitle() {
5842
return title;
5943
}
6044
public void setTitle(String title) {
6145
this.title = title;
6246
}
63-
@XmlElement(name="action")
64-
private Action ruleAction;
6547

66-
public Action getRuleAction() {
67-
return ruleAction;
48+
49+
private Action action;
50+
51+
public Action getAction() {
52+
return action;
6853
}
69-
public void setRuleAction(Action ruleAction) {
70-
this.ruleAction = ruleAction;
54+
public void setAction(Action action) {
55+
this.action = action;
7156
}
72-
@XmlAttribute
57+
7358
private String version;
7459

7560

@@ -80,7 +65,6 @@ public void setVersion(String version) {
8065
this.version = version;
8166
}
8267

83-
@XmlElement(name="title")
8468
private String title;
8569

8670

core/src/main/java/net/sourceforge/jnlp/deploymentrules/DeploymentRuleSetJarVerifier.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
import net.sourceforge.jnlp.security.AppVerifier;
1010
import net.sourceforge.jnlp.tools.CertInformation;
1111
import net.sourceforge.jnlp.tools.JarCertVerifier;
12-
12+
/**
13+
* DeploymentRuleSetJarVerifier object for accessing jar file.
14+
*
15+
* This is class is rarely used yet and can be extended when a
16+
* UI component to display the entire rulset.xml file and edit it will be enhanced
17+
*/
1318
public class DeploymentRuleSetJarVerifier implements AppVerifier {
1419

1520
@Override
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
package net.sourceforge.jnlp.deploymentrules;
2+
3+
import net.adoptopenjdk.icedteaweb.Assert;
4+
import net.adoptopenjdk.icedteaweb.IcedTeaWebConstants;
5+
import net.adoptopenjdk.icedteaweb.JavaSystemProperties;
6+
import net.adoptopenjdk.icedteaweb.i18n.Translator;
7+
import net.adoptopenjdk.icedteaweb.jnlp.element.EntryPoint;
8+
9+
import net.adoptopenjdk.icedteaweb.jvm.JvmUtils;
10+
import net.adoptopenjdk.icedteaweb.logging.Logger;
11+
import net.adoptopenjdk.icedteaweb.logging.LoggerFactory;
12+
import net.adoptopenjdk.icedteaweb.ui.swing.ScreenFinder;
13+
import net.adoptopenjdk.icedteaweb.xmlparser.ParseException;
14+
import net.adoptopenjdk.icedteaweb.xmlparser.XMLParser;
15+
import net.adoptopenjdk.icedteaweb.xmlparser.XmlNode;
16+
17+
18+
import javax.swing.JOptionPane;
19+
import java.awt.Rectangle;
20+
import java.net.MalformedURLException;
21+
import java.net.URL;
22+
import java.util.ArrayList;
23+
import java.util.HashMap;
24+
import java.util.List;
25+
import java.util.Locale;
26+
import java.util.Map;
27+
import java.util.StringTokenizer;
28+
import java.util.regex.Matcher;
29+
import java.util.regex.Pattern;
30+
31+
import static java.lang.Boolean.*;
32+
import static java.util.Arrays.asList;
33+
34+
import static net.adoptopenjdk.icedteaweb.xmlparser.NodeUtils.getAttribute;
35+
import static net.adoptopenjdk.icedteaweb.xmlparser.NodeUtils.getChildNode;
36+
import static net.adoptopenjdk.icedteaweb.xmlparser.NodeUtils.getChildNodes;
37+
import static net.adoptopenjdk.icedteaweb.xmlparser.NodeUtils.getRequiredAttribute;
38+
import static net.adoptopenjdk.icedteaweb.xmlparser.NodeUtils.getRequiredURL;
39+
import static net.adoptopenjdk.icedteaweb.xmlparser.NodeUtils.getSpanText;
40+
import static net.adoptopenjdk.icedteaweb.xmlparser.NodeUtils.getURL;
41+
42+
43+
/**
44+
* Contains methods to parse an XML document into a DeploymentRuleSetFile. Implements JNLP
45+
* specification version 1.0.
46+
*
47+
* @author <a href="mailto:dhirenjoshi@gmail.com">Dhiren Joshi
48+
* (JAM)</a> - initial author
49+
* @version $Revision: 1.13 $
50+
*/
51+
public final class DeploymentRuleSetParser {
52+
53+
private static final Logger LOG = LoggerFactory.getLogger(DeploymentRuleSetParser.class);
54+
55+
56+
57+
/**
58+
* the file reference
59+
*/
60+
private DeploymentRulesSet file=null; // do not use (uninitialized)
61+
62+
/**
63+
* the root node
64+
*/
65+
private final XmlNode root;
66+
/**
67+
* whether to throw errors on non-fatal errors.
68+
*/
69+
private final boolean strict; // if strict==true parses a file with no error then strict==false should also
70+
71+
/**
72+
* whether to allow extensions to the JNLP specification
73+
*/
74+
private final boolean allowExtensions;
75+
76+
77+
78+
/**
79+
* Create a parser for the Deployment rule set file
80+
* Reads the jar and ruleset.xml file is read and parsed. Adds a deploymentRuleSet tag to cover the legalities
81+
* If any with using a Oracle ruleset.xml.
82+
*
83+
* * @throws ParseException if the DeploymentRuleSet string is invalid
84+
*/
85+
/**
86+
* @param ruleSet the object created from the parsed ruleset.xml
87+
* @param root , the root XmlNode
88+
* @param settings , the parser settings
89+
* @throws ParseException
90+
*/
91+
public DeploymentRuleSetParser(final DeploymentRulesSet ruleSet, final XmlNode root, final ParserSettings settings) throws ParseException {
92+
this.file = file;
93+
this.root = root;
94+
this.strict = settings.isStrict();
95+
this.allowExtensions = settings.isExtensionAllowed();
96+
97+
// ensure it's a DeploymentRuleSet node
98+
if (root == null || !root.getNodeName().equals(DeploymentRulesSet.DEPLOYMENTRULE_SET_ROOT_ELEMENT)) {
99+
throw new ParseException("Root element is not a DeploymentRuleset element.");
100+
}
101+
processXmlParsingOfRuleSet(ruleSet,root);
102+
103+
}
104+
105+
106+
107+
/**
108+
* Returns the rule attributes populated
109+
* @param rule
110+
* @param root
111+
* @return rule object populated with attributes values
112+
*/
113+
public Rule getRuleIdAttributeValues(Rule rule, XmlNode root) {
114+
//certificate element
115+
final String hash = getAttribute(root, DeploymentRulesSet.HASH_ATTRIBUTE, null);
116+
//id element
117+
Certificate certs= new Certificate();
118+
certs.setHash(hash);
119+
final String location = getAttribute(root, DeploymentRulesSet.LOCATION_ATTRIBUTE, null);
120+
rule.setcertificate(certs);
121+
rule.setLocation(location);
122+
return rule;
123+
}
124+
125+
/**
126+
*
127+
* @param action
128+
* @param root
129+
* @return Action attributes sets
130+
*/
131+
public Action getActionAttributes(Action action, XmlNode root) {
132+
//action element
133+
final String permission = getAttribute(root, DeploymentRulesSet.PERMISSION_ATTRIBUTE, null);
134+
String version = getAttribute(root, DeploymentRulesSet.VERSION_ATTRIBUTE, null);
135+
action.setPermission(permission);
136+
action.setVersion(version);
137+
return action;
138+
}
139+
140+
/**
141+
* @param ruleSet
142+
* @param parent
143+
* @throws ParseException
144+
*/
145+
public void processXmlParsingOfRuleSet(DeploymentRulesSet ruleSet, final XmlNode parent) throws ParseException {
146+
Rule rule = null;
147+
List<Rule> rules= new ArrayList<Rule>();
148+
XmlNode child = parent.getFirstChild();
149+
XmlNode childRuleSet =null;
150+
if (child.getNodeName().equals(DeploymentRulesSet.RULE_SET_ELEMENT)) {
151+
final XmlNode node = child;
152+
if (!child.getNodeName().equals(DeploymentRulesSet.RULE_SET_ELEMENT)) {
153+
throw new ParseException("Invalid Deployment rule set <ruleset> tag is missing");
154+
}else {
155+
156+
rules = getRules(child);
157+
}
158+
159+
}
160+
ruleSet.setRuleSet(rules);
161+
162+
}
163+
164+
165+
/**
166+
* @param parent
167+
* @return List<Rule> list of Rules from deplyoment rule set
168+
* @throws ParseException
169+
*/
170+
public List<Rule> getRules(final XmlNode parent)
171+
throws ParseException {
172+
final List<Rule> result = new ArrayList<Rule>();
173+
final XmlNode rules[] = getChildNodes(parent, DeploymentRulesSet.RULE_ELEMENT);
174+
175+
// ensure that there are at least one information section present
176+
if (rules.length == 0 ) {
177+
throw new ParseException("No rule <rule> element specified.");
178+
}
179+
for (final XmlNode rule : rules) {
180+
result.add(getRule(rule));
181+
}
182+
return result;
183+
}
184+
185+
/**
186+
* @return the Rule element at the specified node.
187+
* @param node
188+
* @return
189+
* @throws ParseException if the Rule eement does not exist
190+
*/
191+
private Rule getRule(final XmlNode node) throws ParseException {
192+
193+
// create rules
194+
Rule rule=new Rule();
195+
196+
// step through the elements
197+
//first populate the id tag attribute
198+
XmlNode child = node.getFirstChild();
199+
final String name = child.getNodeName();
200+
if (name.equals(DeploymentRulesSet.ID_ELEMENT)) {
201+
getRuleIdAttributeValues(rule, child);
202+
}
203+
//next populate the action tag attribute.
204+
child = child.getNextSibling();
205+
if (child.getNodeName().equals(DeploymentRulesSet.ACTION_ELEMENT)) {
206+
Action action= new Action();
207+
rule.setAction(action);
208+
getActionAttributes(action, child);
209+
}
210+
return rule;
211+
}
212+
213+
}
214+

0 commit comments

Comments
 (0)