Skip to content

Commit e81bf14

Browse files
committed
[PLINK-509] setting required parser features
1 parent 4380773 commit e81bf14

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

modules/common/src/main/java/org/picketlink/common/DefaultPicketLinkLogger.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,4 +2374,9 @@ public RuntimeException cannotSetMaxPoolSizeToNegative(String max) {
23742374
return new RuntimeException("Cannot set maximum STS client pool size to negative number (" + max + ")");
23752375
}
23762376

2377+
@Override
2378+
public RuntimeException parserFeatureNotSupported(String feature) {
2379+
return new RuntimeException("Parser feature " + feature + " not supported.");
2380+
}
2381+
23772382
}

modules/common/src/main/java/org/picketlink/common/PicketLinkLogger.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,4 +1215,6 @@ public interface PicketLinkLogger {
12151215

12161216
RuntimeException cannotSetMaxPoolSizeToNegative(String max);
12171217

1218+
RuntimeException parserFeatureNotSupported(String feature);
1219+
12181220
}

modules/common/src/main/java/org/picketlink/common/util/DocumentUtil.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ public class DocumentUtil {
6666

6767
private static DocumentBuilderFactory documentBuilderFactory;
6868

69+
public static final String feature_external_general_entities = "http://xml.org/sax/features/external-general-entities";
70+
public static final String feature_external_parameter_entities = "http://xml.org/sax/features/external-parameter-entities";
71+
public static final String feature_disallow_doctype_decl = "http://apache.org/xml/features/disallow-doctype-decl";
72+
6973
/**
7074
* Check whether a node belongs to a document
7175
*
@@ -517,6 +521,17 @@ private static DocumentBuilderFactory getDocumentBuilderFactory() {
517521
documentBuilderFactory = DocumentBuilderFactory.newInstance();
518522
documentBuilderFactory.setNamespaceAware(true);
519523
documentBuilderFactory.setXIncludeAware(true);
524+
String feature = "";
525+
try {
526+
feature = feature_disallow_doctype_decl;
527+
documentBuilderFactory.setFeature(feature, true);
528+
feature = feature_external_general_entities;
529+
documentBuilderFactory.setFeature(feature, false);
530+
feature = feature_external_parameter_entities;
531+
documentBuilderFactory.setFeature(feature, false);
532+
} catch (ParserConfigurationException e) {
533+
throw logger.parserFeatureNotSupported(feature);
534+
}
520535
} finally {
521536
if (tccl_jaxp) {
522537
SecurityActions.setTCCL(prevTCCL);

0 commit comments

Comments
 (0)