Commit 97a98a6f authored by michael.simon's avatar michael.simon
Browse files

more changes

parent 90397b97
......@@ -24,6 +24,7 @@ import net.shibboleth.utilities.java.support.httpclient.HttpClientBuilder;
import org.joda.time.DateTime;
import org.opensaml.core.config.Configuration;
import org.opensaml.core.config.ConfigurationService;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.XMLObjectBuilderFactory;
import org.opensaml.saml.common.SAMLVersion;
......@@ -38,6 +39,8 @@ import org.opensaml.security.x509.BasicX509Credential;
import org.opensaml.soap.common.SOAPException;
import org.opensaml.soap.soap11.Body;
import org.opensaml.soap.soap11.Envelope;
import org.opensaml.xmlsec.DecryptionConfiguration;
import org.opensaml.xmlsec.SignatureSigningConfiguration;
import org.opensaml.xmlsec.keyinfo.KeyInfoGenerator;
import org.opensaml.xmlsec.keyinfo.impl.X509KeyInfoGeneratorFactory;
import org.opensaml.xmlsec.signature.KeyInfo;
......@@ -77,6 +80,7 @@ public class AttributeQueryHelper implements Serializable {
AttributeQuery attrQuery = buildAttributeQuery(
persistentId, spEntity.getEntityId());
Envelope envelope = buildSOAP11Envelope(attrQuery);
BasicSOAPMessageContext soapContext = new BasicSOAPMessageContext();
soapContext.setOutboundMessage(envelope);
......@@ -105,8 +109,10 @@ public class AttributeQueryHelper implements Serializable {
Signature signature = (Signature) samlHelper.getBuilderFactory()
.getBuilder(Signature.DEFAULT_ELEMENT_NAME)
.buildObject(Signature.DEFAULT_ELEMENT_NAME);
X509KeyInfoGeneratorFactory keyInfoFac = (X509KeyInfoGeneratorFactory) Configuration
.getGlobalSecurityConfiguration()
SignatureSigningConfiguration ssc = ConfigurationService.get(SignatureSigningConfiguration.class);
X509KeyInfoGeneratorFactory keyInfoFac = (X509KeyInfoGeneratorFactory) ssc
.getKeyInfoGeneratorManager().getDefaultManager()
.getFactory(signingCredential);
keyInfoFac.setEmitEntityCertificate(false);
......@@ -165,7 +171,7 @@ public class AttributeQueryHelper implements Serializable {
}
public Envelope buildSOAP11Envelope(XMLObject payload) {
XMLObjectBuilderFactory bf = Configuration.getBuilderFactory();
XMLObjectBuilderFactory bf = samlHelper.getBuilderFactory();
Envelope envelope = (Envelope) bf.getBuilder(
Envelope.DEFAULT_ELEMENT_NAME).buildObject(
Envelope.DEFAULT_ELEMENT_NAME);
......
......@@ -16,6 +16,7 @@ import java.io.Serializable;
import java.nio.charset.Charset;
import net.shibboleth.utilities.java.support.xml.ParserPool;
import net.shibboleth.utilities.java.support.xml.SerializeSupport;
import org.apache.http.client.HttpClient;
import org.opensaml.core.config.Configuration;
......@@ -49,7 +50,6 @@ public class HttpSignableSoapClient extends HttpSOAPClient implements Serializab
try {
Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(message);
ByteArrayOutputStream arrayOut = new ByteArrayOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(arrayOut, charset);
Element element = marshaller.marshall(message);
try {
......@@ -59,9 +59,9 @@ public class HttpSignableSoapClient extends HttpSOAPClient implements Serializab
}
if (logger.isDebugEnabled()) {
logger.debug("Outbound SOAP message is:\n" + XMLHelper.prettyPrintXML(element));
logger.debug("Outbound SOAP message is:\n" + SerializeSupport.prettyPrintXML(element));
}
XMLHelper.writeNode(element, writer);
SerializeSupport.writeNode(element, arrayOut);
return new ByteArrayRequestEntity(arrayOut.toByteArray(), "text/xml");
} catch (MarshallingException e) {
throw new SOAPClientException("Unable to marshall SOAP envelope", e);
......
......@@ -25,6 +25,7 @@ import javax.inject.Named;
import javax.xml.namespace.QName;
import net.shibboleth.utilities.java.support.xml.BasicParserPool;
import net.shibboleth.utilities.java.support.xml.SerializeSupport;
import net.shibboleth.utilities.java.support.xml.XMLParserException;
import org.opensaml.core.config.ConfigurationService;
......@@ -60,9 +61,6 @@ public class SamlHelper implements Serializable {
@Inject
private Logger logger;
@Inject
private XMLHelper xmlHelper;
protected MarshallerFactory marshallerFactory;
protected UnmarshallerFactory unmarshallerFactory;
protected BasicParserPool basicParserPool;
......@@ -106,7 +104,7 @@ public class SamlHelper implements Serializable {
public <T extends XMLObject> String marshal(T t) {
try {
Element element = toXmlElement(t);
return xmlHelper.nodeToString(element);
return SerializeSupport.nodeToString(element);
} catch (MarshallingException e) {
logger.error("No Marshalling possible", e);
return null;
......@@ -116,7 +114,7 @@ public class SamlHelper implements Serializable {
public <T extends XMLObject> String prettyPrint(T t) {
try {
Element element = toXmlElement(t);
return xmlHelper.prettyPrintXML(element);
return SerializeSupport.prettyPrintXML(element);
} catch (MarshallingException e) {
logger.error("No Marshalling possible", e);
return null;
......
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