Commit 4cb6bc98 authored by michael.simon's avatar michael.simon
Browse files

Need new nodeToString impl

parent f224e938
......@@ -19,13 +19,8 @@ import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;
import net.shibboleth.utilities.java.support.xml.BasicParserPool;
import net.shibboleth.utilities.java.support.xml.ParserPool;
import org.opensaml.core.config.ConfigurationService;
import org.opensaml.core.config.InitializationException;
import org.opensaml.core.config.InitializationService;
import org.opensaml.core.xml.config.XMLObjectProviderRegistry;
import org.slf4j.Logger;
import edu.kit.scc.webreg.drools.BpmProcessService;
......
......@@ -12,11 +12,11 @@ package edu.kit.scc.webreg.service.saml;
import java.io.Serializable;
import java.io.StringReader;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
......@@ -25,16 +25,13 @@ import javax.inject.Named;
import javax.xml.namespace.QName;
import net.shibboleth.utilities.java.support.xml.BasicParserPool;
import net.shibboleth.utilities.java.support.xml.ParserPool;
import net.shibboleth.utilities.java.support.xml.XMLParserException;
import org.opensaml.core.config.Configuration;
import org.opensaml.core.config.ConfigurationService;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.XMLObjectBuilder;
import org.opensaml.core.xml.XMLObjectBuilderFactory;
import org.opensaml.core.xml.config.XMLObjectProviderRegistry;
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
import org.opensaml.core.xml.io.Marshaller;
import org.opensaml.core.xml.io.MarshallerFactory;
import org.opensaml.core.xml.io.MarshallingException;
......@@ -63,7 +60,8 @@ public class SamlHelper implements Serializable {
@Inject
private Logger logger;
protected SecureRandomIdentifierGenerator randomIdGen;
@Inject
private XMLHelper xmlHelper;
protected MarshallerFactory marshallerFactory;
protected UnmarshallerFactory unmarshallerFactory;
......@@ -72,12 +70,6 @@ public class SamlHelper implements Serializable {
@PostConstruct
public void init() {
try {
randomIdGen = new SecureRandomIdentifierGenerator();
} catch (NoSuchAlgorithmException e) {
logger.error("No SecureRandomIdentifierGenerator available", e);
}
basicParserPool = new BasicParserPool();
basicParserPool.setNamespaceAware(true);
......@@ -96,7 +88,7 @@ public class SamlHelper implements Serializable {
}
public String getRandomId() {
return randomIdGen.generateIdentifier();
return UUID.randomUUID().toString();
}
@SuppressWarnings ("unchecked")
......@@ -114,7 +106,7 @@ public class SamlHelper implements Serializable {
public <T extends XMLObject> String marshal(T t) {
try {
Element element = toXmlElement(t);
return XMLHelper.nodeToString(element);
return xmlHelper.nodeToString(element);
} catch (MarshallingException e) {
logger.error("No Marshalling possible", e);
return null;
......@@ -124,7 +116,7 @@ public class SamlHelper implements Serializable {
public <T extends XMLObject> String prettyPrint(T t) {
try {
Element element = toXmlElement(t);
return XMLHelper.prettyPrintXML(element);
return xmlHelper.prettyPrintXML(element);
} catch (MarshallingException e) {
logger.error("No Marshalling possible", e);
return null;
......@@ -205,10 +197,6 @@ public class SamlHelper implements Serializable {
return attrMap;
}
public SecureRandomIdentifierGenerator getRandomIdGen() {
return randomIdGen;
}
public MarshallerFactory getMarshallerFactory() {
return marshallerFactory;
}
......
package edu.kit.scc.webreg.service.saml;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSOutput;
import org.w3c.dom.ls.LSSerializer;
import org.w3c.dom.ls.LSSerializerFilter;
@Named("xmlHelper")
@ApplicationScoped
public class XMLHelper {
public String nodeToString(Node node) {
StringWriter writer = new StringWriter();
writeNode(node, writer);
return writer.toString();
}
public String prettyPrintXML(Node node) {
StringWriter writer = new StringWriter();
writeNode(node, writer, getPrettyPrintParams());
return writer.toString();
}
private Map<String, Object> getPrettyPrintParams() {
Map<String, Object> prettyPrintParams = new HashMap<String, Object>();
prettyPrintParams.put("format-pretty-print", Boolean.TRUE);
return prettyPrintParams;
}
public void writeNode(Node node, Writer output) {
writeNode(node, output, null);
}
public void writeNode(Node node, Writer output,
Map<String, Object> serializerParams) {
DOMImplementationLS domImplLS = getLSDOMImpl(node);
LSSerializer serializer = getLSSerializer(domImplLS, serializerParams);
LSOutput serializerOut = domImplLS.createLSOutput();
serializerOut.setCharacterStream(output);
serializer.write(node, serializerOut);
}
public DOMImplementationLS getLSDOMImpl(Node node) {
DOMImplementation domImpl;
if (node instanceof Document) {
domImpl = ((Document) node).getImplementation();
} else {
domImpl = node.getOwnerDocument().getImplementation();
}
DOMImplementationLS domImplLS = (DOMImplementationLS) domImpl
.getFeature("LS", "3.0");
return domImplLS;
}
public LSSerializer getLSSerializer(DOMImplementationLS domImplLS,
Map<String, Object> serializerParams) {
LSSerializer serializer = domImplLS.createLSSerializer();
serializer.setFilter(new LSSerializerFilter() {
public short acceptNode(Node arg0) {
return FILTER_ACCEPT;
}
public int getWhatToShow() {
return SHOW_ALL;
}
});
if (serializerParams != null) {
DOMConfiguration serializerDOMConfig = serializer.getDomConfig();
for (String key : serializerParams.keySet()) {
serializerDOMConfig
.setParameter(key, serializerParams.get(key));
}
}
return serializer;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment