使用OpenSAML 3的SAML断言验证

时间:2018-12-02 18:44:55

标签: saml opensaml

我试图使用OpenSAML 3验证SAMLResponse断言。 链接:http://shibboleth.net/pipermail/dev/2016-November/008920.html

当我尝试运行以下代码时,我遇到异常java.lang.ClassCastException:org.opensaml.ws.soap.soap11.impl.BodyBuilder无法转换为org.opensaml.core.xml.XMLObjectBuilder

这是在执行“ InitializationService.initialize()”之后立即执行的。

   @PostConstruct
   public void init() {

    try {
      InitializationService.initialize();
      DocumentBuilderFactory documentBuilderFactory = 
      DocumentBuilderFactory.newInstance();
      documentBuilderFactory.setNamespaceAware(true);
      docBuilder = documentBuilderFactory.newDocumentBuilder();
      unmarshallerFactory = 
         XMLObjectProviderRegistrySupport.getUnmarshallerFactory();
      } catch (Exception e){
      logger.error("Error: ",e);
      }
   }

------------------------异常详细信息--------------------- ------------

java.lang.ClassCastException: org.opensaml.ws.soap.soap11.impl.BodyBuilder cannot be cast to org.opensaml.core.xml.XMLObjectBuilder
at org.opensaml.core.xml.config.XMLConfigurator.initializeObjectProviders(XMLConfigurator.java:238)
    at org.opensaml.core.xml.config.XMLConfigurator.load(XMLConfigurator.java:203)
    at org.opensaml.core.xml.config.XMLConfigurator.load(XMLConfigurator.java:188)
    at org.opensaml.core.xml.config.XMLConfigurator.load(XMLConfigurator.java:162)
    at org.opensaml.core.xml.config.AbstractXMLObjectProviderInitializer.init(AbstractXMLObjectProviderInitializer.java:52)
    at org.opensaml.core.config.InitializationService.initialize(InitializationService.java:56)

以下是POM中考虑的依赖项

<dependency>
    <groupId>org.opensaml</groupId>
    <artifactId>xmltooling</artifactId>
    <version>1.4.4</version>
</dependency>

<dependency>
    <groupId>org.opensaml</groupId>
    <artifactId>opensaml-core</artifactId>
    <version>3.1.0</version>
</dependency>

<dependency>
    <groupId>org.opensaml</groupId>
    <artifactId>opensaml-saml-impl</artifactId>
    <version>3.2.0</version>
</dependency>

<dependency>
   <groupId>org.opensaml</groupId>
   <artifactId>opensaml-soap-api</artifactId>
   <version>3.3.0</version>
</dependency>

<dependency>
    <groupId>org.opensaml</groupId>
    <artifactId>opensaml-saml-api</artifactId>
    <version>3.3.0</version>
</dependency>

<dependency>
    <groupId>org.apache.santuario</groupId>
    <artifactId>xmlsec</artifactId>
    <version>2.0.7</version>
</dependency>

 <dependency>
    <groupId>org.apache.ant</groupId>
    <artifactId>ant</artifactId>
    <version>1.8.2</version>
</dependency>

对此表示赞赏。谢谢

1 个答案:

答案 0 :(得分:0)

您将要从POM中删除xmltooling依赖项。它实际上是一个OpenSAML 2.0库,它会引起与您收到的冲突一样的冲突。

有关更多背景信息,请参见与此相关的OpenSAML issuePac4J issue(这是使用OpenSAML的Java库)。