JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(Init.class.getClassLoader().getResource("schemas/security-config.xsd"));
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 = Init.class.getClassLoader().getResource("security-config.xml");
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());
SecurityHeaderHandlerMapper.init(configurationTypeJAXBElement.getValue().getSecurityHeaderHandlers());
JCEAlgorithmMapper.init(configurationTypeJAXBElement.getValue().getJCEAlgorithmMappings());
TransformerAlgorithmMapper.init(configurationTypeJAXBElement.getValue().getTransformAlgorithms());