2017-09-01 248 views
0

错误:SAML断言解密使用Java代码

Exception in thread "main" org.opensaml.xml.io.UnmarshallingException: the assertion does not appear to be encrypted 
    at AssertionDecrypter.unmarshallEncryptedAssertion(AssertionDecrypter.java:162) 
    at AssertionDecrypter.decryptAssertion(AssertionDecrypter.java:119) 
    at AssertionDecrypter.<init>(AssertionDecrypter.java:67) 
    at Saml2AssertionEncoding.main(Saml2AssertionEncoding.java:112) 
Caused by: java.lang.ClassCastException: org.opensaml.saml1.core.impl.ResponseImpl cannot be cast to org.opensaml.saml2.core.EncryptedAssertion 
    at AssertionDecrypter.unmarshallEncryptedAssertion(AssertionDecrypter.java:157) 
    ... 3 more 

我的Java代码

enter image description here

我出海

<dependency> 
     <groupId>org.opensaml</groupId> 
     <artifactId>opensaml-core</artifactId> 
     <version>3.1.1</version> 
     <scope>test</scope> 
    </dependency> 

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

    <dependency> 
     <groupId>org.opensaml</groupId> 
     <artifactId>opensaml</artifactId> 
     <version>2.6.4</version> 
    </dependency> 
    <dependency> 
     <groupId>org.opensaml</groupId> 
     <artifactId>opensaml-saml-impl</artifactId> 
     <version>3.3.0</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <!-- <groupId>org.opensaml</groupId> <artifactId>xmltooling</artifactId> 
      <version>1.3.1</version> 
     <groupId>org.opensaml</groupId> 
     <artifactId>xmltooling</artifactId> 
     <version>1.4.4</version> --> 
      <groupId>org.opensaml</groupId> 
      <artifactId>xmltooling</artifactId> 
      <version>1.3.1</version> 
    </dependency> 
    <dependency> 
     <groupId>com.jcabi</groupId> 
     <artifactId>jcabi-aspects</artifactId> 
     <version>0.22</version> 
    </dependency> 
    <dependency> 
     <groupId>org.aspectj</groupId> 
     <artifactId>aspectjrt</artifactId> 
     <version>1.8.3</version> 
    </dependency> 
    <dependency> 
     <groupId>com.jcabi</groupId> 
     <artifactId>jcabi-xml</artifactId> 
     <version>0.16.2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-nop</artifactId> 
     <version>1.7.5</version> 
     <scope>compile</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.opensaml</groupId> 
     <artifactId>openws</artifactId> 
     <version>1.4.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.opensaml</groupId> 
     <artifactId>opensaml</artifactId> 
     <version>2.2.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <version>4.1.0.RELEASE</version> 
    </dependency> 
</dependencies> 
+0

**引起:java.lang.ClassCastException:org.opensaml.saml1.core.impl.ResponseImpl无法转换为org.opensaml.saml2.core.EncryptedAssertion **是根本原因。请不要链接代码,在问题本身中删除相关部分。 – nullpointer

回答

0

好吧,似乎是两件事情错了。

它看起来像你不小心试图解密响应对象,而不是包含断言。你应该这样做

Response response = unmarshaller.unmarshall(...); 
return (EncryptedAssertion) response.getEncryptedAssertions().get(0) 

只要你知道在响应中只发送一个断言。

但是,你似乎得到了SAML 1响应消息而不是SAML 2. 我不是SAML 1的专家,但似乎不支持encryptet断言。

因此,首先将protocoll版本与发送消息的版本进行排序,然后确保返回加密的断言而不是响应对象。