use of org.apache.cxf.staxutils.W3CDOMStreamWriter in project cas by apereo.
the class WSFederationMetadataWriter method produceMetadataDocument.
/**
* Produce metadata document.
*
* @param config the config
* @return the document
* @throws Exception the exception
*/
public static Document produceMetadataDocument(final CasConfigurationProperties config) throws Exception {
val wsfedIdp = config.getAuthn().getWsfedIdp();
val sts = wsfedIdp.getSts();
val prop = CryptoUtils.getSecurityProperties(sts.getRealm().getKeystoreFile(), sts.getRealm().getKeystorePassword(), sts.getRealm().getKeystoreAlias());
val crypto = CryptoFactory.getInstance(prop);
val writer = new W3CDOMStreamWriter();
writer.writeStartDocument(StandardCharsets.UTF_8.name(), "1.0");
val referenceID = IDGenerator.generateID("_");
writer.writeStartElement("md", "EntityDescriptor", SAML2_METADATA_NS);
writer.writeAttribute("ID", referenceID);
val idpEntityId = config.getServer().getPrefix().concat(WSFederationConstants.ENDPOINT_FEDERATION_REQUEST);
writer.writeAttribute("entityID", idpEntityId);
writer.writeNamespace("md", SAML2_METADATA_NS);
writer.writeNamespace("fed", WS_FEDERATION_NS);
writer.writeNamespace("wsa", WS_ADDRESSING_NS);
writer.writeNamespace("auth", WS_FEDERATION_NS);
writer.writeNamespace("xsi", SCHEMA_INSTANCE_NS);
val stsUrl = config.getServer().getPrefix().concat(WSFederationConstants.BASE_ENDPOINT_STS).concat(wsfedIdp.getIdp().getRealmName());
writeFederationMetadata(writer, idpEntityId, stsUrl, crypto);
writer.writeEndElement();
writer.writeEndDocument();
writer.close();
val out = DOM2Writer.nodeToString(writer.getDocument());
LOGGER.trace(out);
return SignatureUtils.signMetaInfo(crypto, null, sts.getRealm().getKeyPassword(), writer.getDocument(), referenceID);
}
use of org.apache.cxf.staxutils.W3CDOMStreamWriter in project cxf by apache.
the class MappingBeanDefinitionParser method transformElement.
private Element transformElement(Element element) {
W3CDOMStreamWriter domWriter = new W3CDOMStreamWriter();
OutTransformWriter transformWriter = new OutTransformWriter(domWriter, transformMap);
try {
StaxUtils.copy(element, transformWriter);
} catch (XMLStreamException e) {
throw new RuntimeException(e);
}
return domWriter.getDocument().getDocumentElement();
}
use of org.apache.cxf.staxutils.W3CDOMStreamWriter in project cxf by apache.
the class OutTransformWriterTest method testNamespaceConversionAndDefaultNS.
@Test
public void testNamespaceConversionAndDefaultNS() throws Exception {
W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
Map<String, String> outMap = new HashMap<>();
outMap.put("{http://testbeans.com}testBean", "{http://testbeans.com/v2}testBean");
outMap.put("{http://testbeans.com}bean", "{http://testbeans.com/v3}bean");
OutTransformWriter transformWriter = new OutTransformWriter(writer, outMap, Collections.<String, String>emptyMap(), Collections.<String>emptyList(), false, "http://testbeans.com/v2");
JAXBContext context = JAXBContext.newInstance(TestBean.class);
Marshaller m = context.createMarshaller();
m.marshal(new TestBean(), transformWriter);
Element el = writer.getDocument().getDocumentElement();
assertEquals("http://testbeans.com/v2", el.getNamespaceURI());
assertTrue(StringUtils.isEmpty(el.getPrefix()));
el = DOMUtils.getFirstElement(el);
assertEquals("http://testbeans.com/v3", el.getNamespaceURI());
assertFalse(StringUtils.isEmpty(el.getPrefix()));
}
use of org.apache.cxf.staxutils.W3CDOMStreamWriter in project cxf by apache.
the class EndpointReferenceUtils method convertToXML.
public static Source convertToXML(EndpointReferenceType epr) {
try {
Marshaller jm = getJAXBContextForEPR().createMarshaller();
jm.setProperty(Marshaller.JAXB_FRAGMENT, true);
QName qname = new QName("http://www.w3.org/2005/08/addressing", "EndpointReference");
JAXBElement<EndpointReferenceType> jaxEle = new JAXBElement<>(qname, EndpointReferenceType.class, epr);
W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
jm.marshal(jaxEle, writer);
return new DOMSource(writer.getDocument());
} catch (JAXBException e) {
// ignore
}
return null;
}
use of org.apache.cxf.staxutils.W3CDOMStreamWriter in project cxf by apache.
the class TunedDocumentLoader method loadDocument.
@Override
public Document loadDocument(InputSource inputSource, EntityResolver entityResolver, ErrorHandler errorHandler, int validationMode, boolean namespaceAware) throws Exception {
if (validationMode == XmlBeanDefinitionReader.VALIDATION_NONE) {
SAXParserFactory parserFactory = namespaceAware ? nsasaxParserFactory : saxParserFactory;
SAXParser parser = parserFactory.newSAXParser();
XMLReader reader = parser.getXMLReader();
reader.setEntityResolver(entityResolver);
reader.setErrorHandler(errorHandler);
SAXSource saxSource = new SAXSource(reader, inputSource);
W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
StaxUtils.copy(saxSource, writer);
return writer.getDocument();
}
return super.loadDocument(inputSource, entityResolver, errorHandler, validationMode, namespaceAware);
}
Aggregations