final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(
ClassLoaderUtils.getResource("schemas/security-config.xsd", Init.class));
unmarshaller.setSchema(schema);
final UnmarshallerHandler unmarshallerHandler = unmarshaller.getUnmarshallerHandler();
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setXIncludeAware(false);
saxParserFactory.setNamespaceAware(true);
SAXParser saxParser = saxParserFactory.newSAXParser();
if (uri == null) {
URL resource = ClassLoaderUtils.getResource("security-config.xml", Init.class);
if (resource == null) {
//kind of chicken-egg problem here
I18n.init("en", "US");
throw new XMLSecurityConfigurationException("empty", "security-config.xml not found in classpath");
}
uri = resource.toURI();
}
saxParser.parse(uri.toURL().toExternalForm(), new XIncludeHandler(unmarshallerHandler));
JAXBElement<ConfigurationType> configurationTypeJAXBElement = (JAXBElement<ConfigurationType>) unmarshallerHandler.getResult();
ConfigurationProperties.init(configurationTypeJAXBElement.getValue().getProperties(), callingClass);
SecurityHeaderHandlerMapper.init(configurationTypeJAXBElement.getValue().getSecurityHeaderHandlers(), callingClass);
JCEAlgorithmMapper.init(configurationTypeJAXBElement.getValue().getJCEAlgorithmMappings());
TransformerAlgorithmMapper.init(configurationTypeJAXBElement.getValue().getTransformAlgorithms(), callingClass);