添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have to migrate a class from opensaml 2.6 to opensaml 3.1.1 Compiling I obtain some errors

Element plaintextElement = getElementAssertion(inputBean);
String xml = XMLHelper.prettyPrintXML(plaintextElement);

I can't find the class XMLHelper in the new version.

DefaultBootstrap.bootstrap();
builderFactory = Configuration.getBuilderFactory();
Configuration.getMarshallerFactory().getMarshaller(assertion).marshall(assertion);

I can'f find class DefaultBootstrap and I can't find a class Configuration with the methods getBuilderFactory(), getMarshallerFactory()

BasicCredential credential = new BasicCredential();

Now the contructor new BasicCredential() is not visible.

I haven't found documentation with deprecation indication. What must I do to port this class to the opensaml 3.1.1 version?

Not sure if you managed to upgrade to opensaml 3 already but since I came across this while attempting the upgrade myself I thought I'm gonna document what I found.

There's very little documentation as apparently it's not a priority for them at the moment (also mentioned here: OpenSaml3 Documentation), the most useful (even if by far not complete) page I found is this one: https://wiki.shibboleth.net/confluence/display/OS30/Initialization+and+Configuration

1) There's a class SerializeSupport with a method prettyPrintXML in lib net.shibboleth.utilities:java-support

2) Initialization is now done via InitializationService

InitializationService.initialize();

You can retrieve the builder/marshallers via XMLObjectProviderRegistrySupport e.g.:

XMLObjectProviderRegistrySupport.getMarshallerFactory()
XMLObjectProviderRegistrySupport.getBuilderFactory()
XMLObjectProviderRegistrySupport.getUnmarshallerFactory()

Mind that opensaml is using the Java Service Provider API. In my case (using OSGi bundle org.apache.servicemix.bundles:org.apache.servicemix.bundles.opensaml) for parsing a SAML assertion I added the SPI config META-INF/services/org.opensaml.core.config.Initializer containing the following entries:

org.opensaml.core.xml.config.XMLObjectProviderInitializer
org.opensaml.core.xml.config.GlobalParserPoolInitializer
org.opensaml.saml.config.XMLObjectProviderInitializer
org.opensaml.saml.config.SAMLConfigurationInitializer
org.opensaml.xmlsec.config.XMLObjectProviderInitializer

EDIT: The above worked in a test but did not run in the OSGi container. Workaround for OSGi: OpenSAML3 resource not found 'default-config.xml' in OSGi container

If you use the standard libraries (org.opensaml:opensaml-core, org.opensaml:opensaml-saml-api, org.opensaml:opensaml-saml-impl, ...) you may not need to add any SPI config as the jars already contain SPI configs with a standard configuration for initialization.

3) There's a class BasicCredential in lib org.opensaml:opensaml-security-api. I don' see an alternative to providing a key during initalization.

So what could be the reason when i still get null instead of the (un) marshaller from the factory? XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(authnRequest.getElementQName()) – Gobliins Jan 11, 2017 at 12:42 There's some helpful sample code at git.shibboleth.net/view/…. Note that some of the initialization is in the superclass at org.opensaml.core.xml.XMLObjectBaseTestCase#initXMLObjectSupport which in turn inherits from OpenSAMLInitBaseTestCase (does nothing but InitializationService.initialize()). – Marcel Stör Aug 19, 2017 at 19:53 I'm struggling with something similar to section 1) , for classes SOAPHelper and WSSecurityHelper. Anybody knows where those went ? – Serban Feb 15, 2019 at 15:03 Probably org.opensaml.soap.util.SOAPSupport and org.opensaml.soap.wssecurity.util.WSSecuritySupport build.shibboleth.net/nexus/content/sites/site/java-opensaml/… build.shibboleth.net/nexus/content/sites/site/java-opensaml/… – Clauds Feb 18, 2019 at 12:13

I am learning how to use the OS3 for development. This is one example to convert base 64 saml request to SAMLObject in V3 version. Hope it can help you.

The project see the github repository

public class SAMLToolkit {
    public static SAMLObject convertBase64ToSaml(String base64Str) {
        byte[] decodedBytes = new byte[0];
        try {
            decodedBytes = Base64.decode(base64Str);
        } catch (Base64DecodingException e) {
            e.printStackTrace();
            return null;
        InputStream is = new ByteArrayInputStream(decodedBytes);
        //is = new InflaterInputStream(is, new Inflater(true));
        try {
            InitializationService.initialize();
            Document messageDoc;
            BasicParserPool basicParserPool = new BasicParserPool();
            basicParserPool.initialize();
            messageDoc = basicParserPool.parse(is);
            Element messageElem = messageDoc.getDocumentElement();
            Unmarshaller unmarshaller = XMLObjectProviderRegistrySupport.getUnmarshallerFactory().getUnmarshaller(messageElem);
            assert unmarshaller != null;
            return(SAMLObject) unmarshaller.unmarshall(messageElem);
        } catch (InitializationException e) {
            e.printStackTrace();
            return null;
        } catch (XMLParserException e) {
            e.printStackTrace();
            return null;
        } catch (UnmarshallingException e) {
            e.printStackTrace();
            return null;
        } catch (ComponentInitializationException e) {
            e.printStackTrace();
            return null;
                This wouldn't work for me unless I also add ´/META-INF/services/org.opensaml.core.config.Initializer´ which contains the config shown by @Clauds.
– Marcel Stör
                Aug 19, 2017 at 19:56
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.