All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.gov.ida.saml.serializers.XmlObjectToBase64EncodedStringTransformer Maven / Gradle / Ivy

There is a newer version: 3.4.6-277
Show newest version
package uk.gov.ida.saml.serializers;

import net.shibboleth.utilities.java.support.codec.Base64Support;
import net.shibboleth.utilities.java.support.xml.SerializeSupport;
import org.apache.commons.codec.binary.StringUtils;
import org.opensaml.core.xml.XMLObject;
import org.w3c.dom.Element;

import java.util.function.Function;

public class XmlObjectToBase64EncodedStringTransformer implements Function {

    @Override
    public String apply(XMLObject signableXMLObject) {
        Element signedElement = marshallToElement(signableXMLObject);
        String node = SerializeSupport.nodeToString(signedElement);
        return Base64Support.encode(StringUtils.getBytesUtf8(node), Base64Support.UNCHUNKED);
    }

    private static Element marshallToElement(XMLObject rootObject) {
        return new XmlObjectToElementTransformer<>().apply(rootObject);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy