27
27
import com .sun .org .apache .xerces .internal .xni .parser .XMLParserConfiguration ;
28
28
import jdk .xml .internal .JdkConstants ;
29
29
import jdk .xml .internal .JdkProperty ;
30
+ import jdk .xml .internal .Utils ;
30
31
import jdk .xml .internal .XMLSecurityManager ;
32
+ import org .xml .sax .SAXException ;
31
33
import org .xml .sax .SAXNotRecognizedException ;
32
34
import org .xml .sax .SAXNotSupportedException ;
33
35
39
41
* @author Arnaud Le Hors, IBM
40
42
* @author Andy Clark, IBM
41
43
*
42
- * @LastModified: July 2023
44
+ * @LastModified: Sep 2023
43
45
*/
44
46
public class SAXParser
45
47
extends AbstractSAXParser {
@@ -89,6 +91,7 @@ public class SAXParser
89
91
*/
90
92
public SAXParser (XMLParserConfiguration config ) {
91
93
super (config );
94
+ initSecurityManager ();
92
95
} // <init>(XMLParserConfiguration)
93
96
94
97
/**
@@ -125,6 +128,7 @@ public SAXParser(SymbolTable symbolTable, XMLGrammarPool grammarPool) {
125
128
fConfiguration .setProperty (XMLGRAMMAR_POOL , grammarPool );
126
129
}
127
130
131
+ initSecurityManager ();
128
132
} // <init>(SymbolTable,XMLGrammarPool)
129
133
130
134
/**
@@ -152,16 +156,6 @@ public void setProperty(String name, Object value)
152
156
return ;
153
157
}
154
158
155
- if (securityManager == null ) {
156
- securityManager = new XMLSecurityManager (true );
157
- super .setProperty (Constants .SECURITY_MANAGER , securityManager );
158
- }
159
-
160
- if (securityPropertyManager == null ) {
161
- securityPropertyManager = new XMLSecurityPropertyManager ();
162
- super .setProperty (JdkConstants .XML_SECURITY_PROPERTY_MANAGER , securityPropertyManager );
163
- }
164
-
165
159
int index = securityPropertyManager .getIndex (name );
166
160
if (index > -1 ) {
167
161
/**
@@ -178,4 +172,25 @@ public void setProperty(String name, Object value)
178
172
}
179
173
}
180
174
}
175
+
176
+ /**
177
+ * Initiates the SecurityManager. This becomes necessary when the SAXParser
178
+ * is constructed directly by, for example, XMLReaderFactory rather than
179
+ * through SAXParserFactory.
180
+ */
181
+ private void initSecurityManager () {
182
+ try {
183
+ if (securityManager == null ) {
184
+ securityManager = new XMLSecurityManager (true );
185
+ super .setProperty (Constants .SECURITY_MANAGER , securityManager );
186
+ }
187
+
188
+ if (securityPropertyManager == null ) {
189
+ securityPropertyManager = new XMLSecurityPropertyManager ();
190
+ super .setProperty (JdkConstants .XML_SECURITY_PROPERTY_MANAGER , securityPropertyManager );
191
+ }
192
+ } catch (SAXException e ) {
193
+ Utils .dPrint (() -> e .getMessage ());
194
+ }
195
+ }
181
196
} // class SAXParser
0 commit comments