[java-opensaml COMMIT] /trunk/opensaml-saml-api/src/main/java/org/opensaml/saml/common/xml/SAMLSchemaBuilder.java
noreply at shibboleth.net
noreply at shibboleth.net
Fri Nov 6 20:28:03 EST 2015
Author: putmanb
Date: Fri Nov 6 20:28:02 2015
New Revision: 4403
URL: http://svn.shibboleth.net/view/java-opensaml?rev=4403&view=rev
Log:
OSJ-110: SAMLSchemaBuilder ignores failure to locate schemas
Modified:
trunk/opensaml-saml-api/src/main/java/org/opensaml/saml/common/xml/SAMLSchemaBuilder.java
Modified: trunk/opensaml-saml-api/src/main/java/org/opensaml/saml/common/xml/SAMLSchemaBuilder.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-api/src/main/java/org/opensaml/saml/common/xml/SAMLSchemaBuilder.java?rev=4403&r1=4402&r2=4403&view=diff
==============================================================================
--- trunk/opensaml-saml-api/src/main/java/org/opensaml/saml/common/xml/SAMLSchemaBuilder.java (original)
+++ trunk/opensaml-saml-api/src/main/java/org/opensaml/saml/common/xml/SAMLSchemaBuilder.java Fri Nov 6 20:28:02 2015
@@ -30,6 +30,9 @@
import net.shibboleth.utilities.java.support.xml.ClasspathResolver;
import net.shibboleth.utilities.java.support.xml.SchemaBuilder;
+import org.opensaml.core.xml.XMLRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
/**
@@ -40,6 +43,12 @@
*/
@ThreadSafe
public class SAMLSchemaBuilder {
+
+ /** Logger. */
+ private Logger log = LoggerFactory.getLogger(SAMLSchemaBuilder.class);
+
+ /** Flag indicating whether the failure to resolve a schema resource should be considered fatal. */
+ private boolean unresolvedSchemaFatal;
/** Classpath relative location of basic XML schemas. */
@Nonnull @NonnullElements @NotEmpty private static String[] baseXMLSchemas = {
@@ -148,6 +157,7 @@
* @param ver the SAML 1.x version to use
*/
public SAMLSchemaBuilder(@Nonnull final SAML1Version ver) {
+ unresolvedSchemaFatal = true;
if (ver == SAML1Version.SAML_11) {
saml1xSchemas = saml11Schemas;
} else {
@@ -159,6 +169,17 @@
}
/**
+ * Set the flag indicating whether the failure to resolve a schema resource should be considered fatal.
+ *
+ * <p>Default value: true.</p>
+ *
+ * @param flag true if should be fatal, false if not
+ */
+ public void setUnresolvedSchemaFatal(boolean flag) {
+ unresolvedSchemaFatal = flag;
+ }
+
+ /**
* Set a custom {@link SchemaBuilder} to use.
*
* @param builder SchemaBuilder to use
@@ -184,49 +205,48 @@
return cachedSchema;
}
-// Checkstyle: CyclomaticComplexity OFF
/**
* Configure the appropriate {@link SchemaBuilder} with the right set of schemas.
*/
@Nonnull private void configureBuilder() {
-
+ for (final String source : baseXMLSchemas) {
+ addSchemaToBuilder(source);
+ }
+
+ for (final String source : soapSchemas) {
+ addSchemaToBuilder(source);
+ }
+
+ for (final String source : saml1xSchemas) {
+ addSchemaToBuilder(source);
+ }
+
+ for (final String source : saml20Schemas) {
+ addSchemaToBuilder(source);
+ }
+
+ for (final String source : baseExtSchemas) {
+ addSchemaToBuilder(source);
+ }
+ }
+
+ /**
+ * Load the schema from the specified source and add it to the internal {@link SchemaBuilder}.
+ *
+ * @param source the schema resource path
+ */
+ private void addSchemaToBuilder(@Nonnull final String source) {
final Class<SAMLSchemaBuilder> clazz = SAMLSchemaBuilder.class;
- for (final String source : baseXMLSchemas) {
- final InputStream stream = clazz.getResourceAsStream(source);
- if (stream != null) {
- schemaBuilder.addSchema(stream);
+ final InputStream stream = clazz.getResourceAsStream(source);
+ if (stream != null) {
+ schemaBuilder.addSchema(stream);
+ } else {
+ log.warn("Failed to locate schema resource: {}", source);
+ if (unresolvedSchemaFatal) {
+ throw new XMLRuntimeException("Failed to locate schema resource: " + source);
}
}
-
- for (final String source : soapSchemas) {
- final InputStream stream = clazz.getResourceAsStream(source);
- if (stream != null) {
- schemaBuilder.addSchema(stream);
- }
- }
-
- for (final String source : saml1xSchemas) {
- final InputStream stream = clazz.getResourceAsStream(source);
- if (stream != null) {
- schemaBuilder.addSchema(stream);
- }
- }
-
- for (final String source : saml20Schemas) {
- final InputStream stream = clazz.getResourceAsStream(source);
- if (stream != null) {
- schemaBuilder.addSchema(stream);
- }
- }
-
- for (final String source : baseExtSchemas) {
- final InputStream stream = clazz.getResourceAsStream(source);
- if (stream != null) {
[... 9 lines stripped ...]
More information about the commits
mailing list