author | joehw |
Wed, 04 Oct 2017 10:54:18 -0700 | |
changeset 47312 | d4f959806fe9 |
parent 47216 | 71c04702a3d5 |
child 48412 | d4412e380f6b |
permissions | -rw-r--r-- |
12005 | 1 |
/* |
47312 | 2 |
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. |
12005 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.org.apache.xerces.internal.impl; |
|
27 |
||
20968 | 28 |
import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager; |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
29 |
import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager; |
17534 | 30 |
import com.sun.xml.internal.stream.StaxEntityResolverWrapper; |
12005 | 31 |
import java.util.HashMap; |
39907 | 32 |
import javax.xml.XMLConstants; |
33 |
import javax.xml.catalog.CatalogFeatures; |
|
12005 | 34 |
import javax.xml.stream.XMLInputFactory; |
35 |
import javax.xml.stream.XMLOutputFactory; |
|
36 |
import javax.xml.stream.XMLResolver; |
|
39907 | 37 |
import jdk.xml.internal.JdkXmlUtils; |
12005 | 38 |
|
39 |
/** |
|
40 |
* This class manages different properties related to Stax specification and its implementation. |
|
41 |
* This class constructor also takes itself (PropertyManager object) as parameter and initializes the |
|
42 |
* object with the property taken from the object passed. |
|
43 |
* |
|
44 |
* @author Neeraj Bajaj, neeraj.bajaj@sun.com |
|
45 |
* @author K.Venugopal@sun.com |
|
46 |
* @author Sunitha Reddy, sunitha.reddy@sun.com |
|
47 |
*/ |
|
48 |
||
49 |
public class PropertyManager { |
|
50 |
||
51 |
||
52 |
public static final String STAX_NOTATIONS = "javax.xml.stream.notations"; |
|
53 |
public static final String STAX_ENTITIES = "javax.xml.stream.entities"; |
|
54 |
||
55 |
private static final String STRING_INTERNING = "http://xml.org/sax/features/string-interning"; |
|
56 |
||
20968 | 57 |
/** Property identifier: Security manager. */ |
58 |
private static final String SECURITY_MANAGER = Constants.SECURITY_MANAGER; |
|
59 |
||
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
60 |
/** Property identifier: Security property manager. */ |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
61 |
private static final String XML_SECURITY_PROPERTY_MANAGER = |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
62 |
Constants.XML_SECURITY_PROPERTY_MANAGER; |
17534 | 63 |
|
39907 | 64 |
HashMap<String, Object> supportedProps = new HashMap<>(); |
12005 | 65 |
|
20968 | 66 |
private XMLSecurityManager fSecurityManager; |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
67 |
private XMLSecurityPropertyManager fSecurityPropertyMgr; |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
68 |
|
12005 | 69 |
public static final int CONTEXT_READER = 1; |
70 |
public static final int CONTEXT_WRITER = 2; |
|
71 |
||
72 |
/** Creates a new instance of PropertyManager */ |
|
73 |
public PropertyManager(int context) { |
|
74 |
switch(context){ |
|
75 |
case CONTEXT_READER:{ |
|
76 |
initConfigurableReaderProperties(); |
|
77 |
break; |
|
78 |
} |
|
79 |
case CONTEXT_WRITER:{ |
|
80 |
initWriterProps(); |
|
81 |
break; |
|
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
||
86 |
/** |
|
87 |
* Initialize this object with the properties taken from passed PropertyManager object. |
|
88 |
*/ |
|
89 |
public PropertyManager(PropertyManager propertyManager){ |
|
90 |
||
39907 | 91 |
HashMap<String, Object> properties = propertyManager.getProperties(); |
12005 | 92 |
supportedProps.putAll(properties); |
20968 | 93 |
fSecurityManager = (XMLSecurityManager)getProperty(SECURITY_MANAGER); |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
94 |
fSecurityPropertyMgr = (XMLSecurityPropertyManager)getProperty(XML_SECURITY_PROPERTY_MANAGER); |
12005 | 95 |
} |
96 |
||
39907 | 97 |
private HashMap<String, Object> getProperties(){ |
12005 | 98 |
return supportedProps ; |
99 |
} |
|
100 |
||
101 |
||
102 |
/** |
|
103 |
* Important point: |
|
104 |
* 1. We are not exposing Xerces namespace property. Application should configure namespace through |
|
105 |
* Stax specific property. |
|
106 |
* |
|
107 |
*/ |
|
108 |
private void initConfigurableReaderProperties(){ |
|
109 |
//spec default values |
|
110 |
supportedProps.put(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE); |
|
111 |
supportedProps.put(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); |
|
112 |
supportedProps.put(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE); |
|
113 |
supportedProps.put(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE); |
|
114 |
supportedProps.put(XMLInputFactory.IS_COALESCING, Boolean.FALSE); |
|
115 |
supportedProps.put(XMLInputFactory.SUPPORT_DTD, Boolean.TRUE); |
|
116 |
supportedProps.put(XMLInputFactory.REPORTER, null); |
|
117 |
supportedProps.put(XMLInputFactory.RESOLVER, null); |
|
118 |
supportedProps.put(XMLInputFactory.ALLOCATOR, null); |
|
119 |
supportedProps.put(STAX_NOTATIONS,null ); |
|
120 |
||
121 |
//zephyr (implementation) specific properties which can be set by the application. |
|
122 |
//interning is always done |
|
39907 | 123 |
supportedProps.put(Constants.SAX_FEATURE_PREFIX + Constants.STRING_INTERNING_FEATURE , true); |
12005 | 124 |
//recognizing java encoding names by default |
39907 | 125 |
supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE, true) ; |
12005 | 126 |
//in stax mode, namespace declarations are not added as attributes |
127 |
supportedProps.put(Constants.ADD_NAMESPACE_DECL_AS_ATTRIBUTE , Boolean.FALSE) ; |
|
39907 | 128 |
supportedProps.put(Constants.READER_IN_DEFINED_STATE, true); |
129 |
supportedProps.put(Constants.REUSE_INSTANCE, true); |
|
130 |
supportedProps.put(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.STAX_REPORT_CDATA_EVENT , false); |
|
12005 | 131 |
supportedProps.put(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.IGNORE_EXTERNAL_DTD, Boolean.FALSE); |
39907 | 132 |
supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE, false); |
133 |
supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE, false); |
|
134 |
supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE, false); |
|
17534 | 135 |
|
20968 | 136 |
fSecurityManager = new XMLSecurityManager(true); |
137 |
supportedProps.put(SECURITY_MANAGER, fSecurityManager); |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
138 |
fSecurityPropertyMgr = new XMLSecurityPropertyManager(); |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
139 |
supportedProps.put(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr); |
39907 | 140 |
|
141 |
// Initialize Catalog features |
|
142 |
supportedProps.put(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT); |
|
143 |
for( CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) { |
|
144 |
supportedProps.put(f.getPropertyName(), null); |
|
145 |
} |
|
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
146 |
|
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
147 |
supportedProps.put(JdkXmlUtils.CDATA_CHUNK_SIZE, JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT); |
12005 | 148 |
} |
149 |
||
150 |
private void initWriterProps(){ |
|
151 |
supportedProps.put(XMLOutputFactory.IS_REPAIRING_NAMESPACES , Boolean.FALSE); |
|
152 |
//default value of escaping characters is 'true' |
|
153 |
supportedProps.put(Constants.ESCAPE_CHARACTERS , Boolean.TRUE); |
|
39907 | 154 |
supportedProps.put(Constants.REUSE_INSTANCE, true); |
12005 | 155 |
} |
156 |
||
157 |
/** |
|
158 |
* public void reset(){ |
|
159 |
* supportedProps.clear() ; |
|
160 |
* } |
|
161 |
*/ |
|
162 |
public boolean containsProperty(String property){ |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
163 |
return supportedProps.containsKey(property) || |
20968 | 164 |
(fSecurityManager != null && fSecurityManager.getIndex(property) > -1) || |
18891
be38bcc1d0f3
8020430: NullPointerException in xml sqe nightly result on 2013-07-12
joehw
parents:
18890
diff
changeset
|
165 |
(fSecurityPropertyMgr!=null && fSecurityPropertyMgr.getIndex(property) > -1) ; |
12005 | 166 |
} |
167 |
||
168 |
public Object getProperty(String property){ |
|
169 |
return supportedProps.get(property); |
|
170 |
} |
|
171 |
||
172 |
public void setProperty(String property, Object value){ |
|
173 |
String equivalentProperty = null ; |
|
39907 | 174 |
if(property.equals(XMLInputFactory.IS_NAMESPACE_AWARE)){ |
12005 | 175 |
equivalentProperty = Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE ; |
176 |
} |
|
39907 | 177 |
else if(property.equals(XMLInputFactory.IS_VALIDATING)){ |
12005 | 178 |
if( (value instanceof Boolean) && ((Boolean)value).booleanValue()){ |
179 |
throw new java.lang.IllegalArgumentException("true value of isValidating not supported") ; |
|
180 |
} |
|
181 |
} |
|
39907 | 182 |
else if(property.equals(STRING_INTERNING)){ |
12005 | 183 |
if( (value instanceof Boolean) && !((Boolean)value).booleanValue()){ |
184 |
throw new java.lang.IllegalArgumentException("false value of " + STRING_INTERNING + "feature is not supported") ; |
|
185 |
} |
|
186 |
} |
|
39907 | 187 |
else if(property.equals(XMLInputFactory.RESOLVER)){ |
12005 | 188 |
//add internal stax property |
189 |
supportedProps.put( Constants.XERCES_PROPERTY_PREFIX + Constants.STAX_ENTITY_RESOLVER_PROPERTY , new StaxEntityResolverWrapper((XMLResolver)value)) ; |
|
190 |
} |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
191 |
|
20973 | 192 |
/** |
193 |
* It's possible for users to set a security manager through the interface. |
|
194 |
* If it's the old SecurityManager, convert it to the new XMLSecurityManager |
|
195 |
*/ |
|
196 |
if (property.equals(Constants.SECURITY_MANAGER)) { |
|
197 |
fSecurityManager = XMLSecurityManager.convert(value, fSecurityManager); |
|
198 |
supportedProps.put(Constants.SECURITY_MANAGER, fSecurityManager); |
|
199 |
return; |
|
200 |
} |
|
201 |
if (property.equals(Constants.XML_SECURITY_PROPERTY_MANAGER)) { |
|
202 |
if (value == null) { |
|
203 |
fSecurityPropertyMgr = new XMLSecurityPropertyManager(); |
|
204 |
} else { |
|
205 |
fSecurityPropertyMgr = (XMLSecurityPropertyManager)value; |
|
206 |
} |
|
207 |
supportedProps.put(Constants.XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr); |
|
208 |
return; |
|
209 |
} |
|
210 |
||
20968 | 211 |
//check if the property is managed by security manager |
212 |
if (fSecurityManager == null || |
|
213 |
!fSecurityManager.setLimit(property, XMLSecurityManager.State.APIPROPERTY, value)) { |
|
214 |
//check if the property is managed by security property manager |
|
215 |
if (fSecurityPropertyMgr == null || |
|
216 |
!fSecurityPropertyMgr.setValue(property, XMLSecurityPropertyManager.State.APIPROPERTY, value)) { |
|
217 |
//fall back to the existing property manager |
|
218 |
supportedProps.put(property, value); |
|
219 |
} |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
220 |
} |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
221 |
|
12005 | 222 |
if(equivalentProperty != null){ |
223 |
supportedProps.put(equivalentProperty, value ) ; |
|
224 |
} |
|
225 |
} |
|
226 |
||
227 |
public String toString(){ |
|
228 |
return supportedProps.toString(); |
|
229 |
} |
|
230 |
||
231 |
}//PropertyManager |